Python client library for the Financial Modeling Prep API
Project description
FMP Client Library
A Python client library for the Financial Modeling Prep (FMP) API. This library provides both synchronous REST API and asynchronous WebSocket support, all in a modular, easy-to-use package.
The client is built to work with the Stable version of the Financial Modeling Prep (FMP) API. All endpoints are configured to use the stable base URL:
https://financialmodelingprep.com/stable/
The endpoints available in this stable version are defined in the fmp_endpoints.json file
Features
-
Unified API Client:
Dynamically access FMP endpoints using Pythonic method names. -
Rate-Limited HTTP Session:
Built-in rate limiting using theratelimitlibrary and robust error handling with logging. -
Dynamic Endpoint Methods:
Automatically attaches methods based on your configuration file (fmp_endpoints.json). -
Asynchronous WebSocket Clients:
Separate clients for stocks, crypto, and forex data available in thefmp_websocketssubpackage. -
Flexible Configuration and Logging:
Easily configure your endpoints with a JSON file and log messages to a file in the same directory as your main script.
Installation
Clone the repository and install the dependencies:
git clone https://github.com/Vimal-Seshadri-Raguraman/FMP.git
cd FMP
pip install -r requirements.txt
python setup.py install
Alternatively, install directly from Github:
pip install git+https://github.com/Vimal-Seshadri-Raguraman/FMP.git
Usage
API Client
Initialize the client with your API Key and call any endpoint dynmically:
from fmp import FMP
# Initialize client with your API Key
client = fmp(api_key = "YOUR_API_KEY")
# Call an endpoint (e.g., "Profile")
response = client.profile(symbol = "AAPL")
print("Status Code:", response.status_code)
print("Profile Data:", response.json())
Dynmic Methods and Help
The client automatically attaches methods based on the JSON configuration. To see available endpoints and their parameters:
# General help for all endpoints
print(client.help())
# Detailed help for a specific endpoint (e.g., "profile")
print(client.help("profile"))
# Generate a manual page of endpoints
man_doc = client.man_page() # Create a text file
print(man_doc)
WebSocket Clients
The library includes asynchronous WebSocket clients for real-time data.
Stock WebSocket Example
import asyncio
from fmp import StockWebsockets
async def run_stock_ws():
stock_ws = StockWebsockets(tickers=["AAPL", "MSFT"], api_key="YOUR_API_KEY")
async for message in stock_ws.run():
print("Stock WebSocket Message:", message)
asyncio.run(run_stock_ws())
Crypto and Forex WebSocket Example
import asyncio
from fmp import CryptoWebsockets, ForexWebsockets
async def run_crypto_ws():
crypto_ws = CryptoWebsockets(tickers=["BTCUSD", "ETHUSD"], api_key="YOUR_API_KEY")
async for message in crypto_ws.run():
print("Crypto WebSocket Message:", message)
async def run_forex_ws():
forex_ws = ForexWebsockets(pairs=["EURUSD", "GBPUSD"], api_key="YOUR_API_KEY")
async for message in forex_ws.run():
print("Forex WebSocket Message:", message)
# Run one example at a time:
asyncio.run(run_crypto_ws())
# asyncio.run(run_forex_ws())
Configuration
By default, the client loads endpoint configuration from fmp_endpoints.json located in the same directory as fmp_client.py. To use a custom configuration file:
client = FMP(api_key="YOUR_API_KEY", config_file="path/to/your_config.json")
If you update the configuration file during runtime, force a reload with:
client.config_manager.reload()
Logging
Logging is enabled by default and creates a log file (fmp.log) in the directory where your main script is located. To disable logging:
client = FMP(api_key="YOUR_API_KEY", log_enabled=False)
Contributing
Contributions, bug reports, and feature requests are welcome. Please open an issue or submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE.md file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fmp_stable_api-0.0.1.tar.gz.
File metadata
- Download URL: fmp_stable_api-0.0.1.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
261c1efc81a128208d8f1eb23a47ed0357c42956a654f352e118f3cd30a29331
|
|
| MD5 |
909cb875a38f228e2514f5ed97eab2b9
|
|
| BLAKE2b-256 |
cf2ea298b849dcb54aaf31016d23ba986dca4e0b60fb065b0812669a1ec52f3f
|
File details
Details for the file fmp_stable_api-0.0.1-py3-none-any.whl.
File metadata
- Download URL: fmp_stable_api-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7c0bc21081051ba3fc2414419825ee42da59a55d630f8e823c08f6a25d7fed9
|
|
| MD5 |
661709a644b2d66b4dc0d543b5d0842a
|
|
| BLAKE2b-256 |
3e46bae12f6be5bd744104881ec288319bcfd38df9fd5a55fcdd048f822a90cd
|