Fetch the file

The SEC serves company facts at data.sec.gov with no API key. Its developer FAQ asks every automated client to declare a User-Agent with a name and contact email, and sets a maximum rate of 10 requests per second. Pad the CIK to 10 digits.

import datetime as dt
import gzip
import json
import urllib.request

HEADERS = {
    "User-Agent": "Your Name your.email@example.com",
    "Accept-Encoding": "gzip, deflate",
}
cik = 320193  # Apple Inc.
url = f"https://data.sec.gov/api/xbrl/companyfacts/CIK{cik:010d}.json"
req = urllib.request.Request(url, headers=HEADERS)
with urllib.request.urlopen(req, timeout=30) as resp:
    body = resp.read()
    if resp.headers.get("Content-Encoding") == "gzip":
        body = gzip.decompress(body)
facts = json.loads(body)

Replace the User-Agent with your own details. On 2 December 2026 Apple's file was 3,859,564 bytes uncompressed and 277,466 bytes with gzip, so asking for gzip saves most of the transfer.

The shape of the file

{
  "cik": 320193,
  "entityName": "Apple Inc.",
  "facts": { "dei": {}, "us-gaap": {}, "ffd": {} }
}

Each top-level key under facts is a taxonomy. On 2 December 2026 Apple's file had 512 us-gaap concepts, 2 dei and 6 ffd. Under each concept you get a label, a description and units.

Units matter. Across Apple's us-gaap concepts the file used USD (450 concepts), shares (24), pure (18), USD/shares (17), Year (5) and Store (1). Revenue sits in USD and earnings per share in USD/shares, so pick the unit on purpose.

One row

{"start": "2025-09-28", "end": "2026-09-26", "val": 478834000000,
 "accn": "0000320193-26-000026", "fy": 2026, "fp": "FY",
 "form": "10-K", "filed": "2026-11-03", "frame": "CY2026"}
FieldMeaning
start, endThe period the number covers. Balance sheet items have only end.
valThe number, in whole units.
accnAccession number of the filing that reported the row.
fy, fpFiscal year and period of the filing, which can differ from the row's period.
formThe form type, such as 10-K or 10-Q.
filedThe date of that filing.
frameA calendar period label, present on at most one row per period.

Why one period has several rows

For Apple's revenue concept, RevenueFromContractWithCustomerExcludingAssessedTax in USD, the counts on 2 December 2026 were:

MeasureCount
Rows120
Distinct start-to-end periods58
Periods with 1, 2, 3 or 4 rows11, 35, 9, 3
Rows with a frame40
Periods whose rows disagree on val0

Apple's fiscal 2024 revenue, $391,035 million, appears three times: in the 10-Ks filed on 1 November 2024, 31 October 2025 and 3 November 2026. The first reports it. The other two repeat it as a prior-year comparison, and each repeat adds a row. When repeats agree, you have one fact seen three times. When they disagree, you may have a restatement.

Trap 1: filtering on fy and fp

The filter fy == 2024 and fp == "FY" on Apple's revenue concept returns three rows:

startendval ($M)filed
2021-09-262022-09-24394,3282024-11-01
2022-09-252023-09-30383,2852024-11-01
2023-10-012024-09-28391,0352024-11-01

All three come from the one 10-K filed on 1 November 2024, which shows three years. Use end and the length of the period instead.

Trap 2: quarters and year-to-date share one list

Of Apple's 58 revenue periods, 30 run about three months, 10 run about a year, 9 run about six months and 9 run about nine months. The six- and nine-month rows are year to date. The fourth quarter has no three-month row, because no 10-Q covers it. The article on quarterly vs TTM numbers shows how to derive it.

Pick one value per period

This continues the script above and keeps one row per fiscal year end:

def days(row):
    start = dt.date.fromisoformat(row["start"])
    end = dt.date.fromisoformat(row["end"])
    return (end - start).days + 1


def annual(rows, pick="first"):
    """One row per fiscal year end. pick="first" keeps the first filed row, "latest" the last."""
    chosen = {}
    for row in rows:
        if "start" not in row or not 350 <= days(row) <= 380:
            continue
        key = row["end"]
        if key not in chosen:
            chosen[key] = row
        elif pick == "first" and row["filed"] < chosen[key]["filed"]:
            chosen[key] = row
        elif pick == "latest" and row["filed"] > chosen[key]["filed"]:
            chosen[key] = row
    return [chosen[k] for k in sorted(chosen)]


tag = facts["facts"]["us-gaap"]["RevenueFromContractWithCustomerExcludingAssessedTax"]
for row in annual(tag["units"]["USD"])[-4:]:
    print(row["end"], row["val"] // 10**6, row["filed"], row["form"])

Output on 2 December 2026:

2023-09-30 383285 2023-11-03 10-K
2024-09-28 391035 2024-11-01 10-K
2025-09-27 416161 2025-10-31 10-K
2026-09-26 478834 2026-11-03 10-K

The function returns 10 fiscal years for this concept, and first and latest give the same values, since no Apple revenue period disagrees. Choose first when you need what the market could see at the time, as in a backtest. Choose latest for the company's current view. The file gives a filing date but no time of day.

What the file leaves out

The SEC says company facts include only facts that use a non-custom taxonomy and apply to the whole company. Company-defined tags and product or segment breakdowns are missing, so Apple's Products and Services split is not in the file.

Foreign filers can use a different taxonomy. Taiwan Semiconductor Manufacturing's file (CIK 1046179) has no us-gaap group at all. It has ifrs-full with 334 concepts, plus dei and srt, and its rows come from 20-F and 6-K forms. A us-gaap lookup on it raises a KeyError.

One idea can also move across tags. Apple's annual revenue sat under three different tags between 2009 and 2026, so reading one tag gives you a short history. See standardized vs as-reported statements for how that plays out.

Younesa is building US company data from SEC filings.