datasportsapi 0.0.1__py3-none-any.whl
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,82 @@
|
|
|
1
|
+
"""datasportsapi 0.0.x: a minimal client for the DataSportsAPI REST API.
|
|
2
|
+
|
|
3
|
+
One authenticated GET that returns the parsed JSON envelope and raises
|
|
4
|
+
DataSportsAPIError for any non-2xx answer. No dependencies. The full SDK (a
|
|
5
|
+
typed method per endpoint, paging, retries, asyncio and the WebSocket stream)
|
|
6
|
+
arrives with 0.1.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import urllib.error
|
|
14
|
+
import urllib.parse
|
|
15
|
+
import urllib.request
|
|
16
|
+
from typing import Any, Mapping
|
|
17
|
+
|
|
18
|
+
__version__ = "0.0.1"
|
|
19
|
+
__all__ = ["DataSportsAPI", "DataSportsAPIError", "__version__"]
|
|
20
|
+
|
|
21
|
+
DEFAULT_BASE_URL = "https://api.datasportsapi.com"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DataSportsAPIError(Exception):
|
|
25
|
+
"""A non-2xx answer: the HTTP status, the API's error code and Retry-After."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, status: int, code: str, message: str, retry_after: float | None = None) -> None:
|
|
28
|
+
super().__init__(f"{status} {code}: {message}")
|
|
29
|
+
self.status = status
|
|
30
|
+
self.code = code
|
|
31
|
+
self.message = message
|
|
32
|
+
self.retry_after = retry_after
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _query_value(v: Any) -> str:
|
|
36
|
+
if isinstance(v, bool):
|
|
37
|
+
return "true" if v else "false"
|
|
38
|
+
return str(v)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class DataSportsAPI:
|
|
42
|
+
"""client = DataSportsAPI() # reads DATASPORTSAPI_API_KEY"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, api_key: str | None = None, *, base_url: str | None = None, timeout: float = 30.0) -> None:
|
|
45
|
+
key = api_key or os.environ.get("DATASPORTSAPI_API_KEY")
|
|
46
|
+
if not key:
|
|
47
|
+
raise ValueError("DataSportsAPI: pass api_key or set DATASPORTSAPI_API_KEY")
|
|
48
|
+
self._key = key
|
|
49
|
+
self._base = (base_url or os.environ.get("DATASPORTSAPI_BASE_URL") or DEFAULT_BASE_URL).rstrip("/")
|
|
50
|
+
self._timeout = timeout
|
|
51
|
+
|
|
52
|
+
def get(self, path: str, params: Mapping[str, Any] | None = None, **kwargs: Any) -> Any:
|
|
53
|
+
"""GET a path of the API, e.g. client.get("/v2/livescores", sport="football")."""
|
|
54
|
+
query = {k: v for k, v in {**(params or {}), **kwargs}.items() if v is not None}
|
|
55
|
+
url = self._base + (path if path.startswith("/") else "/" + path)
|
|
56
|
+
if query:
|
|
57
|
+
url += "?" + urllib.parse.urlencode({k: _query_value(v) for k, v in query.items()})
|
|
58
|
+
request = urllib.request.Request(
|
|
59
|
+
url,
|
|
60
|
+
headers={
|
|
61
|
+
"Authorization": f"Bearer {self._key}",
|
|
62
|
+
"Accept": "application/json",
|
|
63
|
+
"User-Agent": f"datasportsapi-python/{__version__}",
|
|
64
|
+
},
|
|
65
|
+
)
|
|
66
|
+
try:
|
|
67
|
+
with urllib.request.urlopen(request, timeout=self._timeout) as response:
|
|
68
|
+
raw = response.read()
|
|
69
|
+
except urllib.error.HTTPError as e:
|
|
70
|
+
raw = e.read()
|
|
71
|
+
try:
|
|
72
|
+
error = (json.loads(raw) or {}).get("error") or {}
|
|
73
|
+
except (ValueError, AttributeError):
|
|
74
|
+
error = {}
|
|
75
|
+
retry = e.headers.get("Retry-After")
|
|
76
|
+
try:
|
|
77
|
+
retry_after = float(retry) if retry is not None else None
|
|
78
|
+
except ValueError:
|
|
79
|
+
retry_after = None
|
|
80
|
+
message = error.get("message") or raw[:200].decode("utf-8", "replace") or e.reason or f"HTTP {e.code}"
|
|
81
|
+
raise DataSportsAPIError(e.code, error.get("code") or f"http_{e.code}", str(message), retry_after) from None
|
|
82
|
+
return json.loads(raw) if raw else None
|
datasportsapi/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datasportsapi
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Official client for the DataSportsAPI sports data API (pre-release: a minimal client; the full SDK arrives with 0.1).
|
|
5
|
+
Project-URL: Homepage, https://datasportsapi.com/sdks/python/
|
|
6
|
+
Project-URL: Documentation, https://datasportsapi.com/docs/sdks/
|
|
7
|
+
Author: Noventra Software Ltd
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: api client,football,live scores,sports,sports api,sports data
|
|
11
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# datasportsapi
|
|
21
|
+
|
|
22
|
+
The official Python client for [DataSportsAPI](https://datasportsapi.com), a sports data API:
|
|
23
|
+
live scores, fixtures, lineups, statistics and standings for 24 sports.
|
|
24
|
+
|
|
25
|
+
> **Pre-release.** The API opens at launch; until then requests do not get an answer.
|
|
26
|
+
> This 0.0.x release is a minimal client: one authenticated `get()` with typed errors and no
|
|
27
|
+
> dependencies. The full SDK (a typed method for every endpoint, paging, retries, asyncio and
|
|
28
|
+
> the WebSocket stream) arrives with 0.1. Docs: <https://datasportsapi.com/docs/sdks/>
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install datasportsapi
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from datasportsapi import DataSportsAPI, DataSportsAPIError
|
|
36
|
+
|
|
37
|
+
client = DataSportsAPI() # reads DATASPORTSAPI_API_KEY
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
res = client.get("/v2/livescores", sport="football")
|
|
41
|
+
print(res["data"])
|
|
42
|
+
except DataSportsAPIError as e:
|
|
43
|
+
print(e.status, e.code, e.retry_after)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- `api_key` defaults to `DATASPORTSAPI_API_KEY`; `base_url` to `DATASPORTSAPI_BASE_URL`, then
|
|
47
|
+
`https://api.datasportsapi.com`.
|
|
48
|
+
- Python 3.10+.
|
|
49
|
+
- Get a key at <https://datasportsapi.com/signup/>.
|
|
50
|
+
|
|
51
|
+
MIT licensed. © Noventra Software Ltd.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
datasportsapi/__init__.py,sha256=1OKjJMyyyUwdQ8eaak7cUYIiOlm3Iyhy58zGb3z2jZo,3280
|
|
2
|
+
datasportsapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
datasportsapi-0.0.1.dist-info/METADATA,sha256=g15exbM-lmjuf-UABbPGoXSAk1TBlrzKwka4ZqCviXY,1918
|
|
4
|
+
datasportsapi-0.0.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
5
|
+
datasportsapi-0.0.1.dist-info/licenses/LICENSE,sha256=iKmwhMT2IOxV9EimZ7UNOOeJG4tPIRkrp4FAtVQYZKk,1078
|
|
6
|
+
datasportsapi-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Noventra Software Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|