Python을 사용하여 XBRL 파일 만들기

XBRL 문서는 비즈니스 보고서를 구성하는 사실의 모음입니다. 프로그래밍 방식으로 XBRL 인스턴스 문서를 쉽게 만들고 스키마 참조, 컨텍스트, 단위, 항목 등과 같은 개체 또는 요소를 추가할 수 있습니다. 이 기사에서는 Python을 사용하여 XBRL 파일을 만드는 방법을 배웁니다.

이 기사에서는 다음 주제를 다룹니다.

  1. XBRL이란?
  2. XBRL 파일을 생성하기 위한 Python Finance 라이브러리
  3. XBRL 파일 생성
  4. XBRL에 스키마 참조 추가
  5. XBRL에 컨텍스트 추가
  6. XBRL에서 유닛 생성
  7. XBRL에 팩트 항목 추가
  8. XBRL에 각주 링크 추가
  9. XBRL에 역할 참조 삽입
  10. XBRL에 Arc 역할 참조 추가

XBRL이란 무엇입니까?

XBRL은 XML 기반 마크업 언어인 eXtensible Business Reporting Language의 약자입니다. 회사의 재무 성과에 대한 표준화된 비즈니스 보고에 사용됩니다. 비즈니스 시스템 간에 비즈니스 정보를 통신하고 교환하는 방법을 제공합니다.

XBRL 파일 생성을 위한 Python Finance 라이브러리

XBRL 파일 또는 인스턴스 문서를 생성하기 위해 Aspose.Finance for Python API를 사용할 것입니다. XBRL 인스턴스 생성, 구문 분석 및 XBRL 또는 iXBRL 파일 유효성 검사를 허용합니다.

API는 하나 이상의 XBRL 인스턴스를 포함하는 XBRL 문서를 나타내는 XbrlDocument 클래스를 제공합니다. XBRL 인스턴스는 XBRL 태그가 있는 루트 요소가 있는 XML 조각입니다. XbrlInstance 클래스는 XBRL 인스턴스와 함께 작동하는 다양한 메서드와 속성을 제공합니다. XbrlDocument 클래스의 save() 메서드는 XBRL 파일을 생성하여 디스크에 저장합니다. API 참조에서 XBRL 개체와 함께 작동하는 다른 클래스에 대해 자세히 읽어보십시오.

패키지를 다운로드하거나 콘솔에서 다음 pip 명령을 사용하여 PyPI에서 API를 설치하십시오.

pip install aspose-finance

Python에서 XBRL 인스턴스 문서 만들기

아래 단계에 따라 처음부터 XBRL 인스턴스 문서를 쉽게 만들 수 있습니다.

  1. 먼저 XbrlDocument 클래스의 인스턴스를 만듭니다.
  2. 다음으로 XbrlDocument 개체에서 xbrlinstances 개체로 인스턴스의 컬렉션에 액세스합니다.
  3. 그런 다음 xbrlinstances.add() 메서드를 사용하여 새 XBRL 인스턴스를 추가합니다.
  4. 마지막으로 save(string) 메서드를 사용하여 XBRL 파일을 저장합니다. 출력 파일 경로를 인수로 사용합니다.

다음 코드 샘플은 Python을 사용하여 XBRL 인스턴스를 만드는 방법을 보여줍니다.

# This code example demonstrates how to create an XBRL document
from aspose.finance.xbrl import XbrlDocument

# The path to the documents directory.
outputFile = "C:\\Files\\document.xbrl"

# Create XBRL document
xbrlDoc = XbrlDocument()

# Get document instances collection
xbrlInstances = xbrlDoc.xbrl_instances

# Add instance to the collection
xbrlInstance = xbrlInstances[xbrlInstances.add()]

# Save the file
xbrlDoc.save(outputFile)

XBRL 인스턴스를 생성했으면 새로 생성된 XBRL 인스턴스에 스키마 참조, 컨텍스트, 단위, 항목, 각주 링크, 역할 참조 및 호 역할 참조를 추가할 수 있습니다.

Python을 사용하여 XBRL에 스키마 참조 추가

