Skip to main content

langchain-fmp-data

CI Release PyPI version Python Versions License: MIT

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:

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 data
  • both: 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

  1. Clone the repository:
git clone https://github.com/MehdiZare/langchain-fmp-data.git
cd langchain-fmp-data
  1. Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. 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:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and ensure tests pass
  4. Commit your changes with a descriptive message
  5. Push to your fork and open a Pull Request

Commit Message Format

Follow conventional commits format:

  • feat: New features
  • fix: Bug fixes
  • docs: Documentation changes
  • test: Test additions or modifications
  • refactor: Code refactoring
  • chore: 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

Changelog

See CHANGELOG.md for a detailed list of changes.


Made with ❤️ by Mehdi Zare

Release files for langchain-fmp-data 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-fmp-data 0.2.0
File Size Uploaded
langchain_fmp_data-0.2.0.tar.gz 255.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-fmp-data 0.2.0
File Interpreter ABI Platform
langchain_fmp_data-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 267.7 kB

Release files / langchain_fmp_data-0.2.0.tar.gz

Download URL langchain_fmp_data-0.2.0.tar.gz
Size 255.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ab8d135b940d0fc7b9657d0ba1dba197cc3513f44045146e2c1576a97b39460c
BLAKE2b-256 checksum
How to use checksums
bf670d0f1140b6ce7604d6c8d73bbc84331155ffb7934a09e4af89cbf05d9ae2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.

Transparency log

Release files / langchain_fmp_data-0.2.0-py3-none-any.whl

Download URL langchain_fmp_data-0.2.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1dfb127f3e889a2b2c6e7ed7c8c37fa0649862e6dbf383f18d037b64e95ba5e
BLAKE2b-256 checksum
How to use checksums
2b73cd3da58209bea6c094eb451d439085b15e478c5a2f3176b3cc066614e53b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page