ZeferiniX
ZeferiniX

Reputation: 500

How to extract financial statements only from XBRL files using Arelle's Python API?

Somehow, with the broken documentation on Arelle's python API as of date, I managed to make the API work and successfully load an XBRL file.

Anyways, my question is:

How do I extract only the STATEMENTS from the XBRL file?

Below is a screenshot from Arelle's Windows App.

URL used in this example: https://www.sec.gov/Archives/edgar/data/101984/000010198416000062/ueic-20151231.xml

Arelle GUI

I tried experimenting with the API and here's my code

from arelle import Cntlr

xbrl = Cntlr.Cntlr().modelManager.load('https://www.sec.gov/Archives/edgar/data/101984/000010198416000062/ueic-20151231.xml')

for fact in xbrl.facts:
   print(fact)

but after executing this snippet, I'm bombarded with these:

PyCharm CLI

I tried getting the keys available per modelFact and its a mixture between contextRef, id, decimals and unitRef which is not helpful from what I want to extract. With no documentation to help further with this, I'm at a loss here. Can someone enlighten me on how to achieve extracting only the statements?

Upvotes: 4

Views: 4014

Answers (1)

jeronimo
jeronimo

Reputation: 241

I am doing something similar and have so far had some progress which I can share:

Going through the python code files of arelle you can detect which properties you can access for the different classes such as ModelFact, ModelContext, ModelUnit etc.

To extract the individual data, you can for example put them in a panda dataframe as follows:

factData=pd.DataFrame(data=[(fact.concept.qname,
                           fact.value,
                           fact.isNumeric,
                           fact.contextID,
                           fact.context.isStartEndPeriod,
                           fact.context.isInstantPeriod,
                           fact.context.isForeverPeriod,
                           fact.context.startDatetime,
                           fact.context.endDatetime,
                           fact.unitID) for fact in xbrl.facts])

Now it is easier to work with all the data, filter those that you want to use etc. If you want to reproduce the statements tables, you will also need to incorporate the links for each of the facts and than order and sort, but I haven't gotten this far either.

Upvotes: 3

Related Questions