다음 단계에 따라 XBRL 인스턴스 문서에 스키마 참조를 추가할 수 있습니다.

  1. 먼저 XbrlDocument 클래스의 인스턴스를 만듭니다.
  2. 다음으로 XbrlDocument 개체의 인스턴스 컬렉션을 xbrlinstances 개체로 가져옵니다.
  3. 그런 다음 xbrlinstances.add() 메서드를 사용하여 새 XBRL 인스턴스를 추가합니다.
  4. 다음으로 XbrlInstance 개체의 스키마 참조 컬렉션을 schemarefs 개체로 가져옵니다.
  5. 그런 다음 입력 스키마 파일과 함께 schemarefs.add() 메서드를 사용하여 새 스키마 참조를 추가합니다.
  6. 마지막으로 save(string) 메서드를 사용하여 XBRL 파일을 저장합니다.

다음 코드 샘플은 Python에서 XBRL 인스턴스 문서를 만들고 스키마 참조를 추가하는 방법을 보여줍니다.

# This code example demonstrates how to create an XBRL document and add schema reference object
from aspose.finance.xbrl import XbrlDocument

# The path to the documents directory.
outputFile = "C:\\Files\\document.xbrl"
inputSchemaFile = "C:\\Files\\schema.xsd"

# Create XBRL document
xbrlDoc = XbrlDocument()

# Get document instances collection
xbrlInstances = xbrlDoc.xbrl_instances

# Add instance to the collection
xbrlInstance = xbrlInstances[xbrlInstances.add()]

# Get instance schema references collection
schemaRefs = xbrlInstance.schema_refs

# Add schema
schemaRefs.add(inputSchemaFile, "example", "http://example.com/xbrl/taxonomy")

# Save the document
xbrlDoc.save(outputFile)

Python을 사용하여 XBRL에 컨텍스트 추가

아래 단계에 따라 XBRL 인스턴스 문서에 컨텍스트를 추가할 수 있습니다.

  1. 먼저 XbrlDocument 클래스의 인스턴스를 만듭니다.
  2. 다음으로 XbrlDocument 개체의 xbrlinstances에 새 XBRL 인스턴스를 추가합니다.
  3. 그런 다음 시작 날짜와 종료 날짜를 사용하여 ContextPeriod 클래스의 인스턴스를 만듭니다.
  4. 그런 다음 스키마와 식별자를 사용하여 ContextEntity 개체를 만듭니다.
  5. 그런 다음 정의된 ContextPeriod 및 ContextEntity를 사용하여 Context 클래스의 인스턴스를 만듭니다.
  6. 그런 다음 Context 개체를 컨텍스트 컬렉션에 추가합니다.
  7. 마지막으로 save(string) 메서드를 사용하여 XBRL 파일을 저장합니다.

다음 코드 샘플은 Python에서 XBRL 인스턴스 문서를 만들고 컨텍스트 개체를 추가하는 방법을 보여줍니다.

# This code example demonstrates how to create an XBRL document and add Context object
from datetime import datetime
from aspose.finance.xbrl import XbrlDocument,ContextPeriod,ContextEntity,Context

# The path to the documents directory.
outputFile = "C:\\Files\\document.xbrl"

# Create XBRL document
xbrlDoc = XbrlDocument()

# Get document instances collection
xbrlInstances = xbrlDoc.xbrl_instances

# Add instance to the collection
xbrlInstance = xbrlInstances[xbrlInstances.add()]

# Add context period
contextPeriod = ContextPeriod(datetime(2020,1,1), datetime(2020,2,10))

# Add context entity
contextEntity = ContextEntity("exampleIdentifierScheme", "exampleIdentifier")

# Define and add context
context = Context(contextPeriod, contextEntity)
xbrlInstance.contexts.append(context)

# Save the document
xbrlDoc.save(outputFile)

Python을 사용하여 XBRL에서 단위 생성

XBRL의 단위는 숫자 항목을 측정합니다. 다음 단계에 따라 XBRL 인스턴스 문서에 단위를 추가할 수 있습니다.

  1. 먼저 XbrlDocument 클래스의 인스턴스를 만듭니다.
  2. 다음으로 XbrlDocument 개체의 xbrlinstances에 새 XBRL 인스턴스를 추가합니다.
  3. 그런 다음 UnitType이 MEASURE인 Unit 클래스의 인스턴스를 만듭니다.
  4. 다음으로 QualifiedName을 measurequalifiednames 컬렉션에 추가합니다.
  5. 그런 다음 Units 컬렉션에 Unit을 추가합니다.
  6. 마지막으로 save(string) 메서드를 사용하여 XBRL 파일을 저장합니다.

