Skip to main content

An integration package connecting FmpData and LangChain

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_fmp_data-0.2.0.tar.gz (255.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_fmp_data-0.2.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

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

Hashes for langchain_fmp_data-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ab8d135b940d0fc7b9657d0ba1dba197cc3513f44045146e2c1576a97b39460c
MD5 279e61fde469cde490a872f516b29412
BLAKE2b-256 bf670d0f1140b6ce7604d6c8d73bbc84331155ffb7934a09e4af89cbf05d9ae2

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_fmp_data-0.2.0.tar.gz:

Publisher: release.yml on MehdiZare/langchain-fmp-data

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_fmp_data-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_fmp_data-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1dfb127f3e889a2b2c6e7ed7c8c37fa0649862e6dbf383f18d037b64e95ba5e
MD5 2ccc664566f86ac447b31fe7425d0d71
BLAKE2b-256 2b73cd3da58209bea6c094eb451d439085b15e478c5a2f3176b3cc066614e53b

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page