getting XBRL data with Arelle
Asked Answered
A

1

6

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()
Alexei answered 18/9, 2015 at 18:26 Comment(3)
This is not a well-formed question - there is no real problem defined, neither is there any example of your own input into solving it. On the other hand XBRL is f*cked up and not easy to learn... (Disclaimer: I know what XBRL is, I don't know that technology in-depth, so I cannot help) I would suggest editing this question according to this: stackoverflow.com/help/on-topic and stackoverflow.com/help/dont-ask - this will make it easier for other users to hep you. Actually, I am myself interested in knowing the answer ;)Huss
Are you restricted to Arelle and Python?Usk
Did you have any luck using Arelle to do this? I (think I) am trying to do the same thing as youWingfooted
F
4

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')
Floatable answered 27/2, 2018 at 11:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.