다음 코드 샘플은 Python에서 XBRL 파일을 생성하고 단위 객체를 추가하는 방법을 보여줍니다.

# This code example demonstrates how to create an XBRL document and add Unit object
from aspose.finance.xbrl import XbrlDocument,Unit,QualifiedName,UnitType

# The path to the documents directory.
outputFile = "C:\\Files\\document.xbrl"

# Create XBRL document
xbrlDoc = XbrlDocument()

# Get document instances collection
xbrlInstances = xbrlDoc.xbrl_instances

# Add instance to the collection
xbrlInstance = xbrlInstances[xbrlInstances.add()]

# Add Unit
unit = Unit(UnitType.MEASURE)
unit.measure_qualified_names.append(QualifiedName("USD", "iso4217", "http://www.xbrl.org/2003/iso4217"))
xbrlInstance.units.append(unit)

# Save the document
xbrlDoc.save(outputFile)

Python을 사용하여 XBRL에 사실 항목 추가

XBRL의 사실은 항목 요소를 사용하여 정의됩니다. XBRL의 항목에는 단순 사실의 값과 해당 사실을 올바르게 해석하기 위한 컨텍스트에 대한 참조가 포함됩니다. 다음 단계에 따라 XBRL 인스턴스 문서에 항목을 추가할 수 있습니다.

  1. 먼저 XbrlDocument 클래스의 인스턴스를 만듭니다.
  2. XbrlDocument 개체의 xbrlinstances에 새 XBRL 인스턴스를 추가합니다.
  3. XbrlInstance 개체의 schemarefs에 새 스키마 참조를 추가합니다.
  4. schemarefs에서 인덱스로 SchemaRef를 가져옵니다.
  5. Context 인스턴스를 초기화하고 컨텍스트 컬렉션에 추가합니다.
  6. Unit 인스턴스를 정의하고 unit 컬렉션에 추가합니다.
  7. getconceptbyname() 메서드를 사용하여 개념 클래스 인스턴스를 만듭니다.
  8. Concept 개체를 인수로 사용하여 Item 클래스의 인스턴스를 만듭니다.
  9. contextref, unitref, 정밀도, 값 등과 같은 항목 속성을 설정합니다.
  10. 그런 다음 사실 수집에 항목을 추가합니다.
  11. 마지막으로 save(string) 메서드를 사용하여 XBRL 파일을 저장합니다.

다음 코드 샘플은 Python을 사용하여 XBRL 인스턴스 문서에서 항목 요소로 팩트를 추가하는 방법을 보여줍니다.

# This code example demonstrates how to create an XBRL document and add Item object
from datetime import datetime
from aspose.finance.xbrl import XbrlDocument,ContextPeriod,ContextEntity,Context,Unit,UnitType,QualifiedName,Item

# The path to the documents directory.
outputFile = "C:\\Files\\document.xbrl"
inputSchemaFile = "C:\\Files\\schema.xsd"

# Create XBRL document
xbrlDoc = XbrlDocument()

# Get document instances collection
xbrlInstances = xbrlDoc.xbrl_instances

# Add instance to the collection
xbrlInstance = xbrlInstances[xbrlInstances.add()]

# Get instance schema references collection
schemaRefs = xbrlInstance.schema_refs

# Add schema
schemaRefs.add(inputSchemaFile, "example", "http://example.com/xbrl/taxonomy")
schema = schemaRefs[0]

# Add context
contextPeriod = ContextPeriod(datetime(2020,1,1), datetime(2020,2,10))
contextEntity = ContextEntity("exampleIdentifierScheme", "exampleIdentifier")
context = Context(contextPeriod, contextEntity)
xbrlInstance.contexts.append(context)

# Add unit
unit = Unit(UnitType.MEASURE)
unit.measure_qualified_names.append(QualifiedName("USD", "iso4217", "http://www.xbrl.org/2003/iso4217"))
xbrlInstance.units.append(unit)

