datasportsapi 0.0.1__tar.gz → 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ dist/
3
+ __pycache__/
4
+ *.egg-info/
5
+ .DS_Store
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Noventra Software Ltd
3
+ Copyright (c) 2026 DataSportsAPI
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.5
2
+ Name: datasportsapi
3
+ Version: 0.1.0
4
+ Summary: Official Python client for the DataSportsAPI sports data API: a typed method per endpoint, sync and asyncio, paging, retries and the live WebSocket stream.
5
+ Project-URL: Homepage, https://datasportsapi.com/sdks/python/
6
+ Project-URL: Documentation, https://datasportsapi.com/docs/
7
+ Project-URL: Source, https://github.com/datasportsapi/datasportsapi-python
8
+ Project-URL: Issues, https://github.com/datasportsapi/datasportsapi-python/issues
9
+ Author: DataSportsAPI
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api client,football,live scores,sports,sports api,sports data,websocket
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Software Development :: Libraries
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/markdown
27
+
28
+ # datasportsapi
29
+
30
+ The official Python client for [DataSportsAPI](https://datasportsapi.com): live scores,
31
+ fixtures, lineups, statistics, standings and more for 25 sports.
32
+
33
+ Every endpoint is a method, on a blocking client and on an asyncio client with the same
34
+ surface. Answers are plain dicts described by TypedDicts, so your editor knows the fields.
35
+ Paged lists come with iterators, rate-limit answers are retried for you, and Business plans
36
+ get the live WebSocket stream with a fixture copy that stays current. No dependencies;
37
+ Python 3.10 or newer.
38
+
39
+ - SDK guide: <https://datasportsapi.com/sdks/python/>
40
+ - API docs: <https://datasportsapi.com/docs/>
41
+
42
+ ## Install
43
+
44
+ ```bash
45
+ pip install datasportsapi
46
+ ```
47
+
48
+ ## Your key
49
+
50
+ Create a key in your dashboard (a free one at <https://datasportsapi.com/signup/>). The client
51
+ reads it from `DATASPORTSAPI_API_KEY` when you pass none:
52
+
53
+ ```python
54
+ from datasportsapi import DataSportsAPI
55
+
56
+ client = DataSportsAPI() # DATASPORTSAPI_API_KEY
57
+ client = DataSportsAPI(api_key="sk_live_…") # or in code
58
+ ```
59
+
60
+ ## First calls
61
+
62
+ Values from the URL path come first, in path order; the query follows as keyword
63
+ arguments named like the API's parameters, in snake_case. You get back the same
64
+ `{ "data": …, "meta": … }` envelope the HTTP API returns.
65
+
66
+ ```python
67
+ live = client.livescores.list(sport="football")
68
+ for fixture in live["data"]:
69
+ print(fixture["home"]["name"], fixture["homeScore"]["current"], "–",
70
+ fixture["awayScore"]["current"], fixture["away"]["name"])
71
+
72
+ table = client.leagues.standings(17, season=61627)["data"]
73
+ lineups = client.fixtures.lineups(211521)["data"]
74
+ export = client.exports.create(league=17, season=61627, format="csv")
75
+ ```
76
+
77
+ The types live in `datasportsapi.types` (`Fixture`, `TeamRef`, `LeaguesStandingsResponse`, …).
78
+ They describe the dicts and validate nothing at runtime: when the API adds a field, it simply
79
+ shows up in the dict.
80
+
81
+ ## Errors
82
+
83
+ Each HTTP status has its own exception class, and all of them extend `DataSportsAPIError`.
84
+ Branch on `e.code`, the API's stable error code; `e.message` is written for people and may be
85
+ reworded.
86
+
87
+ ```python
88
+ from datasportsapi import DataSportsAPIError, NotFoundError, PermissionDeniedError
89
+
90
+ try:
91
+ client.fixtures.momentum(211521)
92
+ except PermissionDeniedError as e: # 403: e.code == "endpoint_not_in_plan", …
93
+ print(e.upgrade_url)
94
+ except NotFoundError as e: # 404: not_found, no_data, not_supported
95
+ ...
96
+ except DataSportsAPIError as e: # anything else: e.status, e.code, e.message, e.retry_after
97
+ ...
98
+ ```
99
+
100
+ | Status | Class |
101
+ |---|---|
102
+ | 400 | `BadRequestError` |
103
+ | 401 | `AuthenticationError` |
104
+ | 403 | `PermissionDeniedError` |
105
+ | 404 | `NotFoundError` |
106
+ | 429 | `RateLimitError` |
107
+ | 500 | `InternalServerError` |
108
+ | 503 | `ServiceUnavailableError` |
109
+ | other | `DataSportsAPIError` |
110
+ | no answer | `APIConnectionError` (`status` 0, `code` `connection_error` or `timeout`) |
111
+
112
+ ## Retries and settings
113
+
114
+ Two answers are worth another attempt: `429` with the code `rate_limited`, and `503`. The
115
+ client waits for the seconds in their `Retry-After` header (1, 2, 4 … up to 8 seconds when
116
+ there is none) and tries again, two more times by default. A `Retry-After` above 60 seconds is
117
+ not waited out: you get the error straight away. `429 quota_exceeded` is never retried (a
118
+ quota does not refill within seconds), and neither is any other status or a network failure.
119
+
120
+ ```python
121
+ DataSportsAPI(
122
+ api_key=..., # or DATASPORTSAPI_API_KEY
123
+ base_url=..., # or DATASPORTSAPI_BASE_URL
124
+ timeout=30.0, # seconds, for each attempt
125
+ max_retries=2,
126
+ )
127
+ ```
128
+
129
+ ## Paging
130
+
131
+ Each paged endpoint has a twin with a `_pages` suffix. It fetches page after page, by page
132
+ number or by cursor as the endpoint works, and yields every envelope until the list ends or
133
+ `max_pages` is reached.
134
+
135
+ ```python
136
+ for page in client.teams.fixtures_pages(42, type="recent", max_pages=3):
137
+ for fixture in page["data"]:
138
+ ...
139
+ ```
140
+
141
+ ## asyncio
142
+
143
+ `AsyncDataSportsAPI` has every method of the blocking client; await the calls and use
144
+ `async for` with the `_pages` iterators.
145
+
146
+ ```python
147
+ import asyncio
148
+ from datasportsapi import AsyncDataSportsAPI
149
+
150
+
151
+ async def main() -> None:
152
+ async with AsyncDataSportsAPI() as client:
153
+ fixture = await client.fixtures.get(211521)
154
+ print(fixture["data"]["status"]["description"])
155
+ async for page in client.search.query_pages(q="arsenal", max_pages=2):
156
+ ...
157
+
158
+
159
+ asyncio.run(main())
160
+ ```
161
+
162
+ ## Live stream (Business and up)
163
+
164
+ `client.stream(channels)` opens the WebSocket and does the bookkeeping: it fetches a
165
+ single-use ticket, subscribes when the server says hello, asks for a resync when a sequence
166
+ number is skipped, and reconnects after a dropped socket or a server restart, replaying what
167
+ was missed where the plan allows. It also keeps its own copy of every fixture on the list and
168
+ fixture channels with each delta applied; `stream.fixtures(channel)` hands you a copy.
169
+
170
+ ```python
171
+ with client.stream(["livescores", "fixture:211521"]) as stream:
172
+ for frame in stream:
173
+ if frame["type"] == "delta":
174
+ print(frame["id"], frame["changes"])
175
+ in_play = stream.fixtures("livescores") # deltas applied, finished matches dropped
176
+ ```
177
+
178
+ `stream.subscribe(channel)` and `stream.unsubscribe(channel)` change the channels while it
179
+ runs. With `AsyncDataSportsAPI`, use `async with client.stream([...]) as stream:` and
180
+ `async for frame in stream:`. When the server ends the stream for good (a revoked key, a plan
181
+ without the stream, too many connections), the loop raises once (`StreamClosedError`, or the
182
+ ticket's `AuthenticationError` / `PermissionDeniedError`) and the stream is over.
183
+
184
+ ## Security
185
+
186
+ - The key travels only in the `Authorization` header, and only to the base URL you
187
+ configured. It is never put in a URL, an error message or a `repr()`; the WebSocket URL
188
+ carries a single-use ticket instead.
189
+ - The base URL must use `https://` (plain `http://` is accepted only for `localhost`,
190
+ `127.0.0.1` and `[::1]`, for tests and local proxies).
191
+ - Redirects are never followed: a `3xx` answer becomes an error, so the key cannot be carried
192
+ to another host.
193
+ - This is a server-side library. Keep a secret key out of browsers, mobile apps and anything
194
+ else you ship to users.
195
+
196
+ ## License
197
+
198
+ MIT. © DataSportsAPI.
@@ -0,0 +1,171 @@
1
+ # datasportsapi
2
+
3
+ The official Python client for [DataSportsAPI](https://datasportsapi.com): live scores,
4
+ fixtures, lineups, statistics, standings and more for 25 sports.
5
+
6
+ Every endpoint is a method, on a blocking client and on an asyncio client with the same
7
+ surface. Answers are plain dicts described by TypedDicts, so your editor knows the fields.
8
+ Paged lists come with iterators, rate-limit answers are retried for you, and Business plans
9
+ get the live WebSocket stream with a fixture copy that stays current. No dependencies;
10
+ Python 3.10 or newer.
11
+
12
+ - SDK guide: <https://datasportsapi.com/sdks/python/>
13
+ - API docs: <https://datasportsapi.com/docs/>
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install datasportsapi
19
+ ```
20
+
21
+ ## Your key
22
+
23
+ Create a key in your dashboard (a free one at <https://datasportsapi.com/signup/>). The client
24
+ reads it from `DATASPORTSAPI_API_KEY` when you pass none:
25
+
26
+ ```python
27
+ from datasportsapi import DataSportsAPI
28
+
29
+ client = DataSportsAPI() # DATASPORTSAPI_API_KEY
30
+ client = DataSportsAPI(api_key="sk_live_…") # or in code
31
+ ```
32
+
33
+ ## First calls
34
+
35
+ Values from the URL path come first, in path order; the query follows as keyword
36
+ arguments named like the API's parameters, in snake_case. You get back the same
37
+ `{ "data": …, "meta": … }` envelope the HTTP API returns.
38
+
39
+ ```python
40
+ live = client.livescores.list(sport="football")
41
+ for fixture in live["data"]:
42
+ print(fixture["home"]["name"], fixture["homeScore"]["current"], "–",
43
+ fixture["awayScore"]["current"], fixture["away"]["name"])
44
+
45
+ table = client.leagues.standings(17, season=61627)["data"]
46
+ lineups = client.fixtures.lineups(211521)["data"]
47
+ export = client.exports.create(league=17, season=61627, format="csv")
48
+ ```
49
+
50
+ The types live in `datasportsapi.types` (`Fixture`, `TeamRef`, `LeaguesStandingsResponse`, …).
51
+ They describe the dicts and validate nothing at runtime: when the API adds a field, it simply
52
+ shows up in the dict.
53
+
54
+ ## Errors
55
+
56
+ Each HTTP status has its own exception class, and all of them extend `DataSportsAPIError`.
57
+ Branch on `e.code`, the API's stable error code; `e.message` is written for people and may be
58
+ reworded.
59
+
60
+ ```python
61
+ from datasportsapi import DataSportsAPIError, NotFoundError, PermissionDeniedError
62
+
63
+ try:
64
+ client.fixtures.momentum(211521)
65
+ except PermissionDeniedError as e: # 403: e.code == "endpoint_not_in_plan", …
66
+ print(e.upgrade_url)
67
+ except NotFoundError as e: # 404: not_found, no_data, not_supported
68
+ ...
69
+ except DataSportsAPIError as e: # anything else: e.status, e.code, e.message, e.retry_after
70
+ ...
71
+ ```
72
+
73
+ | Status | Class |
74
+ |---|---|
75
+ | 400 | `BadRequestError` |
76
+ | 401 | `AuthenticationError` |
77
+ | 403 | `PermissionDeniedError` |
78
+ | 404 | `NotFoundError` |
79
+ | 429 | `RateLimitError` |
80
+ | 500 | `InternalServerError` |
81
+ | 503 | `ServiceUnavailableError` |
82
+ | other | `DataSportsAPIError` |
83
+ | no answer | `APIConnectionError` (`status` 0, `code` `connection_error` or `timeout`) |
84
+
85
+ ## Retries and settings
86
+
87
+ Two answers are worth another attempt: `429` with the code `rate_limited`, and `503`. The
88
+ client waits for the seconds in their `Retry-After` header (1, 2, 4 … up to 8 seconds when
89
+ there is none) and tries again, two more times by default. A `Retry-After` above 60 seconds is
90
+ not waited out: you get the error straight away. `429 quota_exceeded` is never retried (a
91
+ quota does not refill within seconds), and neither is any other status or a network failure.
92
+
93
+ ```python
94
+ DataSportsAPI(
95
+ api_key=..., # or DATASPORTSAPI_API_KEY
96
+ base_url=..., # or DATASPORTSAPI_BASE_URL
97
+ timeout=30.0, # seconds, for each attempt
98
+ max_retries=2,
99
+ )
100
+ ```
101
+
102
+ ## Paging
103
+
104
+ Each paged endpoint has a twin with a `_pages` suffix. It fetches page after page, by page
105
+ number or by cursor as the endpoint works, and yields every envelope until the list ends or
106
+ `max_pages` is reached.
107
+
108
+ ```python
109
+ for page in client.teams.fixtures_pages(42, type="recent", max_pages=3):
110
+ for fixture in page["data"]:
111
+ ...
112
+ ```
113
+
114
+ ## asyncio
115
+
116
+ `AsyncDataSportsAPI` has every method of the blocking client; await the calls and use
117
+ `async for` with the `_pages` iterators.
118
+
119
+ ```python
120
+ import asyncio
121
+ from datasportsapi import AsyncDataSportsAPI
122
+
123
+
124
+ async def main() -> None:
125
+ async with AsyncDataSportsAPI() as client:
126
+ fixture = await client.fixtures.get(211521)
127
+ print(fixture["data"]["status"]["description"])
128
+ async for page in client.search.query_pages(q="arsenal", max_pages=2):
129
+ ...
130
+
131
+
132
+ asyncio.run(main())
133
+ ```
134
+
135
+ ## Live stream (Business and up)
136
+
137
+ `client.stream(channels)` opens the WebSocket and does the bookkeeping: it fetches a
138
+ single-use ticket, subscribes when the server says hello, asks for a resync when a sequence
139
+ number is skipped, and reconnects after a dropped socket or a server restart, replaying what
140
+ was missed where the plan allows. It also keeps its own copy of every fixture on the list and
141
+ fixture channels with each delta applied; `stream.fixtures(channel)` hands you a copy.
142
+
143
+ ```python
144
+ with client.stream(["livescores", "fixture:211521"]) as stream:
145
+ for frame in stream:
146
+ if frame["type"] == "delta":
147
+ print(frame["id"], frame["changes"])
148
+ in_play = stream.fixtures("livescores") # deltas applied, finished matches dropped
149
+ ```
150
+
151
+ `stream.subscribe(channel)` and `stream.unsubscribe(channel)` change the channels while it
152
+ runs. With `AsyncDataSportsAPI`, use `async with client.stream([...]) as stream:` and
153
+ `async for frame in stream:`. When the server ends the stream for good (a revoked key, a plan
154
+ without the stream, too many connections), the loop raises once (`StreamClosedError`, or the
155
+ ticket's `AuthenticationError` / `PermissionDeniedError`) and the stream is over.
156
+
157
+ ## Security
158
+
159
+ - The key travels only in the `Authorization` header, and only to the base URL you
160
+ configured. It is never put in a URL, an error message or a `repr()`; the WebSocket URL
161
+ carries a single-use ticket instead.
162
+ - The base URL must use `https://` (plain `http://` is accepted only for `localhost`,
163
+ `127.0.0.1` and `[::1]`, for tests and local proxies).
164
+ - Redirects are never followed: a `3xx` answer becomes an error, so the key cannot be carried
165
+ to another host.
166
+ - This is a server-side library. Keep a secret key out of browsers, mobile apps and anything
167
+ else you ship to users.
168
+
169
+ ## License
170
+
171
+ MIT. © DataSportsAPI.
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.24"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "datasportsapi"
7
+ version = "0.1.0"
8
+ description = "Official Python client for the DataSportsAPI sports data API: a typed method per endpoint, sync and asyncio, paging, retries and the live WebSocket stream."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "DataSportsAPI" }]
14
+ keywords = ["sports", "sports api", "sports data", "live scores", "football", "api client", "websocket"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Framework :: AsyncIO",
26
+ "Topic :: Software Development :: Libraries",
27
+ "Typing :: Typed",
28
+ ]
29
+ dependencies = []
30
+
31
+ [project.urls]
32
+ Homepage = "https://datasportsapi.com/sdks/python/"
33
+ Documentation = "https://datasportsapi.com/docs/"
34
+ Source = "https://github.com/datasportsapi/datasportsapi-python"
35
+ Issues = "https://github.com/datasportsapi/datasportsapi-python/issues"
36
+
37
+ # Only the package goes into the wheel and the sdist: no tests, no scan script, no .venv.
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/datasportsapi"]
40
+ exclude = ["__pycache__", "*.pyc"]
41
+
42
+ [tool.hatch.build.targets.sdist]
43
+ only-include = ["src/datasportsapi", "README.md", "LICENSE", "pyproject.toml"]
44
+ exclude = ["__pycache__", "*.pyc"]
@@ -0,0 +1,49 @@
1
+ """datasportsapi: the official Python client for the DataSportsAPI sports data API.
2
+
3
+ from datasportsapi import DataSportsAPI
4
+
5
+ client = DataSportsAPI() # reads DATASPORTSAPI_API_KEY
6
+ live = client.livescores.list(sport="football")
7
+
8
+ A method per endpoint on a blocking client (DataSportsAPI) and on an asyncio
9
+ client (AsyncDataSportsAPI); <name>_pages iterators for paged lists; retries on
10
+ 429 rate_limited and 503; the live WebSocket stream (client.stream). The
11
+ response types are in datasportsapi.types. No dependencies.
12
+
13
+ Docs: https://datasportsapi.com/sdks/python/
14
+ """
15
+
16
+ from ._client import DEFAULT_BASE_URL, AsyncDataSportsAPI, DataSportsAPI
17
+ from ._errors import (
18
+ APIConnectionError,
19
+ AuthenticationError,
20
+ BadRequestError,
21
+ DataSportsAPIError,
22
+ InternalServerError,
23
+ NotFoundError,
24
+ PermissionDeniedError,
25
+ RateLimitError,
26
+ ServiceUnavailableError,
27
+ StreamClosedError,
28
+ )
29
+ from ._stream import AsyncStream, Stream
30
+ from ._version import __version__
31
+
32
+ __all__ = [
33
+ "DataSportsAPI",
34
+ "AsyncDataSportsAPI",
35
+ "Stream",
36
+ "AsyncStream",
37
+ "DataSportsAPIError",
38
+ "APIConnectionError",
39
+ "StreamClosedError",
40
+ "BadRequestError",
41
+ "AuthenticationError",
42
+ "PermissionDeniedError",
43
+ "NotFoundError",
44
+ "RateLimitError",
45
+ "InternalServerError",
46
+ "ServiceUnavailableError",
47
+ "DEFAULT_BASE_URL",
48
+ "__version__",
49
+ ]