EYARC

EDGAR Explorer Company Facts

Analytics mindset

EDGAR Explorer

Company Facts API

The SEC’s company facts API is accessed via https://data.sec.gov/api/xbrl/companyfacts/CIK##########.json by replacing the 10 hashes with the entity’s unique 10-digit central index key (CIK). For example, using Tesla’s CIK “0001318605” the company facts file for Tesla can be found at:

The company facts file contains both metadata about the entity (the CIK and Company Name), and a large amount of data included under the header ‘facts’. Nested inside ‘facts’ is the document and entity information (‘dei’) and financial statements prepared under US GAAP (‘us-gaap’). Financial data is provided within the ‘us-gaap’ section and includes:

Required – Alteryx

Required – Python

Appendix

Using Python on Google Colab

Google Colab provides a free cloud-based Python integrated development environment (IDE) allowing users to write, edit and execute Python scripts within a browser. Google Colab can be accessed here: https://colab.research.google.com/. Users are required to set up an account and/or login using Google Account (i.e., Gmail) credentials.

Google Colab provides a Python IDE that is very similar to Jupyter Notebooks, allowing users to add both code and comment (markdown) sections. The top menu of Google Colab includes “File” and selecting “New Notebook” for file allows you to start a new Python script. You can edit the name of the new notebook by clicking on the name of the file (located on the top bar) and can access any files uploaded or created in script by clicking the folder icon on the left (the folder should include a sub-folder “sample_data” even if you have not uploaded or created any files on Gooble Colab.

Google Colab provides a free cloud-based Python interface, however, for this case, any python IDE you have access to can be used to create Python scripts to access the SEC EDGAR APIs. Other popular environments include using Jupyter Notebooks within the Anaconda package for those seeking a non-cloud-based approach with similar editing characteristics.

Useful Python Syntax

This section provides some of the syntax used in the solution to this case. This section is written with some basic understanding of Python syntax:

import json

import requests

import pandas as pd

url = "https://url of the API"

headers = {'User-Agent' : 'University Name  email@XX.edu'}

response = requests.get(url, headers=headers)

data=response.json()

print(type(data))

Should return:

<class 'dict'>

Which suggests that the JSON object is a dictionary. To identify keys in the dictionary, the Python function keys() can be used on the object or on nested dictionaries. For example:

data.keys()

data['filings'].keys()

data['facts']['us-gaap']['units'].keys()

In the first example, you examine the top-level keys, which will include metadata including the CIK of the filing entity. The second two examples will recover the keys associated with nested dictionaries. In the second example, the keys of the nested dictionary 'filings' will be returned and in the third example the keys associated with the nested dictionary 'units' which is nested within the 'us-gaap' dictionary, which is nested within the 'facts' dictionary will be recovered. Those who are automation-inclined could consider writing a for-loop to recover all data types for keys within the dictionary. For example:

for k,v in data.items():

    dt=type(data.items())

    print (k,dt)

In both the submissions and company facts JSON files all the top-level keys are associated with nested dictionaries. Automation concepts will be covered in further detail in the related Innovation Mindset Case called “Innovation Mindset: Automating data extraction from EDGAR using XBRL.”

data1 = data['cik']

data2 = data['filings']['recent']['form']

In the first example, Python will save the CIK of the filing’s entity into an integer variable as data1, and the second example will save a list of forms filed by the entity into the variable data2.

df2 = pd.DataFrame(data2)

df2 = pd.DataFrame(data['filings']['recent']['form'])

Note that the first example follows from the prior example and the second combines the two. In both cases, this example saves the forms filed by the entity into a pandas dataframe. There are many useful pandas functions, including unique(), which returns only the unique values from a list. For example:

udf2 = pd.unique(df2[0])

Another useful function in pandas is counting variables. For example, you can count the frequency of any item in a list using groupby and count. For example:

df.groupby(df[0])[0].count()

where the syntax [0] refers to the first item in the list. Additional guidance on pandas dataframes can be found at: https://pandas.pydata.org/pandas-docs/stable/user_guide/index.html