### Install py-xbrl using pip Source: https://github.com/manusimidt/py-xbrl/blob/main/docs/usage.rst This command installs the py-xbrl library using the pip package installer. Ensure you have pip installed and accessible in your system's PATH. ```console $ pip install py-xbrl ``` -------------------------------- ### Example XBRL-JSON structure Source: https://github.com/manusimidt/py-xbrl/blob/main/docs/usage.rst This is an example of the JSON structure generated by py-xbrl for an XBRL report, following the XBRL-JSON recommendation. ```json { "documentInfo": { "documentType": "https://xbrl.org/2021/xbrl-json", "taxonomy": [ ``` -------------------------------- ### Retrieve Labels for a Concept in Linkbase (Python) Source: https://github.com/manusimidt/py-xbrl/blob/main/feature_ideas.md Demonstrates an inefficient method for retrieving labels associated with a specific concept within a Linkbase using a for loop. This approach has O(n) complexity. Future improvements aim to provide direct access to labels, reducing the need for manual iteration. ```python for locator in linkbase.extended_links[0].root_locators: if locator.concept_id != 'ifrs-full_Assets': continue # Here you have the label label: str = locator.children[0].labels[0].text ``` -------------------------------- ### Initialize HttpCache for py-xbrl Source: https://github.com/manusimidt/py-xbrl/blob/main/docs/usage.rst Initializes an HttpCache object to manage downloaded taxonomy files. You must specify a cache location where all XML files will be stored. This cache is automatically used by py-xbrl for downloading and parsing taxonomies. ```python from cache import HttpCache cache: HttpCache = HttpCache('./cache') ``` -------------------------------- ### Parse XBRL from local file with py-xbrl Source: https://github.com/manusimidt/py-xbrl/blob/main/docs/usage.rst Parses XBRL submissions stored locally on your hard drive. Ensure all supporting XML files (taxonomies, linkbases) are downloaded and placed in the correct directory structure relative to the instance file, or specify the `instance_url` parameter. ```python import logging from xbrl.cache import HttpCache from xbrl.instance import XbrlParser, XbrlInstance # just to see which files are downloaded logging.basicConfig(level=logging.INFO) cache: HttpCache = HttpCache('./cache') parser = XbrlParser(cache) schema_path = "./cache/aapl-20210925/aapl-20210925.html" inst: XbrlInstance = parser.parse_instance(schema_path) ``` -------------------------------- ### HttpCache Class Source: https://github.com/manusimidt/py-xbrl/blob/main/docs/modules/cache.rst Handles disk caching for downloaded files, serving them from the file system on subsequent requests. It also supports delaying HTTP requests to reduce server load. ```APIDOC ## HttpCache Class ### Description This class manages a simple disk cache. It downloads requested files and stores them in a user-specified folder. If a file is requested again, it is served directly from the file system. The cache path is derived from the file's URL. ### Method __init__ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "cache_directory": "D:/cache" } ``` ### Response #### Success Response (200) None (This is a class constructor) #### Response Example None ``` -------------------------------- ### Parse XBRL from URL with py-xbrl Source: https://github.com/manusimidt/py-xbrl/blob/main/docs/usage.rst Parses XBRL submissions directly from a web URL. py-xbrl automatically downloads necessary files and stores them in the specified cache. Ensure HTTP headers are set correctly, especially for services like SEC EDGAR. ```python import logging from xbrl.cache import HttpCache from xbrl.instance import XbrlParser, XbrlInstance # just to see which files are downloaded logging.basicConfig(level=logging.INFO) cache: HttpCache = HttpCache('./cache') cache.set_headers({'From': 'YOUR@EMAIL.com', 'User-Agent': 'Company Name AdminContact@.com'}) parser = XbrlParser(cache) schema_url = "https://www.sec.gov/Archives/edgar/data/0000320193/000032019321000105/aapl-20210925.htm" inst: XbrlInstance = parser.parse_instance(schema_url) ``` -------------------------------- ### Cache Edgar Enclosure Source: https://github.com/manusimidt/py-xbrl/blob/main/docs/modules/cache.rst A function within the HttpCache class to cache Edgar enclosures, recommended for batch downloads to manage server load. ```APIDOC ## Cache Edgar Enclosure ### Description This method is part of the `HttpCache` class and is designed to cache Edgar enclosures. It is highly recommended for downloading XBRL submissions in batches to minimize the load on the SEC's EDGAR system. ### Method cache_edgar_enclosure ### Endpoint N/A (This is a method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Assuming 'cache' is an instance of HttpCache cache.cache_edgar_enclosure(url='https://www.sec.gov/Archives/edgar/data/...') ``` ### Response #### Success Response (200) Details of the cached enclosure (specifics depend on implementation). #### Response Example ```json { "cached_path": "D:/cache/www.sec.gov/Archives/..." } ``` ``` -------------------------------- ### Convert XBRL Instance to JSON with py-xbrl Source: https://github.com/manusimidt/py-xbrl/blob/main/docs/usage.rst Converts an XBRLInstance object to its JSON representation. The JSON format follows the XBRL International 2021 recommendation. Use `override_fact_ids=True` to simplify fact identifiers. The JSON can be printed to the console or saved to a file. ```python # print json to console print(inst.json(override_fact_ids=True)) # save to file inst.json('./test.json') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.