Is it possible to parse the GAAP standards taxonomy? #111
-
Hi @manusimidt. Thanks for such a great library. I've really enjoyed digging into the code. I'm new to XBRL, but reading through your answers to #21 and #109 I was quickly able to print out a hierarchy from the presentation linkbases when I provided an iXBRL schema URL for a company. However, what I'm really after is creating a presentation linkbase hierarchy from the GAAP standards themselves, unrelated to a specific company. Which I believe would essentially be parsing a https://xbrl.fasb.org/us-gaap/2022/elts/us-gaap-2022.xsd schema(?) I'm trying to create a similar https://xbrlview.fasb.org schema output which could be used to understand the parent relationship of a child concept. For example, how Ultimately I'm trying to create something similar to http://www.xbrlsite.com/2018/Prototype/ReportingStylesUSGAAP/COMID-BSU-CF2-IS5-IEMIB-OILN/mapping-definition.html which could be used to reference which fundamental abstract concepts a child GAAP concept belongs to. I am currently able to create a hierarchy of the presentation linkbases with The full hierarchy tree shown from the https://xbrlview.fasb.org/ screenshot above is what I'm trying to achieve. After reading through #103, I'm unsure if this is the proper library for such a task, but wanted to start a discussion to understand if this is something that would be easy to accomplish with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I was finally able to find time to return to this project and I realized I completely missed the Here's a sample code snippet in case anyone else comes across this: from xbrl.cache import HttpCache
from xbrl.taxonomy import TaxonomySchema, parse_taxonomy_url
from xbrl.linkbase import PresentationArc
cache: HttpCache = HttpCache('./.cache')
schema_paths = [
# TODO: Dynamically fetch all root XSD files from `stm` and `dis` directories
# at https://xbrl.fasb.org/us-gaap/2022/ and other years of choice
"https://xbrl.fasb.org/us-gaap/2022/stm/us-gaap-stm-soc-2022.xsd",
"https://xbrl.fasb.org/us-gaap/2022/dis/us-gaap-dis-rcc-2022.xsd",
# ...
]
def print_presentation_arc(level: int, arc: PresentationArc):
print(f"{' ' * level}{arc.to_locator.concept_id}")
for child_arc in arc.to_locator.children:
print_presentation_arc(level + 1, child_arc)
for schema_path in schema_paths:
taxonomy: TaxonomySchema = parse_taxonomy_url(schema_path, cache)
for pre_linkbase in taxonomy.pre_linkbases:
for elr in pre_linkbase.extended_links:
print(f"\n\n")
print(elr.elr_id.split('#')[1])
# if the elr is empty, skip it
if len(elr.root_locators) == 0: continue
# print abstract
print(f" {elr.root_locators[0].concept_id}")
for root_locator in elr.root_locators:
for pre_arc in root_locator.children:
print_presentation_arc(2, pre_arc) Obviously change your output style/file as needed, this is just an example. Thanks again for the great library! |
Beta Was this translation helpful? Give feedback.
-
Hey @scottcarlson, sorry for my late answer, for some reason I did not get a notification for the question you asked a week ago. Thanks for the feedback, always nice to hear that |
Beta Was this translation helpful? Give feedback.
I was finally able to find time to return to this project and I realized I completely missed the
TaxonomySchema
functionality. With that I was able to create what I needed.Here's a sample code snippet in case anyone else comes across this: