# Download SEC Filings and Exhibits With Python > Python examples for the EDGAR File & SEC Filings Download API. Download any filing, exhibit, XML file or complete submission text file from EDGAR to local disk using the sec-api Python package. Source: https://sec-api.io/docs/edgar-file-and-sec-filings-download-api/python-example The examples below use the `sec-api` Python package to download any file published on SEC EDGAR: a filing, one of its exhibits, an XML data file or the complete submission text file. The API returns the file exactly as filed, so nothing is converted or reformatted. To convert a filing to PDF instead, see the [PDF Generator API Python example](https://sec-api.io/docs/sec-filings-to-pdf-generator-api/python-example). ## Installation Install the package with pip: ``` pip install sec-api ``` ## Download a filing `get_filing` takes the sec.gov URL of the filing and returns its content as a string. The example saves Abiomed's Form 8-K to disk. ```python from sec_api import DownloadApi downloadApi = DownloadApi("YOUR_API_KEY") url = "https://www.sec.gov/Archives/edgar/data/815094/000156459021006205/abmd-8k_20210211.htm" filing = downloadApi.get_filing(url) with open("abmd-8k.htm", "w") as f: f.write(filing) ``` ## Download an exhibit Exhibits are files in the same folder as the filing, so the same call downloads them. Exhibit URLs are listed in the `documentFormatFiles` array returned by the [Filing Search API](https://sec-api.io/docs/query-api). ```python from sec_api import DownloadApi downloadApi = DownloadApi("YOUR_API_KEY") # Exhibit 99.1, a press release attached to an 8-K url = "https://www.sec.gov/Archives/edgar/data/320193/000032019326000018/a8-kex991q3202606272026.htm" exhibit = downloadApi.get_file(url) with open("exhibit-99-1.htm", "w") as f: f.write(exhibit) ``` ## Download images and other binaries Set `return_binary=True` for files that are not text, such as the graphics attached to a proxy statement, and write the result in binary mode. ```python from sec_api import DownloadApi downloadApi = DownloadApi("YOUR_API_KEY") url = "https://www.sec.gov/Archives/edgar/data/320193/000130817926000008/aapl014016-logo.jpg" image = downloadApi.get_file(url, return_binary=True) with open("logo.jpg", "wb") as f: f.write(image) ``` ## Download the filings of a company The Download API pairs with the [Filing Search API](https://sec-api.io/docs/query-api): search returns the URLs, download fetches the files. The example saves every Apple 10-K filed since 2015. ```python from sec_api import QueryApi, DownloadApi queryApi = QueryApi("YOUR_API_KEY") downloadApi = DownloadApi("YOUR_API_KEY") query = { "query": 'ticker:AAPL AND formType:"10-K" AND filedAt:[2015-01-01 TO 2026-12-31]', "from": "0", "size": "20", "sort": [{"filedAt": {"order": "desc"}}], } filings = queryApi.get_filings(query)["filings"] for filing in filings: url = filing["linkToFilingDetails"] name = filing["accessionNo"] + ".htm" with open(name, "w") as f: f.write(downloadApi.get_filing(url)) print("saved", name) ``` ## Good to know - The URL must point at the file itself under `sec.gov/Archives`. An inline XBRL viewer URL contains `/ix?doc=`, which has to be removed first. - `get_filing` and `get_file` behave the same way. Both accept any EDGAR file, whatever its type. - The complete submission text file, the `.txt` at the end of a filing index, downloads the whole submission including every exhibit in one request.