Validate XBRL in Python

XBRL stands for XML Based Business Reporting Language. It is simply a schema that helps companies to organize their data so that they can share information between various departments within their company. XBRL and Inline XBRL (iXBRL) documents are structured electronic business reports to meet different business requirements. It is not just another type of boring business document — XBRL documents contain certain structure, format and characteristics which can be used to validate the financial documents. We can easily validate an XBRL or iXBRL instance document programmatically. In this article, we will learn how to validate an XBRL document in Python.

The following topics shall be covered in this article:

  1. Python XBRL Validator API to Validate XBRL Document
  2. Validate XBRL File
  3. Validate Inline XBRL File

Python XBRL Validator API to Validate XBRL Document

To validate 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 API provides the XbrlDocument class that 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 validate() method of this class validates the selected XBRL instance. We have the InlineXbrlDocument class of the API that represents an inline XBRL document. Moreover, the ValidationErrorCode enumeration of the API defines all the validation error codes and respective error message.

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

pip install aspose-finance

Validate XBRL Document in Python

We can easily load and validate 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, call the validate() method to validate the XBRL instance.
  5. Finally, show the errors if any.

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

Validate Inline XBRL Document in Python

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

  1. Firstly, load an iXBRL file using the InlineXbrlDocument class.
  2. After that, call the validate() method to validate the XBRL instance.
  3. Finally, show the errors if any.

The following code sample shows how to validate an inline XBRL or iXBRL document 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 validate an XBRL document in Python. We have also seen how to validate an inline XBRL document programmatically. Besides, you can learn more about Aspose.Finance for Python API using documentation. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also