Generated documentation, of the gitHub source code API, is available at: API Documentation.

The Python API requires a Controller (subclass of Cntlr.py) to initiate modelManager operations.  The controller must have two feedback methods, addToLog (for messages) and showStatus(for status messages if they are desired).  CntlrCmdLine.py will be explained to demonstrate the minimum API:

modelManager = ModelManager.initialize(self)

Initializes the model manager, and provides the calling instance (self), needed for the callbacks to addToLog and showStatus.

filesource = FileSource.FileSource(“c:\test\abc.xsd”)

A filesource instance is a wrapper for files that may be ordinary files or zip/xfd/frm archive files.  If the file is not an archive, the filesource just retains the file path, but if it is an archive, then contents of the archive (such as an instance document to read first) can be specified by the filesource.select(“instance.xml”) method.

self.modelManager.validateInferDecimals

Select calculation linkbase checks, inferring decimals, to be performed by validate operation.

self.modelManager.validateInferPrecision

Select calculation linkbase checks, inferring precision, to be performed by validate operation.

modelManager.validateDisclosureSystem = True

Used to inform the modelManager when Disclosure System rules validation (such as U.S. SEC Edgar or Japan FSA) is desired.  Must be set before loading an entry point document.  Edgar Filing Manual and Global Filing Manual are currently implemented. 

modelManager.disclosureSystem.select(“efm”)

Used to select which disclosure system rules to apply (e.g., U.S. SEC Edgar, Japan FSA).  The parameter must match one of the disclosure system names in the file lib/disclosuresystems.xml.  For example, the file entry names=”Japan FSA|jp-fsa|fsa” means that any of the these three name alternatives would specify the Japan FSA rule set.

self.modelManager.validateUtr

Select Unit Type Registry validation is to be performed by the validate operation.

modelManager.load(filesource, “subsequent action”)

Asks the modelManager to load the entry point specified by the filesource.  If successful, the prompt specified by the second argument will be displayed to the showStatus callback method.

modelManager.validate()

Performs validation applicable to the entry point (including that specified by the validateSEC option, if entry file is an instance or DTS).  Any errors and other messages are provided to the addToLog callback method.

modelManager.close()

Closes the last-opened entry point and releases resources.

To compare two DTSes and produce a versioning report, please replace modelManager.validate(), above, with these:

modelManager.load(diffFilesource, _(“views loading”))
modelManager.compareDTSes(versioningReportFileName)

The first .load represents the fromDTS, the second .load represents the toDTS.   The file name provided by compareDTSes is that used to save the versioning report.

Note that two entries were loaded, so there should be two modelManager.close() calls, which act in LIFO manner to close the corresponding .load()’ed entry.

Development Environment

There are several excellent Python-based development environments.  Many XBRL practitioners have spent their lives with Java; they can use  Eclipse, configured for Python (pydev), which is compatible with Arelle.

 

5 Responses to API, Python

  1. ding says:

    Hi, I’m new to python.

    Try to write code as instructed in the “API” section, created a controller, but then ran into the “_” problem: global name ‘_’ is not defined

    import gettext, time, datetime
    import xml.dom.minidom, xml.parsers.expat, os
    from arelle import (Cntlr, FileSource, ModelManager, ModelXbrl, ModelDocument, XmlUtil, Version)
    from arelle import (XbrlConst, XmlUtil, UrlUtil, ModelObject, ValidateFilingText, XmlValidate)
    from arelle.ModelValue import (qname)

    def main():
    ArelleCntlrSample().run()

    class ArelleCntlrSample(Cntlr.Cntlr):
    def __init__(self):
    super().__init__()

    def run(self):
    self.messages = []
    modelManager = ModelManager.initialize(self)
    filesource = FileSource.FileSource(“L:\\home\\research\\xbrl\\us-gaap\\samples\\Marriott_20110617\\mar-20110617.xml”)
    modelManager.load(filesource, _(“views loading”)) ### not working need to expand

    def addToLog(self, message):
    if self.messages is not None:
    self.messages.append(message + ‘\n’)
    else:
    print(message) # allows printing on standard out

    def showStatus(self, message, clearAfter=None):
    pass

    if __name__ == “__main__”:
    main()

  2. hephaestus says:

    The API Documentation page at http://arelle.readthedocs.org/en/latest/index.html (redirected from http://arelle.rtfd.org) contains only a listing of the modules in the Arelle package. There are no links from any of the items in the module listing to the corresponding module contents.

    Configuration or build problem, perhaps?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>