Comments (9)
Currently the libary does not combine the information from the presentation linkbase and the instance document.
It just parses the different Locators and Arcs and stores them into the object tree.
This means if you want to rearrange the facts in the instance document according to the presentation linkbase you have to do it on your own.
However I would like to introduce this in the future. I am planning to introduce a method compile_xbrl()
which merges all information of the taxonomy with the facts of the instance document. It would then also be possible to access the facts in the structure given by the presentation linkbase. Unfortunately, I am currently very busy. That's why I won't be able to work on this feature before October.
But a full implementation of this is also quite challenging. Taxonomies can override each other and can prohibit the use of certain relationships. If you really want to implement it properly, you would have to concider overriding and inheritance of hierarchies within multiple imported taxonomies..
Also keep in mind that there are multiple types of taxonomies (calculation, presentation, definition, reference, label, formular ...).
All are based on XLink, I would prefer a solution that works for all types of taxonomies (not only presentation linkbase).
If you want to get an introduction about XBRL Taxonomies you can read my blog entry "What is XBRL?" section "2.2 Taxonomy Linkbases". But this blog entry does not cover inheritance of taxonomies. For a deep dive into XBRL I can only recommend the book "XBRL for Interactive Data" (978-3-642-01437-6).
from py-xbrl.
Labels are stored in the label linkbase the taxonomy schema imports.
py-xbrl
automatically connects the labels to the concepts, so you can just access it from the concept object.
An example:
first_label = fact.concept.labels[0]
Another complete example that also extracts the labels of the members:
logging.basicConfig(level=logging.INFO)
cache: HttpCache = HttpCache('./cache')
cache.set_headers({'From': '[email protected]', 'User-Agent': 'py-xbrl/2.0.7'})
xbrlParser = XbrlParser(cache)
inst: XbrlInstance = xbrlParser.parse_instance(
'https://www.sec.gov/Archives/edgar/data/320193/000032019321000065/aapl-20210626.htm')
for fact in inst.facts:
if fact.concept.name == 'RevenueFromContractWithCustomerExcludingAssessedTax':
label: str = fact.concept.labels[0]
segments: list = fact.context.segments
pretty_str: str = f"{label}: {fact.value}"
for segment in segments:
pretty_str += f" ({segment.dimension}, {segment.member.labels[0]})"
print(pretty_str)
This will return the following output:
Net sales: 63948000000.0 (ProductOrServiceAxis, Products)
Net sales: 46529000000.0 (ProductOrServiceAxis, Products)
Net sales: 232309000000.0 (ProductOrServiceAxis, Products)
Net sales: 170598000000.0 (ProductOrServiceAxis, Products)
Net sales: 17486000000.0 (ProductOrServiceAxis, Services)
Net sales: 13156000000.0 (ProductOrServiceAxis, Services)
Net sales: 50148000000.0 (ProductOrServiceAxis, Services)
Net sales: 39219000000.0 (ProductOrServiceAxis, Services)
Net sales: 81434000000.0
Net sales: 59685000000.0
Net sales: 282457000000.0
Net sales: 209817000000.0
Net sales: 39570000000.0 (ProductOrServiceAxis, iPhone)
Net sales: 26418000000.0 (ProductOrServiceAxis, iPhone)
Net sales: 153105000000.0 (ProductOrServiceAxis, iPhone)
Net sales: 111337000000.0 (ProductOrServiceAxis, iPhone)
Net sales: 8235000000.0 (ProductOrServiceAxis, Mac)
Net sales: 7079000000.0 (ProductOrServiceAxis, Mac)
Net sales: 26012000000.0 (ProductOrServiceAxis, Mac)
Net sales: 19590000000.0 (ProductOrServiceAxis, Mac)
Net sales: 7368000000.0 (ProductOrServiceAxis, iPad)
Net sales: 6582000000.0 (ProductOrServiceAxis, iPad)
Net sales: 23610000000.0 (ProductOrServiceAxis, iPad)
Net sales: 16927000000.0 (ProductOrServiceAxis, iPad)
Net sales: 8775000000.0 (ProductOrServiceAxis, Wearables, Home and Accessories)
Net sales: 6450000000.0 (ProductOrServiceAxis, Wearables, Home and Accessories)
Net sales: 29582000000.0 (ProductOrServiceAxis, Wearables, Home and Accessories)
Net sales: 22744000000.0 (ProductOrServiceAxis, Wearables, Home and Accessories)
Net sales: 17486000000.0 (ProductOrServiceAxis, Services)
Net sales: 13156000000.0 (ProductOrServiceAxis, Services)
Net sales: 50148000000.0 (ProductOrServiceAxis, Services)
Net sales: 39219000000.0 (ProductOrServiceAxis, Services)
Net sales: 81434000000.0
Net sales: 59685000000.0
Net sales: 282457000000.0
Net sales: 209817000000.0
Net sales: 35870000000.0 (StatementBusinessSegmentsAxis, Americas)
Net sales: 27018000000.0 (StatementBusinessSegmentsAxis, Americas)
Net sales: 116486000000.0 (StatementBusinessSegmentsAxis, Americas)
Net sales: 93858000000.0 (StatementBusinessSegmentsAxis, Americas)
Net sales: 18943000000.0 (StatementBusinessSegmentsAxis, Europe)
Net sales: 14173000000.0 (StatementBusinessSegmentsAxis, Europe)
Net sales: 68513000000.0 (StatementBusinessSegmentsAxis, Europe)
Net sales: 51740000000.0 (StatementBusinessSegmentsAxis, Europe)
Net sales: 14762000000.0 (StatementBusinessSegmentsAxis, Greater China)
Net sales: 9329000000.0 (StatementBusinessSegmentsAxis, Greater China)
Net sales: 53803000000.0 (StatementBusinessSegmentsAxis, Greater China)
Net sales: 32362000000.0 (StatementBusinessSegmentsAxis, Greater China)
Net sales: 6464000000.0 (StatementBusinessSegmentsAxis, Japan)
Net sales: 4966000000.0 (StatementBusinessSegmentsAxis, Japan)
Net sales: 22491000000.0 (StatementBusinessSegmentsAxis, Japan)
Net sales: 16395000000.0 (StatementBusinessSegmentsAxis, Japan)
Net sales: 5395000000.0 (StatementBusinessSegmentsAxis, Rest of Asia Pacific)
Net sales: 4199000000.0 (StatementBusinessSegmentsAxis, Rest of Asia Pacific)
Net sales: 21164000000.0 (StatementBusinessSegmentsAxis, Rest of Asia Pacific)
Net sales: 15462000000.0 (StatementBusinessSegmentsAxis, Rest of Asia Pacific)
Process finished with exit code 0
Does this answer your question? :)
from py-xbrl.
This actually does answer my question. I had found a very round about way of doing it which did not work with the old file structure. As a follow up though... is there any way to select for a table? For example the above shows a consolidated statement of operations. I've managed to find where that is specified in the taxonomy, but i am lost as to how i might find the net sales corresponding with that table.
edit:
To rephrase, is there any way to determine which facts belong to the consolidated statement of operations, perhaps through the id or context ref?
from py-xbrl.
This might help, see extracted labels
#21
from py-xbrl.
The #21 was useful in getting the relevant concept names, but is there any way to connect those to individual or specific inst.facts? I was not able to find any arc.to_locator objects which corresponded with anything in the facts object beside the concept.xml_id, but this is not specific enough to select certain facts.
from py-xbrl.
That would be great if we could do
for fact in sections['balance-sheet].facts:
Just please consider keeping recursion at minimum.
from py-xbrl.
@manusimidt Manuel, i know you are busy (i think you mentioned that you continue the studies) but did you have near future plans on compile_xbrl()
(contruction of income statement, balance sheet, cash flow statement) ?
from py-xbrl.
To be honest I haven't started with this feature until now, because I thought that other features had higher priority. Since the compile_xbrl()
is not a basic function, but rather a "nice to have", I have preferred other functions such as the ixbrl format transformations. Realistically, I'm not going to be able to implement it in the next few weeks either, unfortunately because it is a quite big feature..
So at the latest in August when I have semester break again. I will look at this again in the next week and see if I can find a quick way to implement it. It should be possible to develop this functionality outside of py-xbrl
and just use XbrlInstance object you get back from py-xbrl
.
from py-xbrl.
@manusimidt got it, that makes perfect sense.
from py-xbrl.
Related Issues (20)
- Parsing Failures for Empty Fact Values and 'nil' Text in XBRL Documents HOT 2
- Support a New Taxonomy? HOT 1
- Parsing filings with empty imports HOT 3
- Issue with dateMonthDayYearEN function in Transformation __init__ file HOT 1
- xbrl.TaxonomyNotFound HOT 2
- parse_ixbrl does not close the file it opens HOT 4
- No support for embedded/inline schemas HOT 2
- Elements missing after parsing HOT 3
- maximum recursion depth exceeded in __instancecheck__ HOT 4
- Difference between pypi and github releases? HOT 2
- Infinite recursion loops with cyclic taxonomy imports. HOT 2
- Check differences between transformation registry version 4 and 5
- TaxonomyNotFound: The taxonomy with namespace http://xbrl.sec.gov/dei/2024 could not be found. Please check if it is imported in the schema file
- New taxonomy for 2024 HOT 2
- Index out of range HOT 1
- Add contextRef to Json parsing
- Add namespace to Concept
- Support for xbrldi:typedMember HOT 2
- Start getting 403 errors from sec.gov HOT 5
- Any way to link different facts together in a coherent way?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py-xbrl.