Python module to get stock data from the Financial Modeling Prep API
This library requires you to have an account with Financial Modeling Prep (sign up here)
You can install the package:
- Using pip:
pip install fmp_python
- From the source:
git clone https://github.com/qlikstar/fmp_python.git
pip install -e fmp_python
To get data from the API:
- import the library and call the object with your API key:
from fmp_python.fmp import FMP
fmp = FMP(api_key='YOUR_API_KEY')
fmp.get_quote('AAL')
- Or, you can store it in the environment variable FMP_API_KEY
from fmp_python.fmp import Interval, FMP
fmp = FMP(output_format='pandas')
fmp.get_quote('AAL')
You can choose which output format you want your data output_format = 'pandas' or 'json'.
'pandas' is the default value
Reference: https://financialmodelingprep.com/developer/docs/#Company-Quote
fmp.get_quote(symbol: str)
Usage Example
fmp: DataFrame = FMP(api_key="YOURAPIKEY")
fmp.get_quote('AAL')
OR
fmp = FMP(output_format = 'json')
fmp.get_quote('AAL')
Reference: https://financialmodelingprep.com/developer/docs/#Stock-Price
fmp.get_quote_short(symbol: str)
Usage Example
fmp: DataFrame = FMP(api_key="YOURAPIKEY")
fmp.get_quote('AAL')
Reference: https://financialmodelingprep.com/developer/docs/#Stock-Historical-Price
fmp.get_historical_chart(symbol: str, interval:str)
Usage Example
fmp = FMP(output_format = 'pandas')
fmp.get_historical_chart('AAL', Interval.MIN_5)
fmp.get_index_quote(symbol: str)
Usage Example
fmp = FMP(output_format = 'pandas')
fmp.get_index_quote('GSPC')
Reference: https://financialmodelingprep.com/developer/docs/#Historical-stock-index-prices
- By timelapse:
fmp.get_historical_chart_index("AAPL", Interval.HOUR_4)
fmp.get_historical_chart_index('GSPC', Interval.MIN_1)
fmp.get_historical_price('GSPC')
Reference: https://site.financialmodelingprep.com/developer/docs#technicals
from fmp_python.models.enums import Interval, Indicator
res = fmp.get_technical_indicator("AAPL", Interval.DAY_1, Indicator.RSI, period=14)
df = fmp.get_stock_screener(volume_gt=100000, price_gt=20, price_lt=500, beta_gt=0.3, limit=5000)
-
Add your API key to the
API_KEY
intest_main.py
-
Now run the tests in the folder
test_fmp_python