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
111 stars 40 forks source link

add parse_ixbrl_diskcache_version to accelarate access parsed ixbrls. #90

Open fhopecc opened 1 year ago

fhopecc commented 1 year ago

The logical content of public xbrl can be thought unchangeable lately when it is submited or publiced by the organizations, so its parsed result can be cached in disk to accelerate accessing lately. For HttpCache caches xml files in disk, not python object dumps, parse_ixbrl function is very slow for it will parsed xml to make python object(xbrl instance) again . I add parse_ixbrl_diskcache_version function, it uses diskcache to store the parse result in python object dump format. For load the python dump file is faster than get object from parsing xml. I recommend to use diskcache replacing HttpCache to cache parse results. In addition, diskcache hide the cache detail to let the user merely focus on parse xbrl file or url.

manusimidt commented 1 year ago

Hey, Thanks for your pull request.

I wonder what the use case for this is. py-xbrl currently uses a memory-based LRU-cache for caching taxonomies. You can see this in the taxonomy module: https://github.com/manusimidt/py-xbrl/blob/61a518e7d5efc69647c3f2844540ed78fe39a313/xbrl/taxonomy.py#L509-L510

This speeds up the parsing dramatically because submissions from the same year and country usually use the same taxonomies. If you for example parse 1000 xbrl documents from the SEC, the US-gaap taxonomy will only be loaded once from the file system and then cached into memory.

However, if I see correctly you want to store the python object of the XBRL instance to the file system, correct? Most people using this library are just using it to extract the facts from the incredibly big XML files and then store it either in a json file, a csv file, into a database or into pandas dataframes. So normally you would not need the Xbrlinstance again.

manusimidt commented 1 year ago

@fhopecc Thanks for your interest in py-xbrl and your proposed contributions. I have a hard time understanding what this pull request is about. The title add parse_ixbrl_diskcache_version to accelerate access parsed ixbrls. suggests that you want to cache something with diskcache. However, you added many more commits to this pull request that (and correct me if I am wrong) have nothing to do with the description of the pull request.

If you want me to merge the changes from you I would ask you to use different pull requests for thematically different changes.

Thanks, Manu