Skip to main content

Official Python client for the Live Tennis API — real-time tennis scores, players, market prices and model win-probability over REST and WebSocket.

Project description

Live Tennis API

livetennisapi

Official Python client for the Live Tennis API.

Real-time tennis scores, players, rankings, match-winner market prices and model win-probability — for ATP, WTA, Challenger and ITF, over REST and WebSocket.

PyPI Python License

Documentation · Get an API key


Install

pip install livetennisapi          # REST client + CLI
pip install "livetennisapi[all]"   # + WebSocket feed and rich CLI tables

Use

from livetennisapi import LiveTennisAPI

with LiveTennisAPI(api_key="twjp_…") as client:   # or set LIVETENNISAPI_KEY
    for match in client.list_matches(status="live"):
        print(match.tournament, match.p1.name, "vs", match.p2.name, match.score.sets)

Async is the same API, awaited:

from livetennisapi import AsyncLiveTennisAPI

async with AsyncLiveTennisAPI() as client:
    match = await client.get_match(18953)

Command line

The package ships a livetennis command:

$ livetennis live
Live matches (3)
ID     Tournament            Rd   Players                  Score
18953  ATP Wimbledon         R16  *Alcaraz / Sinner        6-4 3-6 2-1 (40-30)

$ livetennis match 18953
$ livetennis players djokovic
$ livetennis watch --match 18953     # live WebSocket stream

Live score feed (ULTRA)

from livetennisapi import LiveScoreStream

with LiveScoreStream() as stream:
    for update in stream:
        print(update.match_id, update.score.sets)

Reconnects automatically with backoff and re-subscribes. Heartbeats are consumed internally, so you only see real score changes. It deliberately does not reconnect on a bad key or an insufficient tier — those raise immediately rather than retry forever.

Tiers

BASIC PRO ULTRA
list_matches get_match get_match_score
search_players get_player list_fixtures list_completed_matches
list_match_events list_markets get_market_prices
get_match_analysis, win_probability_p1 / danger, WebSocket

Calling above your tier raises UpgradeRequired, which tells you which tier you need:

from livetennisapi import UpgradeRequired

try:
    client.get_match_analysis(18953)
except UpgradeRequired as exc:
    print(exc.required_tier)   # 'ULTRA'

Errors

Exception When
Unauthorized 401 — key missing, unknown, or disabled
UpgradeRequired 403 — valid key, tier too low (carries .required_tier)
NotFound 404 — no such resource, or no data yet
RateLimited 429 — carries .retry_after in seconds
ServerError / ServiceUnavailable 5xx
APIConnectionError / APITimeoutError never reached the API

All inherit from LiveTennisAPIError.

Requests retry automatically on 429 and 5xx only, honouring Retry-After with exponential backoff and jitter. Other 4xx are never retried — a bad key or an unentitled tier cannot start working, and retrying only burns rate limit.

Pagination

limit defaults to 50 and caps at 200. To walk everything:

for player in client.paginate("search_players", search="nadal"):
    print(player.name)

Forward compatibility

The API ships additive changes within v1, so this client never rejects a field it doesn't recognise. Unknown fields stay reachable:

match = client.get_match(18953)
match.raw["some_new_field"]   # always present
match.some_new_field          # also works

That means a new server-side field is usable without upgrading this package.

The score shape (read this one)

games is player-major, not set-major:

score.games      # [[6, 3, 2], [4, 6, 1]]  ->  6-4, 3-6, 2-1
                 #  ^p1 per set  ^p2 per set
score.sets       # [1, 1]  ->  one set each
score.server     # 1 or 2

Indexing it the other way is the most common mistake made against this API, so there's a helper:

score.games_for_set(0)   # (6, 4)

Configuration

LiveTennisAPI(
    api_key="twjp_…",          # or $LIVETENNISAPI_KEY
    base_url=None,             # or $LIVETENNISAPI_BASE_URL
    timeout=30.0,
    max_retries=2,
    auth_header="bearer",      # or "x-api-key"
)

Contributing

Issues and pull requests welcome at livetennisapi/livetennisapi-python.

pip install -e ".[dev]"
pytest                                    # unit tests, no key needed
LIVETENNISAPI_KEY=twjp_… pytest -m contract   # verify against the live API

The contract tests assert that the live API's real responses match these models. If the API and the spec disagree, that's a bug worth reporting.

Licence

MIT — see LICENSE. Use of the API service is governed by the Terms of Service.

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

livetennisapi-1.0.0.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

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

livetennisapi-1.0.0-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file livetennisapi-1.0.0.tar.gz.

File metadata

  • Download URL: livetennisapi-1.0.0.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for livetennisapi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c8c59169da129dfc0a144081b0c49b24ddf65009780a8dd3d797d6bdc127e7e0
MD5 6250243c9ee97a0745a82013a050dce8
BLAKE2b-256 d0ca058303d7a73540c5fb9cc3875162ba9afd6440c0ffe99e7c1f349e156b96

See more details on using hashes here.

Provenance

The following attestation bundles were made for livetennisapi-1.0.0.tar.gz:

Publisher: publish.yml on livetennisapi/livetennisapi-python

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

File details

Details for the file livetennisapi-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: livetennisapi-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for livetennisapi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 760293c3b7e14f756fd5600eb93629d83355d0c6f30edcaf2d903709ffc906d5
MD5 5b7c3c480842f48e3914408cd7b62241
BLAKE2b-256 17cae5dd4af779f23fecd0d8494db730dbe3aa987ce26f28d7d26de198c97db2

See more details on using hashes here.

Provenance

The following attestation bundles were made for livetennisapi-1.0.0-py3-none-any.whl:

Publisher: publish.yml on livetennisapi/livetennisapi-python

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