Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting XBRL data with Arelle

Tags:

xbrl

arelle

After looking over the documentation for arelle on their website, I found the answer. To retrieve the data you need, you can use arelleCmdLine to export a csv specifying relevant data with --factListCols followed by a string of desired data types (separated by spaces). Calling arelleCmdLine varies from os.

CmdL = 'Applications/Arelle.app/contents/MacOS/arelleCmdLine'
os.system('%s --file %s --factListCols "Name Value Period" --facts %s') % (CmdL,xmlPth,csvPth)

I am trying to get "properties" of facts in the "factlist" of an xbrl document. The properties hold the "name" data (or the fact's GAAP taxonomy) and the "contextRef" which holds the date data "StartDate," "endDate" and "instant."

It seems like Arelle is my best bet; however, cmdline utilities dont seem to cut it for this inquiry, and the api documentation Here is entirely blank save for the filenames inside the source.

Is anyone able to explain how to load an xbrl document, load the facts of the fact table and extract the data and meta data from these facts into a list.

Below is a bit of code to help clarify the question. When i try to print modeltuplefacts which i believe holds all the facts and there meta data, i get a blank list. This code is mostly a copy and paste from CustomLogger.py in example in the arelle folder of the arelle package. Im unsure how the logger works, but its needed and this example seems to satisfy the Cntlr requirement for it.

from __future__ import print_function
import sys
sys.path.insert(0, '~/Desktop/Arelle')
from arelle import Cntlr
from arelle import ModelDocument
from arelle import ModelObject as MO
from arelle import ModelInstanceObject as MIO

class CntlrCustomLoggingExample(Cntlr.Cntlr):

    def __init__(self):
        # no logFileName parameter to prevent default logger from starting
        super().__init__()

    def run(self):
        # start custom logger
        CustomLogHandler(self)

        path = "~/Desktop/SEC/SECindexes10-k/fileHolder/1/nick-20150630.xml"
        modelXbrl = self.modelManager.load(path)

        modelDoc = ModelDocument.load(modelXbrl,path)
        mf = MIO.ModelFact()
        mf.init(modelDoc)
        print(mf.modelTupleFacts)

        self.modelManager.close()

        self.close()

import logging
class CustomLogHandler(logging.Handler):
    def __init__(self, cntlr):
        logger = logging.getLogger("arelle")
        self.level = logging.DEBUG
        self.setFormatter(logging.Formatter("[%(messageCode)s] %(message)s - %(file)s %(sourceLine)s"))
        logger.addHandler(self)

    def emit(self, logRecord):
        # just print to standard output (e.g., terminal window)
        print(self.format(logRecord))

if __name__ == "__main__":
    CntlrCustomLoggingExample().run()
like image 475
James Beezho Avatar asked Sep 18 '15 18:09

James Beezho


1 Answers

The simplest answer would be to convert the facts from XBRL into .csv and later on manipulate with .csv file in Python searching for appropriate position. here is the simple code for conversion to .csv :

from arelle import ViewFileFactTable, ModelManager, FileSource, Cntlr, ModelXbrl, ModelDocument

    modelManager = ModelManager.initialize(Cntlr.Cntlr())
    filesource = FileSource.FileSource('C:/XXX/testowy2.xhtml')

    xbrl=ModelXbrl.load(modelManager,'C:/XXX/testowy2.xhtml')

    ViewFileFactTable.viewFacts(xbrl, 'C:/XXX/testowy22.csv')
like image 174
Przemek Avatar answered Jan 03 '23 16:01

Przemek