SEC EDGAR and Python: A Quick Start to the Real Endpoints
How to pull filer history, financial facts and ticker lookups from SEC EDGAR with plain Python, using the SEC's own JSON endpoints.
- SEC EDGAR exposes most of its structured data as free JSON endpoints under data.sec.gov, with no API key required.
- A company's 10-digit CIK is the key that links the ticker file, the submissions API and the XBRL APIs together.
- The submissions API gives a filer's full filing history; the companyfacts, companyconcept and frames APIs give XBRL financial data at different levels of granularity.
- Every call needs a declared User-Agent header, and the SEC asks automated clients to stay under 10 requests per second.
"SEC EDGAR Python" usually means one of two things: downloading the actual filing documents, or pulling structured company data (filing history, financial facts, tickers) as JSON. This guide covers the second case: how to call SEC EDGAR's own JSON endpoints with plain Python, with no third-party library and no API key.
Quick start
Every example below needs only the standard library and a declared User-Agent, which the SEC's access rules require on every request (see SEC EDGAR rate limits and the fair access policy for the full rules):
import json
import urllib.request
HEADERS = {"User-Agent": "Your Company yourname@example.com"}
def get_json(url):
req = urllib.request.Request(url, headers=HEADERS)
with urllib.request.urlopen(req) as resp:
return json.loads(resp.read())
Everything else in this guide is a URL you pass to get_json.
Step 1: ticker to CIK
Most of EDGAR's APIs are keyed by CIK (Central Index Key), not ticker, so the first step is usually a lookup. The SEC publishes a ticker-to-CIK mapping at sec.gov/files/company_tickers.json:
tickers = get_json("https://www.sec.gov/files/company_tickers.json")
by_ticker = {row["ticker"]: row for row in tickers.values()}
cik = by_ticker["AAPL"]["cik_str"]
The file maps ticker, CIK and the company's EDGAR-conformed name. A sister file, company_tickers_exchange.json, adds the listing exchange.
Get this data as clean JSON
SecFeed turns SEC filings into structured data with one API call: GET /v1/xbrl/company-facts?ticker=MSFT. Free key, no card needed.
Step 2: a filer's history with the submissions API
Once you have a CIK, zero-pad it to 10 digits and call the submissions endpoint for that filer's recent filing history:
cik10 = str(cik).zfill(10)
filer = get_json(f"https://data.sec.gov/submissions/CIK{cik10}.json")
recent = filer["filings"]["recent"]
for form, date, acc in zip(recent["form"], recent["filingDate"], recent["accessionNumber"]):
print(form, date, acc)
The response includes the company's name, SIC code, fiscal year end and former names at the top level, plus a filings.recent block with parallel arrays for form type, filing date and accession number. For a company with a long filing history, filings.recent only holds the most recent slice; older filings are paginated into separate JSON files listed under filings.files, each covering an earlier date range, so a full history sometimes means fetching more than one file and concatenating the arrays.
A common use for this endpoint is counting or filtering a filer's history by form type without touching anything else:
tens_k = [d for f, d in zip(recent["form"], recent["filingDate"]) if f == "10-K"]
print(f"{len(tens_k)} 10-K filings in this slice, most recent {tens_k[0] if tens_k else 'none'}")
Because filings.recent is capped, this only counts what is in the current slice. To count a company's entire history you need to also walk filings.files and merge in the older pages before filtering.
Step 3: financial facts from the XBRL APIs
EDGAR's XBRL data is available through three related endpoints, all under data.sec.gov/api/xbrl/:
| Endpoint | What it returns | Example |
|---|---|---|
companyfacts/CIK{10}.json | Every XBRL concept the company has ever reported, in one call | companyfacts/CIK0000320193.json |
companyconcept/CIK{10}/{taxonomy}/{concept}.json | One concept's full history for one company | companyconcept/CIK0000320193/us-gaap/Revenues.json |
frames/{taxonomy}/{concept}/{unit}/{period}.json | One concept, one period, across every company that reported it | frames/us-gaap/Assets/USD/CY2025Q4I.json |
companyfacts is the right call when you want everything about one company and are fine with a large response. companyconcept is lighter when you only need one line item, for example building a revenue time series. frames flips the axis: one fact per company for a single period, useful for cross-company comparisons. Period codes follow a pattern: CY2025 for a full calendar year, CY2025Q4 for a quarter, and the I suffix (CY2025Q4I) for an instantaneous value like a balance sheet figure measured at a point in time rather than over a duration.
concept = get_json(
"https://data.sec.gov/api/xbrl/companyconcept/CIK0000320193/us-gaap/Revenues.json"
)
for row in concept["units"]["USD"]:
print(row["end"], row["val"], row["form"])
data.sec.gov does not support CORS, so calls from a browser will fail; they need to run server side.Common mistakes that cause errors
A few things trip up a first script against these endpoints:
- Missing or generic
User-Agent. A request with noUser-Agent, or a default one like a bare library name, gets rejected. The header needs an identifying string, typically a name and an email address. - Mixing up
www.sec.govanddata.sec.gov. Filing documents and the full text search UI live underwww.sec.gov; the submissions, XBRL and ticker JSON endpoints used above live underdata.sec.gov. Calling the wrong host for a given file returns a 404, not a redirect. - Unpadded CIK.
data.sec.gov/submissions/CIK320193.json(no leading zeros) fails; it has to be the 10-digit, zero-padded form shown above. - Treating
companyconcepttags as universal. Not every company tags everyus-gaapconcept the same way; a smaller or foreign filer may reportRevenuesunder a different element, or not at all for a given year, so a missing concept is not necessarily a bug in your code.
Step 4: full text and filing documents
The JSON endpoints above cover metadata and XBRL facts, not the prose inside a filing. For that, EDGAR's full text search covers filings since 2001, and the documents themselves sit at predictable URLs under sec.gov/Archives/edgar/data/, which downloading SEC filings with Python covers in detail, including how to read a filing's index page before fetching the files it lists.
Where plain Python runs into limits
Each of the endpoints above answers one question for one company or one period. Building a multi-company screen, a time series across many filers, or a search that combines form type, date range and company metadata means making many calls yourself and stitching the results together, while staying under the SEC's request rate. An API that has already indexed the data sideways can do that in one call. For example, SecFeed exposes the same XBRL facts without the CIK lookup step:
curl "https://secfeedapi.com/v1/xbrl/company-facts?ticker=MSFT" \
-H "Authorization: Bearer YOUR_API_KEY"
from secfeed import Client
sf = Client("YOUR_API_KEY")
facts = sf.get("/v1/xbrl/company-facts", params={"ticker": "MSFT"})
It also answers cross-company questions directly, such as screening every filer on an XBRL condition for a quarter, which the SEC's own frames endpoint only does one concept and one period at a time.
Frequently asked questions
Do I need an API key to use SEC EDGAR's own endpoints?
No. The SEC's own JSON endpoints under data.sec.gov and the full-text search system require no account or key, only a declared User-Agent header.
What format is the CIK in these URLs?
A 10-digit, zero-padded number, written as CIK followed by the digits, for example CIK0000320193 for Apple. The plain CIK without padding (320193) works in some EDGAR URLs but not in the data.sec.gov JSON endpoints.
What is the difference between companyfacts and companyconcept?
companyfacts returns every XBRL concept a company has ever tagged, in one large response. companyconcept returns the full history of a single named concept for a single company, which is faster and smaller when you only need one line item.
Can I get XBRL data across many companies at once with plain Python?
The frames endpoint returns one concept for one period across every company that reported it, which covers simple cross-company comparisons. Combining several concepts or screening on conditions means fetching multiple frames yourself and joining them in code.
Is there a Python library that wraps these endpoints?
Several third-party libraries wrap the SEC's EDGAR endpoints, but this guide only covers calling the SEC's own JSON APIs directly with the standard library, since that always works without adding a dependency.
Get this data as clean JSON
SecFeed turns SEC filings into structured data with one API call: GET /v1/xbrl/company-facts?ticker=MSFT. Free key, no card needed.
For information only, not investment advice. Data from public SEC filings; verify important figures on SEC.gov. See our AI Disclosure.