# Add item
fixedAssetsConcept = schema.get_concept_by_name("fixedAssets")
if fixedAssetsConcept is not None:
    item = Item(fixedAssetsConcept)
    item.context_ref = context
    item.unit_ref = unit
    item.precision = 4
    item.value = "1444"
    xbrlInstance.facts.append(item)
    
# Save the document
xbrlDoc.save(outputFile)

아래 단계에 따라 XBRL 인스턴스 문서에 각주 링크를 추가할 수 있습니다.

  1. 먼저 XbrlDocument 클래스의 인스턴스를 만듭니다.
  2. XbrlDocument 개체의 xbrlinstances에 새 XBRL 인스턴스를 추가합니다.
  3. XbrlInstance 개체의 schemarefs에 새 스키마 참조를 추가합니다.
  4. schemarefs에서 인덱스로 SchemaRef를 가져옵니다.
  5. Context 인스턴스를 초기화하고 컨텍스트 컬렉션에 추가합니다.
  6. Footnote 클래스 인스턴스를 정의하고 레이블과 텍스트를 설정합니다.
  7. Loc 클래스 인스턴스를 사용하여 Locator 유형을 초기화합니다.
  8. Locator 레이블과 Footnote 레이블을 인수로 사용하여 FootnoteArc 객체를 정의합니다.
  9. FootnoteLink 클래스의 인스턴스를 만듭니다.
  10. 관련 컬렉션에 Footnote, Locator, FootnoteArc를 추가합니다.
  11. 그런 다음 FootnoteLinks 컬렉션에 FootnoteLink를 추가합니다.
  12. 마지막으로 save(string) 메서드를 사용하여 XBRL 파일을 저장합니다.

다음 코드 샘플은 Python을 사용하여 XBRL 인스턴스 문서에 각주 링크를 추가하는 방법을 보여줍니다.

# This code example demonstrates how to create an XBRL document and add Footnote Link object
from datetime import datetime
from aspose.finance.xbrl import XbrlDocument,ContextPeriod,ContextEntity,Context,FootnoteLink,Footnote,Loc,FootnoteArc

# The path to the documents directory.
outputFile = "C:\\Files\\document.xbrl"
inputSchemaFile = "C:\\Files\\schema.xsd"

# Create XBRL document
xbrlDoc = XbrlDocument()

# Get document instances collection
xbrlInstances = xbrlDoc.xbrl_instances

# Add instance to the collection
xbrlInstance = xbrlInstances[xbrlInstances.add()]

# Get instance schema references collection
schemaRefs = xbrlInstance.schema_refs

# Add schema
schemaRefs.add(inputSchemaFile, "example", "http://example.com/xbrl/taxonomy")
schema = schemaRefs[0]

# Add context
contextPeriod = ContextPeriod(datetime(2020,1,1), datetime(2020,2,10))
contextEntity = ContextEntity("exampleIdentifierScheme", "exampleIdentifier")
context = Context(contextPeriod, contextEntity)
xbrlInstance.contexts.append(context)

# Add Footnote
footnote = Footnote("footnote1")
footnote.text = "Including the effects of the merger."

# Add Location
loc = Loc("#cd1", "fact1")

# Define Footnote arc
footnoteArc = FootnoteArc(loc.label, footnote.label)

# Add FootnoteLink
footnoteLink = FootnoteLink()
footnoteLink.footnotes.append(footnote)
footnoteLink.locators.append(loc)
footnoteLink.footnote_arcs.append(footnoteArc)
xbrlInstance.footnote_links.append(footnoteLink)
    
# Save the document
xbrlDoc.save(outputFile)

Python을 사용하여 XBRL에 역할 참조 삽입

다음 단계에 따라 XBRL 인스턴스 문서에 역할 참조를 추가할 수 있습니다.

  1. 먼저 XbrlDocument 클래스의 인스턴스를 만듭니다.
  2. XbrlDocument 개체의 xbrlinstances에 새 XBRL 인스턴스를 추가합니다.
  3. XbrlInstance 개체의 schemarefs에 새 스키마 참조를 추가합니다.
  4. schemarefs에서 인덱스로 SchemaRef를 가져옵니다.
  5. 다음으로 getroletypebyuri() 메서드에서 RoleType을 가져옵니다.
  6. 그런 다음 RoleType 개체를 인수로 사용하여 RoleReference 클래스의 인스턴스를 만듭니다.
  7. 그런 다음 Rolereferences 컬렉션에 RoleReference를 추가합니다.
  8. 마지막으로 save(string) 메서드를 사용하여 XBRL 파일을 저장합니다.

