Sandbox
@JerBouma/FinanceToolkit

Python financial analysis toolkit and MCP server

FinanceToolkit is a Python library for pulling and calculating financial data across statements, ratios, risk, performance, valuation, and more. It is built around the `Toolkit` class and related modules in `financetoolkit/`, with notebooks in `examples/` showing how the pieces fit together. The repo also ships an MCP server so Claude Code, Copilot, Cursor, Windsurf, and other MCP-compatible clients can query the toolkit directly. That makes it easier to compare methods, reuse calculations, and work from the same source of truth across sessions.

5,317 stars616 forksPythonUpdated 6d ago
Who it's for

Builders who want a reusable Python toolkit for financial analysis or an MCP server for agent access.

What it delivers

You can pull consistent financial metrics and statement data into your own analysis or agent workflow without rebuilding the calculations yourself.

What it does

Financial statements

Gets income statement, balance sheet, cash flow, and statistics data on annual or quarterly bases.

Ratios and custom ratios

Collects profitability, liquidity, efficiency, solvency, and valuation ratios, and lets you define custom ratios.

Market and historical data

Fetches daily to yearly OHLC, volume, dividends, returns, and cumulative returns.

Risk and performance metrics

Calculates measures like volatility, Sharpe ratio, excess return, excess volatility, and value at risk.

Discovery and screening

Finds companies, sectors, industries, news, and screeners for stocks and other instruments.

MCP server access

Exposes 500+ methods through an MCP server for supported clients and local setups.

How to get it

  1. 1To install the Finance Toolkit it simply requires the following
    pip install financetoolkit -U
  2. 2Run the setup wizard — it locates your client's config file and writes the MCP entry…
    uvx --from "financetoolkit[mcp]" financetoolkit-mcp-setup

README

FinanceToolkit

GitHub Sponsors Buy Me a Coffee LinkedIn MCP Server Download MCP Bundle Smithery Glama Documentation Supported Python Versions PYPI Version PYPI Downloads

While browsing a variety of websites, I repeatedly observed significant fluctuations in the same financial metric among different sources. Similarly, the reported financial statements often didn't line up, and there was limited information on the methodology used to calculate each metric.

For example, Microsoft's Price-to-Earnings (PE) ratio on the 6th of May, 2023 is reported to be 28.93 (Stockopedia), 32.05 (Morningstar), 32.66 (Macrotrends), 33.09 (Finance Charts), 33.66 (Y Charts), 33.67 (Wall Street Journal), 33.80 (Yahoo Finance) and 34.4 (Companies Market Cap). All of these calculations are correct, however the method of calculation varies leading to different results. Therefore, collecting data from multiple sources can lead to wrong interpretation of the results given that one source could apply a different definition than another. And that is, if that definition is even available as often the underlying methods are hidden behind a paid subscription.

This is why I designed the FinanceToolkit, this is an open-source toolkit in which all relevant financial methods (500+) are written down in the most simplistic way allowing for complete transparency of the method of calculation (proof). This enables you to avoid dependence on metrics from other providers that do not provide their methods. With a large selection of financial statements in hand, it facilitates streamlined calculations, promoting the adoption of a consistent and universally understood methods and formulas.

Beyond Equities, it supports Options, Currencies, Cryptocurrencies, ETFs, Mutual Funds, Indices, Money Markets, Commodities, Key Economic Indicators and more, allowing you to obtain historical data as well as important performance and risk measurements such as the Sharpe Ratio and Value at Risk.

Complementing this is the Finance Database 🌎, a database featuring 300.000+ symbols containing Equities, ETFs, Funds, Indices, Currencies, Cryptocurrencies and Money Markets. By utilising both, it is possible to do a fully-fledged competitive analysis with the tickers found from the FinanceDatabase inputted into the FinanceToolkit.


🔌 The Finance Toolkit is also available as an MCP Server

Query 500+ methods from Claude, Copilot, Cursor, Windsurf or any MCP-compatible client without writing code.

  • Hosted: connect to https://financetoolkit.jeroenbouma.com/mcp — OAuth handles the rest on first use.
  • Local: uvx --from "financetoolkit[mcp]" financetoolkit-mcp-setup — sets up your client config and API key automatically. See MCP Server Documentation for manual setup.

Also on Smithery, Glama, MCP Servers and more.


Table of Contents

  1. Installation
  2. Functionality
  3. MCP Server
  4. Questions & Answers
  5. Contributing
  6. Mentions
  7. Contact

Installation

Before installation, consider starring the project on GitHub which helps others find the project as well.

image

To install the Finance Toolkit it simply requires the following:

pip install financetoolkit -U

Then within Python use:

from financetoolkit import Toolkit

companies = Toolkit(
    tickers=['AAPL', 'MSFT'],
    api_key="FINANCIAL_MODELING_PREP_KEY",  # replace with your actual API key
)

To be able to get started, you need to obtain an API Key from FinancialModelingPrep. This is used to gain access to 30+ years of financial statement both annually and quarterly. Note that the Free plan is limited to 250 requests each day, 5 years of data and only features companies listed on US exchanges.


