DEV Community

13F Chat
13F Chat

Posted on

Pulling SEC EDGAR Data with Python: A Beginner's Guide

Every quarter the SEC publishes thousands of filings on EDGAR, and all of it is free. If you're a developer curious about finance data, here's what I learned getting started.

1. Identify yourself

EDGAR asks every automated client to send a descriptive User-Agent with a contact email, and to stay under about 10 requests per second. If you skip this you'll get 403s.

import requests
HEADERS = {"User-Agent": "my-research-script you@example.com"}
Enter fullscreen mode Exit fullscreen mode

2. Use the JSON APIs, not HTML scraping

data.sec.gov serves clean JSON:

  • https://data.sec.gov/submissions/CIK##########.json lists a company's recent filings
  • https://data.sec.gov/api/xbrl/companyfacts/CIK##########.json returns every XBRL fact (revenue, assets...) the company has reported

CIKs must be zero-padded to 10 digits.

cik = "320193"  # Apple
url = f"https://data.sec.gov/submissions/CIK{cik.zfill(10)}.json"
data = requests.get(url, headers=HEADERS).json()
recent = data["filings"]["recent"]
for form, date in list(zip(recent["form"], recent["filingDate"]))[:10]:
    print(form, date)
Enter fullscreen mode Exit fullscreen mode

3. Know the form types

  • 10-K / 10-Q: annual and quarterly reports
  • 8-K: material events
  • 4: insider transactions
  • 13F-HR: quarterly holdings of large investment managers
  • SC 13D / 13G: 5%+ ownership stakes

4. Cache everything

Filings never change after they're accepted, so cache responses on disk. You'll stay well within rate limits and iterate faster.

5. Watch the units

XBRL facts come with units (USD, shares, USD/share) and periods (instant vs duration). Mixing a quarterly duration with an annual one is the most common bug I hit.

That's enough to build a small personal dashboard in an afternoon. Happy parsing!

Top comments (0)