An integration package connecting FmpData and LangChain
Project description
langchain-fmp-data
A LangChain integration for Financial Modeling Prep (FMP) API, providing easy access to financial data through LangChain tools and agents.
Features
- FMPDataToolkit: Query-based toolkit for retrieving specific financial data tools
- FMPDataTool: AI-powered agent for natural language financial data queries
- Comprehensive Financial Data: Access to stock prices, financial statements, economic indicators, and more
- LangGraph Integration: Built on LangGraph for reliable agent workflows
- Vector Search: Intelligent tool selection using embeddings and similarity search
Installation
pip install -U langchain-fmp-data
Quick Start
Prerequisites
You'll need API keys for:
- Financial Modeling Prep (FMP) - Get your API key
- OpenAI - Get your API key
Set them as environment variables:
export FMP_API_KEY="your-fmp-api-key"
export OPENAI_API_KEY="your-openai-api-key"
Using FMPDataToolkit
The toolkit allows you to retrieve specific financial data tools based on your query:
import os
from langchain_fmp_data import FMPDataToolkit
os.environ["FMP_API_KEY"] = "your-fmp-api-key"
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
# Get tools for specific financial data needs
query = "Stock market prices, fundamental and technical data"
fmp_toolkit = FMPDataToolkit(query=query, num_results=10)
tools = fmp_toolkit.get_tools()
for tool in tools:
print(f"- {tool.name}: {tool.description}")
Using FMPDataTool
The FMPDataTool provides an AI agent that can answer complex financial questions:
import os
from langchain_fmp_data import FMPDataTool
os.environ["FMP_API_KEY"] = "your-fmp-api-key"
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
# Initialize the tool
tool = FMPDataTool()
# Ask financial questions in natural language
response = tool.invoke({"query": "What is the latest price of Bitcoin?"})
print(response)
# Get structured data
response = tool.invoke({
"query": "Show me Apple's revenue for the last 4 quarters",
"response_format": "data_structure"
})
print(response)
Response Formats
The FMPDataTool supports three response formats:
natural_language: Human-readable text response (default)data_structure: Structured JSON databoth: Both natural language and structured data
from langchain_fmp_data import FMPDataTool, ResponseFormat
tool = FMPDataTool()
# Natural language response
response = tool.invoke({
"query": "What is Tesla's P/E ratio?",
"response_format": ResponseFormat.NATURAL_LANGUAGE
})
# Structured data response
response = tool.invoke({
"query": "Get AAPL stock data",
"response_format": ResponseFormat.DATA_STRUCTURE
})
# Both formats
response = tool.invoke({
"query": "Show me Microsoft's financial metrics",
"response_format": ResponseFormat.BOTH
})
Development
Setup
- Clone the repository:
git clone https://github.com/MehdiZare/langchain-fmp-data.git
cd langchain-fmp-data
- Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh
- Install dependencies:
uv sync --extra dev --extra test
Running Tests
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=src/langchain_fmp_data --cov-report=term-missing
# Run specific test file
uv run pytest tests/unit_tests/test_tools.py
Code Quality
This project uses several tools to maintain code quality:
- Ruff: Fast Python linter and formatter
- Mypy: Static type checking
# Linting
uv run ruff check src/langchain_fmp_data/
# Formatting
uv run ruff format src/langchain_fmp_data/
# Type checking
uv run mypy src/langchain_fmp_data/
CI/CD
GitHub Actions Workflows
-
CI: Runs on all PRs
- Linting with Ruff
- Type checking with Mypy
- Security scanning with Bandit
- Tests on Python 3.10, 3.11, 3.12, 3.13, 3.14
- Code coverage reporting to Codecov
-
Release: Automated version management and publishing
- Tag-based versioning from PR labels
- Publishing to PyPI with trusted publishing
- GitHub release creation with notes
-
Dev Release: Development releases to TestPyPI
- Automatic dev version calculation
- Published on every push to dev branch
PR Labels for Versioning
release:major: Bumps major version (1.0.0 → 2.0.0)release:minor: Bumps minor version (1.0.0 → 1.1.0)release:patch: Bumps patch version (1.0.0 → 1.0.1)
Contributing
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes and ensure tests pass
- Commit your changes with a descriptive message
- Push to your fork and open a Pull Request
Commit Message Format
Follow conventional commits format:
feat:New featuresfix:Bug fixesdocs:Documentation changestest:Test additions or modificationsrefactor:Code refactoringchore:Maintenance tasks
Project Structure
langchain-fmp-data/
├── src/
│ └── langchain_fmp_data/ # Main package code
│ ├── __init__.py # Package exports
│ ├── agent.py # LangGraph agent implementation
│ ├── tools.py # FMPDataTool implementation
│ └── toolkits.py # FMPDataToolkit implementation
├── tests/ # Test suite
│ ├── unit_tests/ # Unit tests
│ └── integration_tests/ # Integration tests
├── .github/ # GitHub Actions workflows
├── pyproject.toml # Project configuration
├── README.md # This file
└── CLAUDE.md # AI assistant documentation
Dependencies
- Python: 3.10 - 3.14
- LangChain: ^1.0.0
- LangChain Core: ^1.0.0
- LangChain OpenAI: ^1.0.0
- LangGraph: ^1.0.0
- FMP-Data: ^2.1.5 with LangChain extras
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
Acknowledgments
- Financial Modeling Prep for providing comprehensive financial data APIs
- LangChain for the excellent framework
- OpenAI for embedding and language models
Changelog
See CHANGELOG.md for a detailed list of changes.
Made with ❤️ by Mehdi Zare
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 langchain_fmp_data-0.2.0.tar.gz.
File metadata
- Download URL: langchain_fmp_data-0.2.0.tar.gz
- Upload date:
- Size: 255.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab8d135b940d0fc7b9657d0ba1dba197cc3513f44045146e2c1576a97b39460c
|
|
| MD5 |
279e61fde469cde490a872f516b29412
|
|
| BLAKE2b-256 |
bf670d0f1140b6ce7604d6c8d73bbc84331155ffb7934a09e4af89cbf05d9ae2
|
Provenance
The following attestation bundles were made for langchain_fmp_data-0.2.0.tar.gz:
Publisher:
release.yml on MehdiZare/langchain-fmp-data
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_fmp_data-0.2.0.tar.gz -
Subject digest:
ab8d135b940d0fc7b9657d0ba1dba197cc3513f44045146e2c1576a97b39460c - Sigstore transparency entry: 897583583
- Sigstore integration time:
-
Permalink:
MehdiZare/langchain-fmp-data@2b4b2f3c32119cbefbf3104c216cedcc53847dab -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MehdiZare
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2b4b2f3c32119cbefbf3104c216cedcc53847dab -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file langchain_fmp_data-0.2.0-py3-none-any.whl.
File metadata
- Download URL: langchain_fmp_data-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1dfb127f3e889a2b2c6e7ed7c8c37fa0649862e6dbf383f18d037b64e95ba5e
|
|
| MD5 |
2ccc664566f86ac447b31fe7425d0d71
|
|
| BLAKE2b-256 |
2b73cd3da58209bea6c094eb451d439085b15e478c5a2f3176b3cc066614e53b
|
Provenance
The following attestation bundles were made for langchain_fmp_data-0.2.0-py3-none-any.whl:
Publisher:
release.yml on MehdiZare/langchain-fmp-data
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_fmp_data-0.2.0-py3-none-any.whl -
Subject digest:
a1dfb127f3e889a2b2c6e7ed7c8c37fa0649862e6dbf383f18d037b64e95ba5e - Sigstore transparency entry: 897583617
- Sigstore integration time:
-
Permalink:
MehdiZare/langchain-fmp-data@2b4b2f3c32119cbefbf3104c216cedcc53847dab -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MehdiZare
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2b4b2f3c32119cbefbf3104c216cedcc53847dab -
Trigger Event:
pull_request
-
Statement type: