ferc_xbrl_extractor.arelle_interface#
Abstract away interface to Arelle XBRL Library.
Classes#
Pydantic model that defines XBRL references. |
|
Pydantic model that defines XBRL calculations. |
|
Pydantic model that defines metadata extracted from XBRL taxonomies. |
Functions#
|
Use Arelle to load a taxonomy and build its parent-child relationship view. |
|
Load XBRL taxonomy, and parse relationships. |
Load an XBRL taxonomy from a zipfile archive. |
Module Contents#
- ferc_xbrl_extractor.arelle_interface._taxonomy_view(taxonomy_source: str | arelle.FileSource.FileSource, max_retries: int = 7) tuple[arelle.ModelXbrl.ModelXbrl, arelle.ViewFileRelationshipSet.ViewRelationshipSet][source]#
Use Arelle to load a taxonomy and build its parent-child relationship view.
As it parses a taxonomy, Arelle downloads the schema/linkbase files it references to a local on-disk cache (managed by Arelle’s own
webCache), then reads them back from there. When two or more callers load the same taxonomy concurrently – e.g. multiple threads or processes each extracting a different filing that shares one taxonomy version – their cache writes can race, and Arelle raisesFileExistsErrorwhen one caller tries to create a cache file another is already writing.This is a transient condition, not a real failure: by the time we retry, the other caller has usually finished writing the file, so the retried
ModelXbrl.loadcall reads the now-complete cache entry instead of trying to write it again. The loop therefore retries onlyFileExistsError, with exponential backoff, up tomax_retriesattempts before giving up and re-raising. Any other exception (a genuinely missing taxonomy, malformed XBRL, an unrelated network error, …) is allowed to propagate immediately on the first attempt, since retrying those wouldn’t help – they aren’t the race this loop exists to work around. Seetest_concurrent_taxonomy_load(integration) andtest_taxonomy_view_retries_then_raises_after_max_retries(unit) for coverage of this behavior.- Parameters:
taxonomy_source – URL, local path, or in-memory
FileSourcepointing at the taxonomy entry point.max_retries – Maximum number of load attempts before giving up and re-raising the last
FileExistsError.
- ferc_xbrl_extractor.arelle_interface.load_taxonomy(path: str | pathlib.Path) tuple[arelle.ModelXbrl.ModelXbrl, arelle.ViewFileRelationshipSet.ViewRelationshipSet][source]#
Load XBRL taxonomy, and parse relationships.
- Parameters:
path – URL or local path pointing to an XBRL taxonomy.
- ferc_xbrl_extractor.arelle_interface.load_taxonomy_from_archive(taxonomy_archive: BinaryIO, entry_point: str | pathlib.Path) tuple[arelle.ModelXbrl.ModelXbrl, arelle.ViewFileRelationshipSet.ViewRelationshipSet][source]#
Load an XBRL taxonomy from a zipfile archive.
- Parameters:
taxonomy_archive – In memory taxonomy archive.
entry_point – Relative path to taxonomy entry point within archive.
- class ferc_xbrl_extractor.arelle_interface.References(/, **data: Any)[source]#
Bases:
pydantic.BaseModelPydantic model that defines XBRL references.
FERC uses XBRL references to link Concepts defined in its taxonomy to the physical paper form. These are included in the output metadata and can be useful for linking between XBRL and DBF data.
This model is not a generic representation of XBRL references, but specific to those used by FERC.
- class ferc_xbrl_extractor.arelle_interface.Calculation(/, **data: Any)[source]#
Bases:
pydantic.BaseModelPydantic model that defines XBRL calculations.
XBRL calculation relationships are also included in the metadata. Calculations are a validation tool used to define relationships between facts using some mathematical formula. For example, a calculation relationship might denote that one fact is equal to the sum of 2 or more other facts, and this relationship can be used to validate a filing.
- class ferc_xbrl_extractor.arelle_interface.Metadata(/, **data: Any)[source]#
Bases:
pydantic.BaseModelPydantic model that defines metadata extracted from XBRL taxonomies.
Taxonomies contain various metadata which are useful for interpreting XBRL filings. The metadata fields being extracted here include references, calculations, and balances.
- references: References[source]#
- calculations: list[Calculation][source]#