Python Examples

Examples using the requests library. Install it with pip install requests.

Basic setup

import os
import requests

API_KEY = os.environ["SEC_API_KEY"]
BASE_URL = "https://api.secdailyapi.com"
HEADERS = {"x-api-key": API_KEY}

Get recent filings

response = requests.get(
    f"{BASE_URL}/filings",
    headers=HEADERS,
    params={"limit": 10}
)
data = response.json()

for filing in data["filings"]:
    print(f"{filing['filingDateInEst']} - {filing['formType']} - {filing.get('entity', {}).get('name', 'N/A')}")

Response:

{
  "filings": [
    {
      "id": "0000320193-24-000123",
      "formType": "10-K",
      "filingDateInEst": "2024-11-01",
      "entity": {
        "name": "Apple Inc.",
        "cik": "0000320193",
        "ticker": "AAPL"
      },
      "linkToFiling": "https://www.sec.gov/Archives/edgar/data/320193/..."
    }
  ],
  "count": 1247,
  "hasMore": true
}

Get 10-K filings for a company

response = requests.get(
    f"{BASE_URL}/filings",
    headers=HEADERS,
    params={
        "cik": "320193",       # Apple
        "formTypes": "10-K",
        "limit": 5
    }
)

for filing in response.json()["filings"]:
    print(f"{filing['filingDateInEst']} - {filing['formType']}")
    print(f"  Link: {filing['linkToFiling']}")

Response:

{
  "filings": [
    {
      "id": "0000320193-24-000123",
      "formType": "10-K",
      "filingDateInEst": "2024-11-01",
      "entity": {
        "name": "Apple Inc.",
        "cik": "0000320193",
        "ticker": "AAPL"
      },
      "periodOfReport": "2024-09-28",
      "linkToFiling": "https://www.sec.gov/Archives/edgar/data/320193/000032019324000123/aapl-20240928.htm"
    }
  ],
  "count": 5,
  "hasMore": false
}

Get insider purchases

response = requests.get(
    f"{BASE_URL}/insider-transactions",
    headers=HEADERS,
    params={
        "transactionTypes": "purchase",
        "limit": 20
    }
)

for txn in response.json()["insiderTransactions"]:
    amount = txn.get("totalAmount", 0)
    print(f"{txn['filingDateInEst']} - CIK {txn['issuerCik']} - ${amount:,.0f}")

Response:

{
  "insiderTransactions": [
    {
      "id": "abc123",
      "accessionNumber": "0001140361-25-001234",
      "issuerCik": "320193",
      "reportingOwnerCik": "1051401",
      "formType": "4",
      "filingDateInEst": "2025-01-16",
      "periodOfReportDate": "2025-01-15",
      "totalAmount": 1250000.00,
      "hasPurchases": true,
      "hasSales": false,
      "normalizedOfficerTitle": "CFO",
      "ownerRoles": "officer"
    }
  ],
  "count": 20,
  "recordedTimeInUtc": "2025-01-17T12:00:00Z"
}

Get insider transactions with date range

response = requests.get(
    f"{BASE_URL}/insider-transactions",
    headers=HEADERS,
    params={
        "issuerCik": "1318605",  # Tesla
        "filingDateInEstStartDate": "2025-01-01",
        "filingDateInEstEndDate": "2025-01-31",
        "limit": 50
    }
)

data = response.json()
print(f"Found {data['count']} transactions")

for txn in data["insiderTransactions"]:
    role = txn.get("normalizedOfficerTitle", txn.get("ownerRoles", ""))
    print(f"  {txn['periodOfReportDate']} - {role} - ${txn.get('totalAmount', 0):,.0f}")

Response:

{
  "insiderTransactions": [
    {
      "id": "def456",
      "accessionNumber": "0001140361-25-002345",
      "issuerCik": "1318605",
      "reportingOwnerCik": "1494730",
      "formType": "4",
      "filingDateInEst": "2025-01-22",
      "periodOfReportDate": "2025-01-20",
      "totalAmount": 4500000.00,
      "hasPurchases": false,
      "hasSales": true,
      "normalizedOfficerTitle": "CEO",
      "ownerRoles": "officer,director"
    }
  ],
  "count": 3,
  "recordedTimeInUtc": "2025-01-23T08:00:00Z"
}

Get latest news

response = requests.get(
    f"{BASE_URL}/news",
    headers=HEADERS,
    params={
        "newsType": "PressReleases",
        "limit": 5
    }
)

for item in response.json()["news"]:
    print(f"{item['publishedDateInUtc'][:10]} - {item['title']}")
    print(f"  Source: {item['source']}")
    print(f"  Link: {item['linkToNews']}")
    print()

Response:

{
  "news": [
    {
      "id": "news-abc123",
      "title": "Apple Reports Q1 2025 Results",
      "summary": "Apple today announced financial results for its fiscal 2025 first quarter...",
      "newsType": "PressReleases",
      "publishedDateInUtc": "2025-01-30T21:30:00Z",
      "source": "BusinessWire",
      "linkToNews": "https://example.com/news/apple-q1-2025"
    }
  ],
  "count": 5,
  "newsType": "PressReleases",
  "lastUpdated": "2025-01-30T22:00:00Z"
}

Error handling

response = requests.get(
    f"{BASE_URL}/filings",
    headers=HEADERS,
    params={"limit": 10}
)

if response.status_code == 200:
    data = response.json()
    print(f"Got {data['count']} filings")
elif response.status_code == 429:
    print("Rate limited — wait and retry")
elif response.status_code == 403:
    print("Invalid API key")
else:
    print(f"Error {response.status_code}: {response.text}")