manusimidt / py-xbrl

Python-based parser for parsing XBRL and iXBRL files
https://py-xbrl.readthedocs.io/en/latest/
GNU General Public License v3.0
100 stars 37 forks source link

Currency extraction #41

Closed mrx23dot closed 3 years ago

mrx23dot commented 3 years ago

Any chance we could extract the reportedCurrency e.g: "USD", it's in the high level xbrli header.

<xbrli:measure>iso4217:USD</xbrli:measure>

in https://www.sec.gov/ix?doc=/Archives/edgar/data/0000320193/000032019321000056/aapl-20210327.htm

It's also in xml:

<xbrli:unit id="USD">
<xbrli:measure>iso4217:USD</xbrli:measure>
</xbrli:unit>

https://www.sec.gov/Archives/edgar/data/1403570/000149315221006582/qtmm-20190630.xml

manusimidt commented 3 years ago

Unfortunately I am not entirely sure what you mean. The XbrlInstance object instance has a dictionary called unit_map which stores all units with the corresponding id in the dictionary. image

The parser also automatically links the units to the facts: image

The code I used:

cache: HttpCache = HttpCache('./cache')
xbrlParser = XbrlParser(cache)

xbrl_url = 'https://www.sec.gov/Archives/edgar/data/0000320193/000032019321000056/aapl-20210327.htm'

inst: XbrlInstance = xbrlParser.parse_instance(xbrl_url)
print(inst.unit_map)
print([str(fact.unit) for fact in inst.facts if fact.concept.name == 'Assets'])
mrx23dot commented 3 years ago

Works great, thanks!