Skip to main content

pitchapi — Python SDK

Typed Python client for the PitchAPI football-data API. Match results, shots, xG, lineups, momentum, events, player stats, head-to-head, and advanced analytics derived from the event feed.

  • Sync and async clients over one shared core (httpx)
  • Plain dataclass response models — a faithful mirror of the API's JSON, built through a small from_dict converter (no Pydantic, one dependency)
  • Typed exceptions mapped from the API's stable error.code
  • Automatic retries on 429/5xx with Retry-After honoured

Install

pip install pitchapi

Requires Python 3.9+.

Quick start

from pitchapi import PitchAPI

with PitchAPI(api_key="pk_live_...") as client:
    day = client.date.get("2026-08-27")
    for m in day.matches:
        print(m.home_team.name, m.score_home, "-", m.score_away, m.away_team.name)

    match = client.matches.get("m_4DP2fy")
    shots = client.matches.shots(match.id)
    adv = client.matches.advanced(match.id)          # team rollups
    net = client.matches.advanced_network(match.id)  # pass networks

The key can also come from the PITCHAPI_API_KEY environment variable, in which case PitchAPI() needs no arguments.

Async

import asyncio
from pitchapi import AsyncPitchAPI

async def main():
    async with AsyncPitchAPI() as client:
        league = await client.leagues.get("l_0bfbkO")
        matches = await client.leagues.matches(league.id, season="2025/2026")
        print(len(matches.matches), "matches")

asyncio.run(main())

Namespaces

Namespace Methods
client.date get(date, status=None) — date is a str (YYYY-MM-DD) or a datetime.date
client.matches get, shots, shot, events, lineups, momentum, stats, players, player, players_halves, player_halves, player_shots, h2h, advanced, advanced_network, advanced_players, advanced_player, heatmaps(id, frame=None)
client.leagues list, get, matches(id, season=None, status=None)
client.teams get
client.players get

Every method returns a typed dataclass from pitchapi.models.

Per-player match stats is a list of PlayerStatGroup — top_stats, attack, defense, duels — and which groups appear depends on position and involvement. Each group's stats is keyed by display label, but the label is presentation text: branch on the entry's key.

for group in client.matches.players("m_4DP2fy")[0].stats:
    for label, entry in group.stats.items():
        s = entry.stat
        # integer and double carry a value; fractionWithPercentage adds a total
        print(group.key, entry.key, s.type, s.value, s.total)

Upcoming fixtures

Match listings return played matches by default. Pass status to reach scheduled ones — "upcoming" for fixtures that have not kicked off, "all" for both. An upcoming match carries a kickoff time_utc and a status, but its scores are None until it is played.

for m in client.date.get("2026-09-01", status="upcoming").matches:
    print(m.time_utc, m.home_team.name, "vs", m.away_team.name)

# Within a season. The season is resolved first, so asking for upcoming
# fixtures of a finished campaign is an empty list, not next season's.
client.leagues.matches("l_0bfbkO", season="2025/2026", status="all")

Lineups for a fixture may be a pre-match prediction rather than the real XI. confirmed is the flag to branch on; lineup_type carries the source's own label for a prediction and is None once the lineup is confirmed.

lineups = client.matches.lineups("m_4DP2fy")
if lineups.home.confirmed:
    print(lineups.home.formation, [p.name for p in lineups.home.starters])
else:
    print("predicted only:", lineups.home.lineup_type)

Errors

from pitchapi import NotFoundError, PlanUpgradeRequiredError, RateLimitError

try:
    client.matches.advanced("m_unprocessed")
except NotFoundError as e:
    # code is RESOURCE_NOT_FOUND, ANALYTICS_UNAVAILABLE or HALVES_UNAVAILABLE
    print(e.code, e.request_id)
except PlanUpgradeRequiredError:
    ...  # league is Pro-only
except RateLimitError as e:
    print("retry after", e.retry_after, "s")

All exceptions derive from pitchapi.PitchAPIError and carry code, status_code, and request_id where available.

Configuration

PitchAPI(
    api_key="pk_live_...",
    base_url="https://api.pitchapi.dev",  # override for self-hosting/tests
    timeout=30.0,
    max_retries=2,                        # 429/5xx + network errors; 0 disables
)

Development

pip install -e ".[dev]"
pytest              # tests use httpx.MockTransport — no network
mypy                # scoped to src/ by pyproject
ruff check .
ruff format --check .

OpenAPI

A full OpenAPI 3.1 description of the API lives at openapi/openapi.yaml in the repository root. The dataclass models in this SDK mirror its schemas one-to-one.

License

This client library is released under the MIT License.

The licence covers the SDK source only. Access to the PitchAPI service and the football data it returns is governed separately by the PitchAPI terms of service — an MIT-licensed client does not grant any right to the data.

Metadata

Release files for pitchapi 0.1.6

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

Source distribution (sdist)

Source distribution for pitchapi 0.1.6
File Size Uploaded Provenance Actions
pitchapi-0.1.6.tar.gz 26.9 kB Without provenance Details for pitchapi-0.1.6.tar.gz

Built distribution (wheel)

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

Total release size: 56.4 kB

Release files / pitchapi-0.1.6.tar.gz

Download URL pitchapi-0.1.6.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f3d99cd05ab8a4ea6dbd7c581db253c419bb27cfd5d0d892364a6732d5363905
BLAKE2b-256 checksum
How to use checksums
9a560de92ca29b125a58d605900e7e66f788469bec0f0e20b3eae8a87afe8bd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / pitchapi-0.1.6-py3-none-any.whl

Download URL pitchapi-0.1.6-py3-none-any.whl
Size 29.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30908d357222f1ea58d80428d3d4b33c99ed47fb01e8088d986e4d54b386a1a9
BLAKE2b-256 checksum
How to use checksums
9015943539a1253b10bfde9bae49d6e2aedde1a9fe2faf301892a4a021b80b04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for pitchapi 0.1.6

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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