datasportsapi
The official Python client for DataSportsAPI: live scores, fixtures, lineups, statistics, standings and more for 25 sports.
Every endpoint is a method, on a blocking client and on an asyncio client with the same surface. Answers are plain dicts described by TypedDicts, so your editor knows the fields. Paged lists come with iterators, rate-limit answers are retried for you, and Business plans get the live WebSocket stream with a fixture copy that stays current. No dependencies; Python 3.10 or newer.
- SDK guide: https://datasportsapi.com/sdks/python/
- API docs: https://datasportsapi.com/docs/
Install
pip install datasportsapi
Your key
Create a key in your dashboard (a free one at https://datasportsapi.com/signup/). The client
reads it from DATASPORTSAPI_API_KEY when you pass none:
from datasportsapi import DataSportsAPI
client = DataSportsAPI() # DATASPORTSAPI_API_KEY
client = DataSportsAPI(api_key="sk_live_…") # or in code
First calls
Values from the URL path come first, in path order; the query follows as keyword
arguments named like the API's parameters, in snake_case. You get back the same
{ "data": …, "meta": … } envelope the HTTP API returns.
live = client.livescores.list(sport="football")
for fixture in live["data"]:
print(fixture["home"]["name"], fixture["homeScore"]["current"], "–",
fixture["awayScore"]["current"], fixture["away"]["name"])
table = client.leagues.standings(17, season=61627)["data"]
lineups = client.fixtures.lineups(211521)["data"]
export = client.exports.create(league=17, season=61627, format="csv")
The types live in datasportsapi.types (Fixture, TeamRef, LeaguesStandingsResponse, …).
They describe the dicts and validate nothing at runtime: when the API adds a field, it simply
shows up in the dict.
Errors
Each HTTP status has its own exception class, and all of them extend DataSportsAPIError.
Branch on e.code, the API's stable error code; e.message is written for people and may be
reworded.
from datasportsapi import DataSportsAPIError, NotFoundError, PermissionDeniedError
try:
client.fixtures.momentum(211521)
except PermissionDeniedError as e: # 403: e.code == "endpoint_not_in_plan", …
print(e.upgrade_url)
except NotFoundError as e: # 404: not_found, no_data, not_supported
...
except DataSportsAPIError as e: # anything else: e.status, e.code, e.message, e.retry_after
...
| Status | Class |
|---|---|
| 400 | BadRequestError |
| 401 | AuthenticationError |
| 403 | PermissionDeniedError |
| 404 | NotFoundError |
| 429 | RateLimitError |
| 500 | InternalServerError |
| 503 | ServiceUnavailableError |
| other | DataSportsAPIError |
| no answer | APIConnectionError (status 0, code connection_error or timeout) |
Retries and settings
Two answers are worth another attempt: 429 with the code rate_limited, and 503. The
client waits for the seconds in their Retry-After header (1, 2, 4 … up to 8 seconds when
there is none) and tries again, two more times by default. A Retry-After above 60 seconds is
not waited out: you get the error straight away. 429 quota_exceeded is never retried (a
quota does not refill within seconds), and neither is any other status or a network failure.
DataSportsAPI(
api_key=..., # or DATASPORTSAPI_API_KEY
base_url=..., # or DATASPORTSAPI_BASE_URL
timeout=30.0, # seconds, for each attempt
max_retries=2,
)
Paging
Each paged endpoint has a twin with a _pages suffix. It fetches page after page, by page
number or by cursor as the endpoint works, and yields every envelope until the list ends or
max_pages is reached.
for page in client.teams.fixtures_pages(42, type="recent", max_pages=3):
for fixture in page["data"]:
...
asyncio
AsyncDataSportsAPI has every method of the blocking client; await the calls and use
async for with the _pages iterators.
import asyncio
from datasportsapi import AsyncDataSportsAPI
async def main() -> None:
async with AsyncDataSportsAPI() as client:
fixture = await client.fixtures.get(211521)
print(fixture["data"]["status"]["description"])
async for page in client.search.query_pages(q="arsenal", max_pages=2):
...
asyncio.run(main())
Live stream (Business and up)
client.stream(channels) opens the WebSocket and does the bookkeeping: it fetches a
single-use ticket, subscribes when the server says hello, asks for a resync when a sequence
number is skipped, and reconnects after a dropped socket or a server restart, replaying what
was missed where the plan allows. It also keeps its own copy of every fixture on the list and
fixture channels with each delta applied; stream.fixtures(channel) hands you a copy.
with client.stream(["livescores", "fixture:211521"]) as stream:
for frame in stream:
if frame["type"] == "delta":
print(frame["id"], frame["changes"])
in_play = stream.fixtures("livescores") # deltas applied, finished matches dropped
stream.subscribe(channel) and stream.unsubscribe(channel) change the channels while it
runs. With AsyncDataSportsAPI, use async with client.stream([...]) as stream: and
async for frame in stream:. When the server ends the stream for good (a revoked key, a plan
without the stream, too many connections), the loop raises once (StreamClosedError, or the
ticket's AuthenticationError / PermissionDeniedError) and the stream is over.
Security
- The key travels only in the
Authorizationheader, and only to the base URL you configured. It is never put in a URL, an error message or arepr(); the WebSocket URL carries a single-use ticket instead. - The base URL must use
https://(plainhttp://is accepted only forlocalhost,127.0.0.1and[::1], for tests and local proxies). - Redirects are never followed: a
3xxanswer becomes an error, so the key cannot be carried to another host. - This is a server-side library. Keep a secret key out of browsers, mobile apps and anything else you ship to users.
Help
Questions, ideas and what you built: the developer Discord (#python), or info@datasportsapi.com. Guide: https://datasportsapi.com/sdks/python/
License
MIT. © DataSportsAPI.
Metadata
Release files for datasportsapi 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datasportsapi-0.2.4.tar.gz | 85.9 kB | With provenance | Details for datasportsapi-0.2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datasportsapi-0.2.4-py3-none-any.whl | Python 3 | none | any | Details for datasportsapi-0.2.4-py3-none-any.whl |
Total release size: 175.3 kB
Release files / datasportsapi-0.2.4.tar.gz
| Download URL | datasportsapi-0.2.4.tar.gz |
|---|---|
| Size | 85.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ab41d4b26d402979543fb006d1f567ebb42134a90bf16947a51858bf0976e64
|
|
BLAKE2b-256 checksum How to use checksums |
bdbd46089bec660625abfe565140d195fd0c76c4b5a32a07fa2ade529038f313
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 1, 2026.
Transparency logRelease files / datasportsapi-0.2.4-py3-none-any.whl
| Download URL | datasportsapi-0.2.4-py3-none-any.whl |
|---|---|
| Size | 89.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9494918f4283508d3236d8458cd95d41d7ad5634b2be8362fdcb1cb9de8a3757
|
|
BLAKE2b-256 checksum How to use checksums |
81d17d9a6517bd7840798582713f9e377c03ca7ee0a5015f272bfa9c2e74e087
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 1, 2026.
Transparency logSecurity for datasportsapi 0.2.4
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for datasportsapi-0.2.4.tar.gz
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 Dec 1, 2026.
Transparency logA 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.