Read XBRL in Python

XBRL and Inline XBRL (iXBRL) documents are structured electronic business reports to meet different business requirements. An XBRL document is a collection of facts that together make up a business report. Whereas, an iXBRL report is a human-readable report with tagged data embedded in it. We can easily parse an XBRL or iXBRL instance document programmatically and read objects or elements such as schema reference, context, unit, items, etc. In the previous post, we have seen how to create an XBRL document. In this article, we will learn how to parse an XBRL document in Python.

The following topics shall be covered in this article:

  1. XBRL Parser Python API to Parse XBRL
  2. Parse XBRL File
  3. Parse iXBRL File

XBRL Parser Python API to Parse XBRL

To parse an XBRL file or instance document, we will be using the Aspose.Finance for Python API. It allows creating XBRL instances, parsing, and validating the XBRL or iXBRL files.

The XbrlDocument class of the API represents an XBRL document containing one or more XBRL instances. An XBRL instance is an XML fragment, with the root element having an XBRL tag. The XbrlInstance class provides various methods and properties to work with XBRL instances. The InlineXbrlDocument class of the API represents an inline XBRL document.

Please either download the package or install the API from PyPI using the following pip command in the console:

pip install aspose-finance

Parse XBRL File in Python

We can easily load and parse an XBRL instance document by following the steps given below:

  1. Firstly, load an XBRL file using the XbrlDocument class.
  2. Next, get all the instances using the xbrl_instances.
  3. Then, access the desired XBRL instance from the collection.
  4. After that, parse the content of the XBRL instance.
  5. Finally, show the required data/information.

The following code sample shows how to parse an XBRL instance in Python.

Parse iXBRL File in Python

We can also parse an iXBRL document by following the steps given below:

  1. Firstly, load an iXBRL file using the InlineXbrlDocument class.
  2. Parse the content of the iXBRL document.

The following code sample shows how to parse an iXBRL in Python.

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

In this article, we have learned how to parse an XBRL or iBXRL document in Python. We have also seen how to extract data from XBRL instance objects programmatically. Besides, you can learn more about Aspose.Finance for Python API using the documentation. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also