Obtain an API Key from FinancialModelingPrep here.


Through the link you are able to subscribe for the free plan and also premium plans at a 15% discount. This is an affiliate link and thus supports the project at the same time. I have chosen FinancialModelingPrep as a source as I find it to be the most transparent, reliable and at an affordable price. I have yet to find a platform offering such low prices for the amount of data offered. When you notice that the data is inaccurate or have any other issue related to the data, note that I simply provide the means to access this data and I am not responsible for the accuracy of the data itself. For this, use their contact form or provide the data yourself.

By default, the Finance Toolkit prioritizes Financial Modeling Prep for data retrieval. If data acquisition from Financial Modeling Prep is unsuccessful (e.g., due to plan restrictions or API key issues), the toolkit automatically switches to Yahoo Finance as a secondary source. To disable this fallback behavior and exclusively use Financial Modeling Prep, set enforce_source="FinancialModelingPrep" during Toolkit initialization. This configuration ensures that an error is raised if Financial Modeling Prep data cannot be accessed. Alternatively, you can set enforce_source="YahooFinance" to exclusively use Yahoo Finance as the data source.

The same enforce_source argument is also accepted per call on get_historical_data, get_treasury_data and the four statement functions (get_balance_sheet_statement, get_income_statement, get_cash_flow_statement and get_statistics_statement), where it overrides whatever the Toolkit was initialised with.

Functionality

This section is an introduction to the Finance Toolkit. Find with the link below fully-fledged code documentation as well as Jupyter Notebooks in which you can see many examples ranging from basic examples to creating custom ratios to working with your own datasets.


Find a variety of How-To Guides including Code Documentation for the FinanceToolkit here.


A basic example of how to use the Finance Toolkit is shown below. Every code snippet in the sections that follow builds on this same companies instance.

from financetoolkit import Toolkit

# Initialize the Toolkit for Apple and Microsoft
companies = Toolkit(["AAPL", "MSFT"], api_key=API_KEY, start_date="2017-12-31")

Each ratio, indicator and metric has a corresponding function that can be called directly, for example ratios.get_return_on_equity or technicals.get_relative_strength_index. Every module also has one or more collect_ functions that return a whole category at once, e.g. ratios.collect_profitability_ratios, useful when you want everything in one call instead of assembling it metric by metric.

Three capabilities cut across nearly the whole toolkit:

  • rolling and trailing windows. Many metrics return one value per reporting period by default. Pass rolling=<n> to compute the metric over a sliding window instead, or trailing=<n> for a trailing sum/average (e.g. a trailing 4-quarter sum to annualize a quarterly flow) — turning a snapshot into a proper time series.
  • growth and lag. Pass growth=True on almost any get_ or collect_ function to return the period-over-period growth instead of the raw value. lag (an int or list of ints, default 1) controls how many periods back that growth is measured against, e.g. lag=4 for year-over-year growth on quarterly data. Combine with trailing (e.g. trailing=4, growth=True) to get TTM growth.
  • standardize (Z-Score). Most get_* methods across Economics, Ratios, Technicals, Risk, Performance, Models, Options and Fixed Income accept standardize=True, converting raw values into standard deviations from their own historical mean/std. Useful for ranking, scoring, or spotting an unusual reading across metrics that otherwise live on incompatible scales.

Every module below also has a How-To Guide notebook and full code documentation (formulas, parameters, worked examples) linked in its own section, see the documentation hub for the complete index.

Discovering Instruments & News

Before analyzing a ticker you often need to find it. The Discovery module is standalone and covers among other things lists of companies, cryptocurrencies, forex, commodities, ETFs and indices.

from financetoolkit import Discovery

# Initialize the standalone Discovery module
discovery = Discovery(api_key="FINANCIAL_MODELING_PREP_KEY")

# Screen for stocks matching a set of criteria
discovery.get_stock_screener(
    market_cap_higher=1000000,
    price_higher=100,
    price_lower=200,
    beta_higher=1,
    beta_lower=1.5,
    dividend_higher=1,
)

Which returns:

SymbolNameMarket CapSectorIndustryBetaPriceDividendExchangeCountry
NKENIKE, Inc.163403295604Consumer CyclicalFootwear & Accessories1.079107.361.48New York Stock ExchangeUS
SAF.PASafran SA66234006559IndustrialsAerospace & Defense1.339160.161.35ParisFR
ROSTRoss Stores, Inc.46724188589Consumer CyclicalApparel Retail1.026138.7851.34NASDAQ Global SelectUS

Furthermore, you can find in this module stock screeners, sector/industry performance and news feeds and more. Find the Notebook here and the full instrument discovery documentation here.

Obtaining Historical Data

Obtain historical data on a daily, weekly, monthly or yearly basis. This includes OHLC, volumes, dividends, returns and cumulative returns for each corresponding period.

# Obtain historical market data for all tickers
historical_data = companies.get_historical_data()

# Select the results for Apple
historical_data.xs('AAPL', axis=1, level=1)

For example, a portion of the historical data for Apple is shown below.

