我希望将XBRL报表实例,特别是SEC生成的财务报表,转换为Python字典或JSON。我花了一些时间使用bs4(漂亮汤(开发代码,但理想情况下,我想利用开源的Arelle库。
我的理解是,有一个用于Arelle软件包的插件;saveLoadableOIM";。XBRL.org发布了通用指南;然而,它还没有实际实现。
http://www.xbrl.org/Specification/xbrl-json/CR-2020-05-06/xbrl-json-CR-2020-05-06.html
我发现命令提示符使用Arelle的文档已经过时了;不适用于Python 3.x。有人能通过Python命令提示符提供如何操作Arelle的指导吗;具体来说,如何将SEC xBRL报表实例转换为JSON?我想要一个适应标准分类法未来变化的模型,特别是GAAP:
https://www.sec.gov/info/edgar/edgartaxonomies.shtml
将以下MSFT10-K的XBRL报告实例映射为JSON:的示例代码将特别有用
https://www.sec.gov/Archives/edgar/data/789019/000156459018019062/msft-20180630.xml
如果现有的Arelle库存在限制,我想了解这些限制是什么。
我在Python 3下用调用Arelle
python3 $HOME/Arelle/arelleCmdLine.py
这是在Linux上,并且假设我已经在主目录中将Arelle签出为Arelle
。
要加载插件,请使用--plugins
,并为其提供Arelle/arelle/plugin
目录下的文件名(不带.py
扩展名(。例如,--plugins=saveLoadableOIM
。然后,您可以添加--help
,您应该会看到帮助消息中包含的其他选项。
这对我有效:
python3 $HOME/Arelle/arelleCmdLine.py --plugins=saveLoadableOIM --saveLoadableOIM=msft.json -f https://www.sec.gov/Archives/edgar/data/789019/000156459018019062/msft-20180630.xml
使用令人敬畏的jq:提取数据的示例
jq '[.facts[] | select( .dimensions.concept | test(":GrossProfit$") )] | sort_by(.dimensions.period)[-1]' msft.json
这将获得最新的GrossProfile值:
{
"value": "20343000000",
"decimals": -6,
"dimensions": {
"concept": "us-gaap:GrossProfit",
"entity": "cik:0000789019",
"period": "2018-04-01T00:00:00/2018-07-01T00:00:00",
"unit": "iso4217:USD"
}
}
我应该注意的是,xBRL JSON规范还没有最终确定,这个JSON的格式可能会随着时间的推移而略有变化。我希望Arelle在发布后能更新到最终版本。
我不得不解决同样的问题,并开发了一个通用的xBRL到JSON转换器,该转换器可以自动适应美国公认会计原则分类法的任何变化。
API从10-K(和10-Q(文件中提取所有xBRL财务报表,将其标准化并转换为JSON。使用熊猫数据帧就像一个符咒。
您可以提供
-
xBRL文件的URL,例如MSFT 10-K文件https://www.sec.gov/Archives/edgar/data/789019/000156459018019062/msft-20180630.xml
-
文件的HTML文件的URL,例如。https://www.sec.gov/Archives/edgar/data/789019/000156459018019062/msft-10k_20180630.htm
-
文件的登录号,例如
0001564590-18-019062
标准化财务报表包括:
- 收入报表
- 收入明细表
- 综合收益表
- 全面收入报表
- 资产负债表
- 资产负债表Parenthical
- 现金流量表
- 现金流量表
- 股东权益声明
- 股东权益声明
变体(如ConsolidatedStatementsofOperations
或ConsolidatedStatementsOfLossIncome
(会自动标准化为其根名称,例如StatementsOfIncome
。
示例
API支持GET HTTP方法。换句话说,您可以通过提供xBRL文件URL和API返回完全转换的JSON来发出一个简单的GET请求。
将xbrl file转换为json
GET请求到:
https://api.sec-api.io/xbrl-to-json?
xbrl-url=https://www.sec.gov/Archives/edgar/data/789019/000156459018019062/msft-20180630.xml&
token=YOUR_API_KEY
转换的json
注:此处为短版。
{
"StatementsOfIncome": {
"RevenueFromContractWithCustomerExcludingAssessedTax": [
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"value": "274515000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"value": "260174000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"value": "265595000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ProductMember"
},
"value": "220747000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ProductMember"
},
"value": "213883000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ProductMember"
},
"value": "225847000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ServiceMember"
},
"value": "53768000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ServiceMember"
},
"value": "46291000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ServiceMember"
},
"value": "39748000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:IPhoneMember"
},
"value": "137781000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:IPhoneMember"
},
"value": "142381000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:IPhoneMember"
},
"value": "164888000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:MacMember"
},
"value": "28622000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:MacMember"
},
"value": "25740000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:MacMember"
},
"value": "25198000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:IPadMember"
},
"value": "23724000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:IPadMember"
},
"value": "21280000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:IPadMember"
},
"value": "18380000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:WearablesHomeandAccessoriesMember"
},
"value": "30620000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:WearablesHomeandAccessoriesMember"
},
"value": "24482000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "aapl:WearablesHomeandAccessoriesMember"
},
"value": "17381000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:AmericasSegmentMember"
},
"value": "124556000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:AmericasSegmentMember"
},
"value": "116914000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:AmericasSegmentMember"
},
"value": "112093000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:EuropeSegmentMember"
},
"value": "68640000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:EuropeSegmentMember"
},
"value": "60288000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:EuropeSegmentMember"
},
"value": "62420000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:GreaterChinaSegmentMember"
},
"value": "40308000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:GreaterChinaSegmentMember"
},
"value": "43678000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:GreaterChinaSegmentMember"
},
"value": "51942000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:JapanSegmentMember"
},
"value": "21418000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:JapanSegmentMember"
},
"value": "21506000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:JapanSegmentMember"
},
"value": "21733000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:RestOfAsiaPacificSegmentMember"
},
"value": "19593000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:RestOfAsiaPacificSegmentMember"
},
"value": "17788000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "us-gaap:StatementBusinessSegmentsAxis",
"value": "aapl:RestOfAsiaPacificSegmentMember"
},
"value": "17407000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:StatementGeographicalAxis",
"value": "country:US"
},
"value": "109197000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:StatementGeographicalAxis",
"value": "country:US"
},
"value": "102266000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:StatementGeographicalAxis",
"value": "country:US"
},
"value": "98061000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:StatementGeographicalAxis",
"value": "country:CN"
},
"value": "40308000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:StatementGeographicalAxis",
"value": "country:CN"
},
"value": "43678000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:StatementGeographicalAxis",
"value": "country:CN"
},
"value": "51942000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:StatementGeographicalAxis",
"value": "aapl:OtherCountriesMember"
},
"value": "125010000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:StatementGeographicalAxis",
"value": "aapl:OtherCountriesMember"
},
"value": "114230000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:StatementGeographicalAxis",
"value": "aapl:OtherCountriesMember"
},
"value": "115592000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2020-06-28",
"endDate": "2020-09-26"
},
"value": "64698000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2020-03-29",
"endDate": "2020-06-27"
},
"value": "59685000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-12-29",
"endDate": "2020-03-28"
},
"value": "58313000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2019-12-28"
},
"value": "91819000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-06-30",
"endDate": "2019-09-28"
},
"value": "64040000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-03-31",
"endDate": "2019-06-29"
},
"value": "53809000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-12-30",
"endDate": "2019-03-30"
},
"value": "58015000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2018-12-29"
},
"value": "84310000000"
}
],
"CostOfGoodsAndServicesSold": [
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ProductMember"
},
"value": "151286000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ProductMember"
},
"value": "144996000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ProductMember"
},
"value": "148164000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ServiceMember"
},
"value": "18273000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ServiceMember"
},
"value": "16786000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"segment": {
"dimension": "srt:ProductOrServiceAxis",
"value": "us-gaap:ServiceMember"
},
"value": "15592000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"value": "169559000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"value": "161782000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2017-10-01",
"endDate": "2018-09-29"
},
"value": "163756000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2019-09-29",
"endDate": "2020-09-26"
},
"segment": [
{
"dimension": "us-gaap:DerivativeInstrumentRiskAxis",
"value": "us-gaap:ForeignExchangeContractMember"
},
{
"dimension": "us-gaap:ReclassificationOutOfAccumulatedOtherComprehensiveIncomeAxis",
"value": "us-gaap:ReclassificationOutOfAccumulatedOtherComprehensiveIncomeMember"
},
{
"dimension": "us-gaap:StatementEquityComponentsAxis",
"value": "us-gaap:AccumulatedGainLossNetCashFlowHedgeParentMember"
}
],
"value": "-584000000"
},
{
"decimals": "-6",
"unitRef": "usd",
"period": {
"startDate": "2018-09-30",
"endDate": "2019-09-28"
},
"segment": [
{
"dimension": "us-gaap:DerivativeInstrumentRiskAxis",
"value": "us-gaap:ForeignExchangeContractMember"
},
{
"dimension": "us-gaap:ReclassificationOutOfAccumulatedOtherComprehensiveIncomeAxis",
"value": "us-gaap:ReclassificationOutOfAccumulatedOtherComprehensiveIncomeMember"
},
{
"dimension": "us-gaap:StatementEquityComponentsAxis",
"value": "us-gaap:AccumulatedGainLossNetCashFlowHedgeParentMember"
}
],
"value": "-482000000"
}
]
}
}