jadchaar / sec-edgar-downloader

πŸ“ˆ Download filings from the SEC EDGAR database using Python
https://sec-edgar-downloader.readthedocs.io
MIT License
485 stars 136 forks source link

Download straight to variable / memory #132

Open Elijas opened 11 months ago

Elijas commented 11 months ago

Hello πŸ‘‹,

I'm using sec-edgar-downloader and would like to know if it's possible to directly download filings (e.g., 10-Q for AAPL) in HTML format without file access?

The workaround I'm using currently is:

from sec_downloader import Downloader

dl = Downloader("MyCompanyName", "email@example.com")
html = dl.get_latest_html("10-Q", "AAPL")
print(f"{html[:50]}...")
<?xml version="1.0" ?><!--XBRL Document Created wi...

which is implemented as

# pip install sec-edgar-downloader sec-downloader

from sec_edgar_downloader import Downloader
from sec_downloader import DownloadStorage

ONLY_HTML = "**/*.htm*"

storage = DownloadStorage(filter_pattern=ONLY_HTML)
with storage as path:
    dl = Downloader("MyCompanyName", "email@example.com", path)
    dl.get("10-Q", "AAPL", limit=1, download_details=True)
# all files are now deleted and only stored in memory

content = storage.get_file_contents()[0].content
print(f"{content[:50]}...")
<?xml version="1.0" ?><!--XBRL Document Created wi...
jadchaar commented 11 months ago

Hi @Elijas, currently this tool only downloads and stores filings onto disk, but I will note this down for a future improvement.