EDINET API v2:以 CSV 簡化 XBRL 財務申報資料處理
EDINET API v2: XBRL filings as CSV without the pain
EDINET API v2 是日本官方免費財務申報 API,提供約十年申報資料,並可透過 type=5 取得 CSV 格式數據,免去只需數字時解析完整 XBRL。type=5 資料採用 UTF-16 編碼、以 tab 分隔,且每個欄位均加引號,讀取時須留意格式細節。API 支援按日期範圍搜尋,方便批量擷取及定期取得新增資料。
The problem: Japanese financial filings in a usable shape
If you want annual or quarterly financials for Japanese companies, the filings are real and public, but they sit in XBRL. XBRL is great for regulators and lousy for a quick pipeline: it is verbose, namespaced, and tied to taxonomy dictionaries. My first attempts to pull company financials meant wrestling XBRL documents and their taxonomies into something I could actually compute on. It was painful enough that I kept looking for a shortcut, and the right shortcut is the official one.
The direct answer: EDINET API v2 is Japan's official financial filings API, and it exposes XBRL metadata and documents for essentially all filers going back about ten years, free. For bulk work, the type=5 form delivers the data as CSV so I can skip the full XBRL parse when all I need is the numbers.
Where the CSV simplicity hides
The type=5 CSV form is what makes EDINET usable as a data source rather than a document dump. It flattens financial data into a CSV-like payload that I can load into analysis directly. But "CSV-like" deserves the qualifier, because the format has quirks that will break a naive reader.
Three things bit me. The payload is UTF-16 encoded, not UTF-8. The delimiter is a tab, not a comma. And every field is quoted, like a fully escaped TSV. My normal CSV parser choked on the encoding on the first try, and even after fixing that, the all-fields-quoted layout needs the right handling to split lines cleanly. Once I put the splitlines handling in place, the data comes through reliably, but it is precisely the kind of edge case that makes a canned "just use csv.reader" approach fail silently.
Auth lives in a header, not a query param
A detail that cost me a round-trip: the API authenticates with an Ocp-Apim-Subscription-Key header, not a query parameter. If you are used to appending a key to the URL, you will get a rejection before you ever reach the data. It is a small thing, but it is the kind of contract detail that determines whether an integration is smooth or a morning of debugging. Because the credential goes in a header, it stays out of the URL, which also keeps it out of the obvious places where query strings end up logged. I still keep the key behind my normal key-handling practices rather than embedding it in anything that ships. I describe it as the subscription key; the actual value never leaves my controlled environment.
Bulk ingestion and date-range search
The API supports searching by date range, and that is the lever for doing this at scale. I ingest financial data for hundreds of companies programmatically, which would be miserable one filing at a time. Searching by range and pulling the type=5 CSV form means I can batch the work instead of scripting per-company lookups. Searching by date also maps cleanly onto a recurring job: I know what moved since the last run, and I fetch only the new material.
Why official EDINET wins
The case for EDINET over an unofficial feed is the same one I apply across data sources: when an official API exists with a stated contract and a subscription-key auth model, it is more reliable and it avoids the upkeep of chasing a feed that might change without notice. An unofficial EDINET mirror can work, but it is a source of truth I do not control. My preference is the official API first, unofficial only when there is no other choice.
None of this is to say the official API is turnkey — the UTF-16, tab-delimited, every-field-quoted CSV is a reminder that "official" and "ergonomic" are different things. But it is official, it is free, and it gives me a ten-year window of filings. That combination is hard to beat.
The rest of the Japanese-API cluster
The other pieces I use with this one: Getting Japanese government statistics via the e-Stat API, the corporate number API, IRBANK API, GAS web app proxies and kintone from the CLI. Full map: Japan's public APIs for agents.
For anyone pulling Japanese financials, my advice is: start from EDINET API v2, use the type=5 CSV form, and fix the encoding and delimiter up front. What has your experience been with XBRL taxonomies versus the flattened CSV — is the raw XBRL worth the extra parsing for you?
Originally published at agentjournal.dev.
來源:DEV Community · dev.to