FMP

FMP

Enter

How to pull financial statements using the FMP API

-

twitterlinkedinfacebook
blog post cover photo

Image credit: Tech Daily

Financial statements are fundamental to most financial analysis and especially when it comes to investment decisions. Most analysts are used to using Excel to perform their analysis but many are learning about the power of using a coding language like Python. So, if you're somewhat new to coding and you want to learn how to pull financial statements from FMP Financial Statement API, you are in the right place. Here's a step-by-step guide to learn how to pull financial statements from the FMP API.

Step 1: Load FMP Developer API Docs Website

From this article go to the top right of the page, click “Developers” and then click "API Docs" from the list below. Make sure you are logged into your account. You should see this in the top right corner:

image

Otherwise, click login and enter your account credentials.

A key piece of information that'll want to write down in a safely secured location is your API Key. This is located in the second section of the API docs page which is called "Your Details". See in the example below, it should be a long series of letters and numbers. As with any key, this unlocks something and in this case it ensures that you have permission to access the API you are requesting. Make sure to keep your key private and safely secured if you are storing it somewhere on your computer. It is against our terms and conditions to share your API key with anyone - your account will be blocked and investigated if we suspect you are doing this.

Step 2: Copy the API URL from the Financial Statement you wish to Retrieve

image

After the documentation URL is loaded you'll need to scroll down to the section called Company Financial Statements. Alternatively, you can use the navigation sidebar on the left and click Company Financial Statements om the menu on the left. Here you need to decide a few things:

  • Which financial statement do you want to pull?

Your options are Income Statement, Balance Sheet, or Cash Flow Statement

  • Which time period of statement do you want to pull?

Your options are Annual or Quarterly statements.

  • Which company do you want to pull?

You can choose almost any publicly listed company in the world! You'll need to find out what their stock ticker is and replace the default APPL (Apple Inc) ticker that is the standard. You can find stock tickers by simply googling Company Name + Stock Ticker.

Once you decide which type and period you want to pull, copy the relevant URL.

For this tutorial, we're going to be pulling Apple Inc's annual Income Statements.

Step 3: Open Your Python Environment and copy URL

Now you'll need to open up your Python environment to start writing code. To start with, create a variable called “URL” and give the string version of the URL you copied in step 2. You can simply use Ctrl + V (or cmd + V for mac users) to paste the url you copied.

ERROR ALERT: Make sure to add inverted commas (otherwise called quotation marks) around the copied URL to make the URL variable a string.

url = “https://financialmodelingprep.com/api/v3/income-statement/AAPL?limit=120&apikey=demo”

If you're copying directly from this page you'll need to make sure that you replace the ‘demo' with your API key

Step 4: Write the Python code to access the Financial Statement

To learn more about exactly what all the following code means and why it works, visit out guide - How to call a Financial Modeling Prep API

try: # For Python 3.0 and later from urllib.request import urlopen except ImportError: # Fall back to Python 2's urllib2 from urllib2 import urlopen import json def get_jsonparsed_data(url): """ Receive the content of ``url``, parse it as JSON and return the object. Parameters ---------- url : str Returns ------- dict """ response = urlopen(url) data = response.read().decode("utf-8") return json.loads(data) url = ("https://financialmodelingprep.com/api/v3/income-statement/AAPL?limit=120&apikey=demo") IncomeStatement_APPL = get_jsonparsed_data(url)

Step 5: Look inside the data you just received!

If you're working in a JupyterLab environment you'll be able to see the JSON data you received by simply typing in the name of the variable you've stored the information under and hitting enter. As you can see on the last line of code above, we've named our variable IncomeStatement_APPL. If you're working in a regular python environment and want to print the data then use the following:

print(IncomeStatement_APPL)

You may have noticed that in the URL you copied over the limit = 120, this means that the API will deliver the last 120 statements. That's why when you hit enter above, you'll get a lot of statements. You may not want this many. If that's the case, simply enter the number of historical statements you wish to receive.

Step 6: Get a specific data point from the larger JSON data provided

Often it's good to take a look at the one of the statements delivered to be able to see the way everything has been stored. Assuming you're using JupyterLab, enter the following code to look at the most recent statement:

IncomeStatement_APPL[0]

You should see something like this:

image

Now I'm going to show you how to pull one data point from this set. You'll need to index into the particular statement (note that you index in using a number from 0 to the limit you set minus 1) and then index the element of the statement you want to extract. Here's how you could pull the 2020 operating income:

IncomeStatement_APPL [0] [‘operatingIncome']

ERROR ALERT: To ensure you don't get a DNE error, make sure to directly copy the name of the financial statement element from the sample view of one years entire statement.

Rounding Up

There you have it! Getting access to financial statements using Financial Modeling Prep's financial statements API is that easy! As a bit of a bonus, here's an example of using a for loop to create a table with Apple's most recent 5 net income ratios.

image

From this we can see that 2020, had a significant dip in the net income ratio - perhaps this is caused by the pandemic?

Other Blogs

May 14, 2024 11:41 AM - Sanzhi Kobzhan

The easiest way to calculate stock’s target price and why the target price is important.

A stock's target price, also known as its fair value, is an indication of what a share can cost based on the company’s forecasted financial statements. It is important to know a stock's fair value to find undervalued stocks with great growth potential. Let's consider how investment analysts calculat...

blog post title

May 24, 2024 9:30 AM - Rajnish Katharotiya

How to Access and Analyze Earnings Call Transcripts

Earnings call transcripts are invaluable resources for investors, analysts, and financial enthusiasts. They provide insights into a company's performance, strategy, and future outlook, making them essential for making informed investment decisions. With Financial Modeling Prep, Earnings Call Transcr...

blog post title

May 27, 2024 3:30 PM - Rajnish Katharotiya

The best 5 GPU stocks other than NVDA

In the ever-evolving world of technology, certain sectors have consistently demonstrated exceptional growth and innovation. The graphics processing units (GPUs) industry is one such sector, offering investors a golden opportunity for potentially high returns. In this blog, we'll delve into why inves...

blog post title
FMP

FMP

Financial Modeling Prep API provides real time stock price, company financial statements, major index prices, stock historical data, forex real time rate and cryptocurrencies. Financial Modeling Prep stock price API is in real time, the company reports can be found in quarter or annual format, and goes back 30 years in history.
twitterlinkedinfacebookinstagram
2017-2024 © Financial Modeling Prep