dateOpenHighLowCloseAdj CloseVolumeDividendsReturnCumulative Return
2018-01-0242.5443.07542.31543.06540.781.02224e+08001
2018-01-0343.132543.637542.9943.057540.771.17982e+080-0.00020.9998
2018-01-0443.13543.367543.0243.257540.968.97384e+0700.00471.0044
2018-01-0543.3643.842543.262543.7541.439.46401e+0700.01151.0159
2018-01-0843.587543.902543.482543.587541.278.22711e+070-0.00391.012

And below the cumulative returns are plotted which include the S&P 500 as benchmark:

HistoricalData

Metrics such as Volatility, Excess Return and Excess Volatility are calculated as dedicated Risk and Performance methods rather than columns on this table to create more efficient and flexible functionalities. Find the Notebook here and the full historical data documentation here.

Obtaining Financial Statements

Obtain an Income Statement on an annual or quarterly basis. This can also be a balance statement or cash flow statement.

# Obtain the Income Statement for all tickers
income_statement = companies.get_income_statement()

# Select the results for Apple
income_statement.loc['AAPL']

For example, the first 5 rows of the Income Statement for Apple are shown below.

2017201820192020202120222023
Revenue2.29234e+112.65595e+112.60174e+112.74515e+113.65817e+113.94328e+113.83285e+11
Cost of Goods Sold1.41048e+111.63756e+111.61782e+111.69559e+112.12981e+112.23546e+112.14137e+11
Gross Profit8.8186e+101.01839e+119.8392e+101.04956e+111.52836e+111.70782e+111.69148e+11
Gross Profit Ratio0.38470.38340.37820.38230.41780.43310.4413
Research and Development Expenses1.1581e+101.4236e+101.6217e+101.8752e+102.1914e+102.6251e+102.9915e+10

And below the Earnings Before Interest, Taxes, Depreciation and Amortization (EBITDA) are plotted for both Apple and Microsoft. Find the Notebook here and the full financial statement documentation here.

FinancialStatements

Obtaining Financial Ratios

Get Profitability Ratios based on the inputted balance sheet, income and cash flow statements. This can be any of the 80+ ratios within the ratios module.

# Collect all Profitability Ratios for all tickers
profitability_ratios = companies.ratios.collect_profitability_ratios()

# Select the results for Microsoft
profitability_ratios.loc['MSFT']

For example, see some of the profitability ratios of Microsoft below.

2017201820192020202120222023
Gross Margin0.61910.65250.6590.67780.68930.6840.6892
Operating Margin0.24820.31770.34140.37030.41590.42060.4177
Net Profit Margin0.23570.15020.31180.30960.36450.36690.3415
Interest Coverage Ratio13.998216.582120.342925.378234.783547.427552.0244
Income Before Tax Profit Margin0.25740.33050.34720.37080.4230.42220.4214

And below a few of the profitability ratios are plotted for Microsoft.

FinancialRatios

The 80+ ratios are divided into five categories: Efficiency (asset/inventory/receivables turnover, cash conversion cycle, R&D/SG&A/SBC-to-revenue), Liquidity (current, quick and cash ratios, working capital), Profitability (margins, ROE/ROA/ROIC, cash vs. effective tax rate), Solvency (debt-to-equity, debt-to-capital, interest and dividend coverage) and Valuation (P/E, PEG, Forward P/E, EV multiples, buyback and shareholder yield). It's also possible to define fully custom ratios calculated automatically from the balance sheet, income and cash flow statements. Find the Notebook here and the full ratio-by-ratio documentation here.

Obtaining Financial Models

Get an Extended DuPont Analysis based on the inputted balance sheet, income and cash flow statements.

# Get the Extended DuPont Analysis for all tickers
extended_dupont_analysis = companies.models.get_extended_dupont_analysis()

# Select the results for Apple
extended_dupont_analysis.loc['AAPL']

For example, this shows the Extended DuPont Analysis for Apple:

|

Files in the repo

Repository payload16 top-level entries
  • .github
  • examples
  • financetoolkit
  • tests
  • .gitignore
  • .pre-commit-config.yaml
  • CONTRIBUTING.md
  • docker-compose.yml
  • Dockerfile
  • glama.json
  • LICENSE.txt
  • medium.pdf
  • pyproject.toml
  • README.md
  • server.json
  • uv.lock

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More frameworks & sdks

kyegomez/
OpenMythos
kyegomez/OpenMythosFrameworks & SDKs

A theoretical reconstruction of the Claude Mythos architecture, built from first principles using the available research literature.

15k
D4Vinci/ScraplingFrameworks & SDKs

🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl!

80k
alibaba/zvecFrameworks & SDKs

A lightweight, lightning-fast, in-process vector database

16k
EverMind-AI/EverOSFrameworks & SDKs

One portable memory layer for every AI agent: local-first, Markdown-native, user-owned, and self-evolving across apps, tools, and workflows.

13k
FlowElement-xinliuyuansu/
m_flow

A bio-inspired cognitive memory engine — a new paradigm for Graph RAG.

4.5k