다음 코드 샘플은 Python을 사용하여 XBRL 인스턴스 문서에 역할 참조를 추가하는 방법을 보여줍니다.

# This code example demonstrates how to create an XBRL document and add Role reference object
from aspose.finance.xbrl import XbrlDocument,RoleReference

# The path to the documents directory.
outputFile = "C:\\Files\\document.xbrl"
inputSchemaFile = "C:\\Files\\schema.xsd"

# Create XBRL document
xbrlDoc = XbrlDocument()

# Get document instances collection
xbrlInstances = xbrlDoc.xbrl_instances

# Add instance to the collection
xbrlInstance = xbrlInstances[xbrlInstances.add()]

# Get instance schema references collection
schemaRefs = xbrlInstance.schema_refs

# Add schema
schemaRefs.add(inputSchemaFile, "example", "http://example.com/xbrl/taxonomy")
schema = schemaRefs[0]

# Get role type
roleType = schema.get_role_type_by_uri("http://abc.com/role/link1")

# Add role reference
if roleType is not None:
    roleReference = RoleReference(roleType)
    xbrlInstance.role_references.append(roleReference)

# Save the document
xbrlDoc.save(outputFile)

Python에서 XBRL에 Arc 역할 참조 추가

다음 단계에 따라 XBRL 인스턴스 문서에 Arc 역할 참조를 추가할 수 있습니다.

  1. 먼저 XbrlDocument 클래스의 인스턴스를 만듭니다.
  2. XbrlDocument 개체의 xbrlinstances에 새 XBRL 인스턴스를 추가합니다.
  3. XbrlInstance 개체의 schemarefs에 새 스키마 참조를 추가합니다.
  4. schemarefs에서 인덱스로 SchemaRef를 가져옵니다.
  5. 다음으로 getarcroletypebyuri() 메서드에서 RoleType을 가져옵니다.
  6. 그런 다음 RoleType 개체를 인수로 사용하여 ArcroleReference 클래스의 인스턴스를 만듭니다.
  7. 그런 다음 arcrolereferences 컬렉션에 ArcroleReference를 추가합니다.
  8. 마지막으로 save(string) 메서드를 사용하여 XBRL 파일을 저장합니다.

다음 코드 샘플은 Python을 사용하여 XBRL 인스턴스 문서에 호 역할 참조를 추가하는 방법을 보여줍니다.

# This code example demonstrates how to create an XBRL document and add Arc Role reference object
from aspose.finance.xbrl import XbrlDocument,ArcroleReference

# The path to the documents directory.
outputFile = "C:\\Files\\document.xbrl"
inputSchemaFile = "C:\\Files\\schema.xsd"

# Create XBRL document
xbrlDoc = XbrlDocument()

# Get document instances collection
xbrlInstances = xbrlDoc.xbrl_instances

# Add instance to the collection
xbrlInstance = xbrlInstances[xbrlInstances.add()]

# Get instance schema references collection
schemaRefs = xbrlInstance.schema_refs

# Add schema
schemaRefs.add(inputSchemaFile, "example", "http://example.com/xbrl/taxonomy")
schema = schemaRefs[0]

# Get role type
roleType = schema.get_role_type_by_uri("http://abc.com/role/link1")

# Add role reference
if roleType is not None:
    arcroleReference = ArcroleReference(roleType)
    xbrlInstance.arcrole_references.append(arcroleReference)

# Save the document
xbrlDoc.save(outputFile)

무료 라이선스 받기

평가 제한 없이 라이브러리를 사용해 보려면 무료 임시 라이센스를 얻으십시오.

결론

이 기사에서는 Python을 사용하여 XBRL 문서를 만드는 방법을 배웠습니다. 또한 프로그래밍 방식으로 생성된 XBRL 인스턴스 문서에 다양한 XBRL 개체를 추가하는 방법을 살펴보았습니다. 또한 문서를 사용하여 Aspose.Finance for Python API에 대해 자세히 알아볼 수 있습니다. 모호한 점이 있는 경우 포럼에서 언제든지 문의하십시오.

또한보십시오