Skip to content

Commit 5722c57

Browse files
added XBRL-to-JSON converter API
1 parent 28ebf2c commit 5722c57

5 files changed

Lines changed: 245 additions & 3 deletions

File tree

README.md

Lines changed: 195 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ It includes:
55

66
- Query and Full-Text Search API
77
- Real-Time Stream API
8-
- Filings Render API
8+
- XBRL-to-JSON Converter API + Financial Statements
9+
- Filing Render & Download API
910

1011

1112
# Data Coverage
@@ -14,6 +15,7 @@ It includes:
1415
- **All +150 filing types** are supported, eg 10-Q, 10-K, 4, 8-K, 13-F, S-1, 424B4 and many more.
1516
[See the list of supported form types here.](https://sec-api.io/list-of-sec-filing-types)
1617
- Newly published filings are accessible in real-time
18+
- XBRL-to-JSON converter and parser API. Extract standardized financial statements from any 10-K and 10-Q filing.
1719
- 13F holdings API included. Monitor all institutional ownerships in real-time.
1820
- Every filing is **mapped to a CIK and ticker**
1921
- All filings in JSON - **no XBRL/XML**
@@ -165,10 +167,200 @@ print(filings)
165167
> See the documentation for more details: https://sec-api.io/docs/full-text-search-api
166168
167169

168-
# Filing Render API
170+
# XBRL-To-JSON Converter API
169171

170-
Used to fetch the content of any filing or exhibit.
172+
Parse and standardize any XBRL and convert it to JSON or pandas dataframes. Extract financial statements and meta data from 10-K and 10-Q filings.
171173

174+
The entire US GAAP taxonomy is fully supported. All XBRL items are fully converted into JSON, including `us-gaap`, `dei` and custom items. XBRL facts are automatically mapped to their respective context including period instants and date ranges.
175+
176+
All financial statements are accessible and standardized:
177+
178+
- StatementsOfIncome
179+
- StatementsOfIncomeParenthetical
180+
- StatementsOfComprehensiveIncome
181+
- StatementsOfComprehensiveIncomeParenthetical
182+
- BalanceSheets
183+
- BalanceSheetsParenthetical
184+
- StatementsOfCashFlows
185+
- StatementsOfCashFlowsParenthetical
186+
- StatementsOfShareholdersEquity
187+
- StatementsOfShareholdersEquityParenthetical
188+
189+
Variants such as `ConsolidatedStatementsofOperations` or `ConsolidatedStatementsOfLossIncome` are automatically standardized to their root name, e.g. `StatementsOfIncome`.
190+
191+
## Income Statement - Example Item
192+
193+
```json
194+
{
195+
"StatementsOfIncome": {
196+
"RevenueFromContractWithCustomerExcludingAssessedTax": [
197+
{
198+
"decimals": "-6",
199+
"unitRef": "usd",
200+
"period": {
201+
"startDate": "2019-09-29",
202+
"endDate": "2020-09-26"
203+
},
204+
"value": "274515000000"
205+
},
206+
{
207+
"decimals": "-6",
208+
"unitRef": "usd",
209+
"period": {
210+
"startDate": "2018-09-30",
211+
"endDate": "2019-09-28"
212+
},
213+
"value": "260174000000"
214+
}
215+
]
216+
}
217+
}
218+
```
219+
220+
## Usage
221+
222+
There are 3 ways to convert XBRL to JSON:
223+
224+
- `htm_url`: Provide the URL of the filing ending with `.htm`.
225+
Example URL: https://www.sec.gov/Archives/edgar/data/1318605/000156459021004599/tsla-10k_20201231.htm
226+
- `xbrl_url`: Provide the URL of the XBRL file ending with `.xml`. The XBRL file URL can be found in the `dataFiles` array returned by our query API. The array item has the description `EXTRACTED XBRL INSTANCE DOCUMENT` or similar.
227+
Example URL: https://www.sec.gov/Archives/edgar/data/1318605/000156459021004599/tsla-10k_20201231_htm.xml
228+
- `accession_no`: Provide the accession number of the filing, e.g. `0001564590-21-004599`
229+
230+
231+
```python
232+
from sec_api import XbrlApi
233+
234+
xbrlApi = XbrlApi("YOUR_API_KEY")
235+
236+
# 10-K HTM File URL example
237+
xbrl_json = xbrlApi.xbrl_to_json(
238+
htm_url="https://www.sec.gov/Archives/edgar/data/320193/000032019320000096/aapl-20200926.htm"
239+
)
240+
241+
# access income statement, balance sheet and cash flow statement
242+
print(xbrl_json["StatementsOfIncome"])
243+
print(xbrl_json["BalanceSheets"])
244+
print(xbrl_json["StatementsOfCashFlows"])
245+
246+
# 10-K XBRL File URL example
247+
xbrl_json = xbrlApi.xbrl_to_json(
248+
xbrl_url="https://www.sec.gov/Archives/edgar/data/1318605/000156459021004599/tsla-10k_20201231_htm.xml"
249+
)
250+
251+
# 10-K accession number example
252+
xbrl_json = xbrlApi.xbrl_to_json(accession_no="0001564590-21-004599")
253+
```
254+
255+
## Example Response
256+
257+
Note: response is shortened.
258+
259+
```json
260+
{
261+
"CoverPage": {
262+
"DocumentPeriodEndDate": "2020-09-26",
263+
"EntityRegistrantName": "Apple Inc.",
264+
"EntityIncorporationStateCountryCode": "CA",
265+
"EntityTaxIdentificationNumber": "94-2404110",
266+
"EntityAddressAddressLine1": "One Apple Park Way",
267+
"EntityAddressCityOrTown": "Cupertino",
268+
"EntityAddressStateOrProvince": "CA",
269+
"EntityAddressPostalZipCode": "95014",
270+
"CityAreaCode": "408",
271+
"LocalPhoneNumber": "996-1010",
272+
"TradingSymbol": "AAPL",
273+
"EntityPublicFloat": {
274+
"decimals": "-6",
275+
"unitRef": "usd",
276+
"period": {
277+
"instant": "2020-03-27"
278+
},
279+
"value": "1070633000000"
280+
},
281+
"EntityCommonStockSharesOutstanding": {
282+
"decimals": "-3",
283+
"unitRef": "shares",
284+
"period": {
285+
"instant": "2020-10-16"
286+
},
287+
"value": "17001802000"
288+
},
289+
"DocumentFiscalPeriodFocus": "FY",
290+
"CurrentFiscalYearEndDate": "--09-26"
291+
},
292+
"StatementsOfIncome": {
293+
"RevenueFromContractWithCustomerExcludingAssessedTax": [
294+
{
295+
"decimals": "-6",
296+
"unitRef": "usd",
297+
"period": {
298+
"startDate": "2019-09-29",
299+
"endDate": "2020-09-26"
300+
},
301+
"segment": {
302+
"dimension": "srt:ProductOrServiceAxis",
303+
"value": "us-gaap:ProductMember"
304+
},
305+
"value": "220747000000"
306+
},
307+
{
308+
"decimals": "-6",
309+
"unitRef": "usd",
310+
"period": {
311+
"startDate": "2018-09-30",
312+
"endDate": "2019-09-28"
313+
},
314+
"segment": {
315+
"dimension": "srt:ProductOrServiceAxis",
316+
"value": "us-gaap:ProductMember"
317+
},
318+
"value": "213883000000"
319+
}
320+
]
321+
},
322+
"BalanceSheets": {
323+
"CashAndCashEquivalentsAtCarryingValue": [
324+
{
325+
"decimals": "-6",
326+
"unitRef": "usd",
327+
"period": {
328+
"instant": "2020-09-26"
329+
},
330+
"value": "38016000000"
331+
},
332+
{
333+
"decimals": "-6",
334+
"unitRef": "usd",
335+
"period": {
336+
"instant": "2019-09-28"
337+
},
338+
"value": "48844000000"
339+
},
340+
{
341+
"decimals": "-6",
342+
"unitRef": "usd",
343+
"period": {
344+
"instant": "2020-09-26"
345+
},
346+
"segment": {
347+
"dimension": "us-gaap:FinancialInstrumentAxis",
348+
"value": "us-gaap:CashMember"
349+
},
350+
"value": "17773000000"
351+
}
352+
]
353+
}
354+
}
355+
```
356+
357+
> See the documentation for more details: https://sec-api.io/docs/xbrl-to-json-converter-api
358+
359+
360+
361+
# Filing Render & Download API
362+
363+
Used to download any filing or exhibit. You can process the downloaded filing in memory or save the filing to your hard drive.
172364

173365
```python
174366
from sec_api import RenderApi

examples.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from sec_api.index import XbrlApi
2+
3+
xbrlApi = XbrlApi("YOUR_API_KEY")
4+
5+
# 10-K HTM File URL example
6+
xbrl_json_1 = xbrlApi.xbrl_to_json(
7+
htm_url="https://www.sec.gov/Archives/edgar/data/320193/000032019320000096/aapl-20200926.htm"
8+
)
9+
10+
print(xbrl_json_1["StatementsOfIncome"])
11+
print(xbrl_json_1["BalanceSheets"])
12+
print(xbrl_json_1["StatementsOfCashFlows"])
13+
14+
# 10-K XBRL File URL example
15+
xbrl_json_2 = xbrlApi.xbrl_to_json(
16+
xbrl_url="https://www.sec.gov/Archives/edgar/data/1318605/000156459021004599/tsla-10k_20201231_htm.xml"
17+
)
18+
19+
# 10-K XBRL File URL example
20+
xbrl_json_3 = xbrlApi.xbrl_to_json(accession_no="0001564590-21-004599")
291 Bytes
Binary file not shown.
2.83 KB
Binary file not shown.

sec_api/index.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import requests
2+
import json
23

34
query_api_endpoint = "https://api.sec-api.io"
45
full_text_search_api_endpoint = "https://api.sec-api.io/full-text-search"
56
render_api_endpoint = "https://api.sec-api.io/filing-reader"
7+
xbrl_api_endpoint = "https://api.sec-api.io/xbrl-to-json"
68

79

810
class QueryApi:
@@ -46,3 +48,31 @@ def get_filing(self, url):
4648
_url = self.api_endpoint + "&type=html&url=" + url
4749
response = requests.get(_url)
4850
return response.text
51+
52+
53+
class XbrlApi:
54+
"""
55+
Base class for XBRL-to-JSON API
56+
"""
57+
58+
def __init__(self, api_key):
59+
self.api_key = api_key
60+
self.api_endpoint = xbrl_api_endpoint + "?token=" + api_key
61+
62+
def xbrl_to_json(self, htm_url="", xbrl_url="", accession_no=""):
63+
if len(htm_url) == 0 and len(xbrl_url) == 0 and len(accession_no) == 0:
64+
raise ValueError("htm_url, xbrl_url or accession_no must be present")
65+
66+
_url = ""
67+
68+
if len(htm_url):
69+
_url = self.api_endpoint + "&htm-url=" + htm_url
70+
71+
if len(xbrl_url):
72+
_url = self.api_endpoint + "&xbrl-url=" + xbrl_url
73+
74+
if len(accession_no):
75+
_url = self.api_endpoint + "&accession-no=" + accession_no
76+
77+
response = requests.get(_url)
78+
return json.loads(response.text)

0 commit comments

Comments
 (0)