Skip to main content

FastballAPI for Python

Python client for the FastballAPI MLB data API. It has no required dependencies (standard library only) and works on Python 3.9 and newer. Pandas is optional.

Install

pip install fastballapi
pip install "fastballapi[pandas]"   # only if you want DataFrames

Set your key

Get a free key at https://fastballapi.com/signup. Free accounts get 500 credits a month.

export FASTBALLAPI_API_KEY=your_key_here
from fastballapi import Client

client = Client()                      # reads FASTBALLAPI_API_KEY
client = Client(api_key="your_key")    # or pass it in

Examples

1. Player props for one game

get_player_props returns lines by sportsbook. Here are home run props for one game.

from fastballapi import Client, to_dataframe

client = Client()

props = client.get_player_props(
    game_id="401815991",
    market="batter_home_runs",
)
df = to_dataframe(props, key="props")
print(df[["player_name", "bookmaker", "line", "over_odds", "under_odds"]].head(10))

2. A pitcher's pitch mix

Find the player id with search_players, then ask for usage, velocity and whiff rate by pitch type.

from fastballapi import Client, to_dataframe

client = Client()

ohtani = client.search_players("Ohtani", limit=1)["players"][0]
mix = client.get_pitch_mix(ohtani["player_id"])
print(to_dataframe(mix, key="mix")[["name", "usage", "avg_velocity", "whiff_rate"]])

3. League leaders

get_leaders ranks qualified hitters or pitchers by a stat.

from fastballapi import Client

client = Client()

leaders = client.get_leaders("ops", limit=5)
for row in leaders["leaders"]:
    print(row["name"], row["team"], row["ops"])

Credits

Every method returns the data object from the response. After each call, client.last_credits_used and client.last_credits_remaining hold the counters from the X-Credits-Used and X-Credits-Remaining headers. Methods that take estimate_only=True return the price of a call without running or charging it.

Pandas

from fastballapi import to_dataframe

df = to_dataframe(data)                # finds the main list in the response
df = to_dataframe(data, key="rows")    # or name the list yourself

Nested fields become dotted columns. Install pandas separately or with pip install "fastballapi[pandas]".

Errors

Every error is an APIError subclass, with the server's message and the HTTP status.

Exception Status Meaning
AuthError 401 Missing, invalid or revoked key
InsufficientCreditsError 402 Not enough credits for the call
NotFoundError 404 The id or name does not exist
RateLimitError 429 Too many requests; has .retry_after when the server sends it
APIError 400, 5xx Bad arguments or a server problem
APIConnectionError none No response (network or timeout)
from fastballapi import Client, APIError, InsufficientCreditsError, RateLimitError

client = Client()
try:
    data = client.list_teams()
except InsufficientCreditsError:
    print("Out of credits, top up at https://fastballapi.com")
except RateLimitError as exc:
    print("Slow down, retry after", exc.retry_after)
except APIError as exc:
    print(exc.status_code, exc.message)

The client retries 429 and 5xx responses and connection failures up to 3 times with backoff, and honors Retry-After. Set Client(max_retries=0) to turn that off.

If you see CERTIFICATE_VERIFY_FAILED on a python.org install for macOS, run the "Install Certificates.command" script that came with Python, or pip install certifi (the client uses it when present).

Options

Client(
    api_key=None,                          # defaults to $FASTBALLAPI_API_KEY
    base_url="https://mcp.fastballapi.com",           # point at another host
    timeout=60.0,                          # seconds per request
    max_retries=3,
)

client.call("tool_name", {"arg": "value"}) calls any tool by name, which helps when the API adds a tool before this package does.

Tools

Method names match the API tool names. Arguments are keyword arguments; required ones can also be passed positionally. Each method's docstring lists its arguments (help(client.list_teams)).

Method Credits What it does
list_teams 1 List teams
get_games 2 Games
get_schedule 2 Schedule
get_game 5 Game
get_standings 2 Standings
get_injuries 2 Injuries
search_players 1 Search players
get_player 5 Player
get_player_games 5 Player games
get_leaders 5 Leaders
get_team_stats 5 Team stats
get_plate_appearances 10 Plate appearances
get_pitches 10 Pitches
get_pitch_mix 5 Pitch mix
get_spray_chart 10 Spray chart
get_odds 5 Odds
get_line_movement 10 Line movement
get_ratings 2 Ratings
get_player_props 10 Player props
get_prop_history 10 Prop history

Full API reference: https://fastballapi.com/docs

License

MIT

Metadata

Release files for fastballapi 0.1.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 fastballapi 0.1.0
File Size Uploaded
fastballapi-0.1.0.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastballapi 0.1.0
File Interpreter ABI Platform
fastballapi-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.7 kB

Release files / fastballapi-0.1.0.tar.gz

Download URL fastballapi-0.1.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1da42fd6e1784bbaad1cf6ba51fdc4a2ef5b133be2f009ece5605c56678a59e3
BLAKE2b-256 checksum
How to use checksums
b7f8b718ebbbe70dbd0371bd79716e6b2dfba86aa5a694fd15ce4d1bde91ed68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 15, 2026.

Transparency log

Release files / fastballapi-0.1.0-py3-none-any.whl

Download URL fastballapi-0.1.0-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20c7f51c8fc5403350183a045a7463f9a627d394b490ca8c846a18a006e79e3e
BLAKE2b-256 checksum
How to use checksums
417ddfdc0c609fa48dabb516737a310c5a74649ebff371381656a6f0b9c7d8f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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