datafortennis 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.
- datafortennis-0.1.0/.github/workflows/publish.yml +60 -0
- datafortennis-0.1.0/.github/workflows/test.yml +33 -0
- datafortennis-0.1.0/.gitignore +11 -0
- datafortennis-0.1.0/PKG-INFO +136 -0
- datafortennis-0.1.0/README.md +116 -0
- datafortennis-0.1.0/examples/free_tournament.py +47 -0
- datafortennis-0.1.0/pyproject.toml +44 -0
- datafortennis-0.1.0/src/datafortennis/__init__.py +42 -0
- datafortennis-0.1.0/src/datafortennis/_transport.py +375 -0
- datafortennis-0.1.0/src/datafortennis/_types.py +63 -0
- datafortennis-0.1.0/src/datafortennis/_version.py +1 -0
- datafortennis-0.1.0/src/datafortennis/client.py +68 -0
- datafortennis-0.1.0/src/datafortennis/errors.py +87 -0
- datafortennis-0.1.0/src/datafortennis/models.py +891 -0
- datafortennis-0.1.0/src/datafortennis/py.typed +0 -0
- datafortennis-0.1.0/src/datafortennis/resources/__init__.py +1 -0
- datafortennis-0.1.0/src/datafortennis/resources/_base.py +180 -0
- datafortennis-0.1.0/src/datafortennis/resources/catalogue.py +286 -0
- datafortennis-0.1.0/src/datafortennis/resources/exports.py +91 -0
- datafortennis-0.1.0/src/datafortennis/resources/free.py +49 -0
- datafortennis-0.1.0/src/datafortennis/resources/live.py +181 -0
- datafortennis-0.1.0/src/datafortennis/resources/matches.py +256 -0
- datafortennis-0.1.0/src/datafortennis/resources/research.py +149 -0
- datafortennis-0.1.0/tests/check_contract.py +196 -0
- datafortennis-0.1.0/tests/test_resources.py +618 -0
- datafortennis-0.1.0/tests/test_transport.py +408 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
name: Publish Python SDK to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
permissions: {}
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
if: github.repository == 'DataForTennis/datafortennis-python' && github.ref_type == 'tag'
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
|
|
16
|
+
with:
|
|
17
|
+
persist-credentials: false
|
|
18
|
+
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
|
|
19
|
+
with:
|
|
20
|
+
python-version: '3.12'
|
|
21
|
+
- name: Test and build distributions
|
|
22
|
+
run: |
|
|
23
|
+
python -m pip install -e '.[dev]' twine
|
|
24
|
+
python -m pytest -q
|
|
25
|
+
python -m build
|
|
26
|
+
python -m twine check --strict dist/*
|
|
27
|
+
- name: Verify the installed wheel and release tag
|
|
28
|
+
run: |
|
|
29
|
+
python -m venv "$RUNNER_TEMP/installed"
|
|
30
|
+
"$RUNNER_TEMP/installed/bin/python" -m pip install dist/*.whl
|
|
31
|
+
"$RUNNER_TEMP/installed/bin/python" -I - <<'PY'
|
|
32
|
+
import os
|
|
33
|
+
import re
|
|
34
|
+
from importlib.metadata import version
|
|
35
|
+
|
|
36
|
+
from datafortennis import DataForTennis, __version__
|
|
37
|
+
|
|
38
|
+
assert __version__ == version("datafortennis")
|
|
39
|
+
assert re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", __version__)
|
|
40
|
+
assert os.environ["GITHUB_REF_NAME"] == f"v{__version__}"
|
|
41
|
+
DataForTennis().close()
|
|
42
|
+
PY
|
|
43
|
+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
44
|
+
with:
|
|
45
|
+
name: python-distributions
|
|
46
|
+
path: dist/
|
|
47
|
+
if-no-files-found: error
|
|
48
|
+
|
|
49
|
+
publish:
|
|
50
|
+
needs: build
|
|
51
|
+
runs-on: ubuntu-latest
|
|
52
|
+
environment: pypi
|
|
53
|
+
permissions:
|
|
54
|
+
id-token: write
|
|
55
|
+
steps:
|
|
56
|
+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
57
|
+
with:
|
|
58
|
+
name: python-distributions
|
|
59
|
+
path: dist/
|
|
60
|
+
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Python SDK
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
permissions:
|
|
7
|
+
contents: read
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
tests:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python: ['3.10', '3.12', '3.14']
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
|
|
17
|
+
with:
|
|
18
|
+
persist-credentials: false
|
|
19
|
+
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python }}
|
|
22
|
+
- name: Test clients and type signatures
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install -e '.[dev]'
|
|
25
|
+
python -m ruff check src tests examples
|
|
26
|
+
python -m mypy --strict src/datafortennis
|
|
27
|
+
python -m pytest -q
|
|
28
|
+
- name: Install the wheel in a separate environment
|
|
29
|
+
run: |
|
|
30
|
+
python -m build
|
|
31
|
+
python -m venv "$RUNNER_TEMP/sdk-wheel"
|
|
32
|
+
"$RUNNER_TEMP/sdk-wheel/bin/python" -m pip install dist/*.whl
|
|
33
|
+
"$RUNNER_TEMP/sdk-wheel/bin/python" -I -c 'from datafortennis import DataForTennis; DataForTennis().close()'
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datafortennis
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed synchronous client for the Data for Tennis API
|
|
5
|
+
Project-URL: Homepage, https://datafortennis.com
|
|
6
|
+
Project-URL: Documentation, https://docs.datafortennis.com
|
|
7
|
+
Project-URL: Source, https://github.com/DataForTennis/datafortennis-python
|
|
8
|
+
Project-URL: Releases, https://github.com/DataForTennis/datafortennis-python/releases
|
|
9
|
+
Author: Data for Tennis
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: Typing :: Typed
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: httpx<0.29,>=0.28.1
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: build<2,>=1.2; extra == 'dev'
|
|
16
|
+
Requires-Dist: mypy<2,>=1.13; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest<10,>=8.3; extra == 'dev'
|
|
18
|
+
Requires-Dist: ruff<1,>=0.9; extra == 'dev'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Data for Tennis for Python
|
|
22
|
+
|
|
23
|
+
Read matches, point-by-point records and statistics through the Data for Tennis API. Each historical result carries the release that produced it. The client also supports exports, live REST reads and stream tickets.
|
|
24
|
+
|
|
25
|
+
The SDK targets REST contract 1.12.1, SHA-256 `5409bc1a61fbdfd465abe4a7cbcc4d88d7aa515d4c41dac0f64774185d2a736e`. It covers 51 customer operations. The two infrastructure health probes are available directly over HTTP. [Public API documentation](https://docs.datafortennis.com)
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
Use Python 3.10 or later. In your virtual environment, install the wheel for release `v0.1.0`.
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
python -m pip install "https://github.com/DataForTennis/datafortennis-python/releases/download/v0.1.0/datafortennis-0.1.0-py3-none-any.whl"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Check coverage without an account
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from datafortennis import DataForTennis
|
|
39
|
+
|
|
40
|
+
with DataForTennis() as tennis:
|
|
41
|
+
result = tennis.coverage.summary(
|
|
42
|
+
release="research-challenger-20261007-v1",
|
|
43
|
+
category="Challenger",
|
|
44
|
+
season=2025,
|
|
45
|
+
)
|
|
46
|
+
pbp = next(row for row in result.data if row["family"] == "pbp")
|
|
47
|
+
print(pbp["available"], "of", pbp["census"], "matches have point data")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The December 2, 2026 coverage summary for this named release reported 10,177 of 10,302 matches. All 10,177 were classified as partial. Coverage counts use decimal strings. The corresponding 2019 query reported zero matches with point data among 5,223 matches. [Coverage summary](https://api.datafortennis.com/v1/coverage/summary?release=research-challenger-20261007-v1&category=Challenger&season=2025)
|
|
51
|
+
|
|
52
|
+
## Read the Free tournament
|
|
53
|
+
|
|
54
|
+
Create a managed API key in the Console. Put the key in the `DATAFORTENNIS_API_KEY` environment variable via your application's secret configuration. Keep it on your server or local machine. Every Free account receives the same published tournament edition and release. A new key or account sees the same matches. [Data for Tennis Console](https://console.datafortennis.com)
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from datafortennis import DataForTennis
|
|
58
|
+
|
|
59
|
+
with DataForTennis() as tennis:
|
|
60
|
+
edition = tennis.free.tournament()
|
|
61
|
+
print(edition.data["name"], edition.data["season"], edition.data["census_matches"])
|
|
62
|
+
matches = tennis.free.matches(limit=10)
|
|
63
|
+
if matches.data:
|
|
64
|
+
match = matches.data[0]
|
|
65
|
+
points = tennis.free.points(match["id"], limit=20)
|
|
66
|
+
stats = tennis.free.stats(match["id"], limit=20)
|
|
67
|
+
print(match["id"], match["score"]["display"])
|
|
68
|
+
print("First page:", len(points.data), "points and", len(stats.data), "metrics")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Free lists accept `limit` and `cursor`. They default to 20 rows and accept up to 50. Cursors expire after one hour. All keys belonging to one account share a limit of 60 tournament requests per minute. The fixed-match route has its own limit.
|
|
72
|
+
|
|
73
|
+
The service chooses the edition. Details, points and statistics for a match outside it return `NotFoundError`. An eligible match with no observed points returns an empty page. `tennis.free.sample_match()` reads the compatible fixed-match endpoint. Its result also belongs to the current Free edition. A cached fixed-match response can omit `meta.onboarding`. Tournament endpoints include `meta.onboarding.edition_id` and `meta.onboarding.quota_units_milli`. Free reads consume zero paid allowance in both cases.
|
|
74
|
+
|
|
75
|
+
Run `python examples/free_tournament.py` for a JSON summary of the first match. Add `--match-id` to choose another match from the same edition. To use a development server, set `DATAFORTENNIS_BASE_URL` for that example or pass `base_url` to the client constructor. Only use a server you trust with your key.
|
|
76
|
+
|
|
77
|
+
## Read your own selection
|
|
78
|
+
|
|
79
|
+
Paid access depends on your current plan, scope and release. This example lists Challenger matches from a named release. To narrow the selection, pass a player ID from that release as the `player` filter.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from datafortennis import DataForTennis
|
|
83
|
+
|
|
84
|
+
with DataForTennis() as tennis:
|
|
85
|
+
release = "research-challenger-20261007-v1"
|
|
86
|
+
first = tennis.matches.list(release=release, category="Challenger", season=2025, limit=10)
|
|
87
|
+
for match in first.data:
|
|
88
|
+
print(match["id"], match["status"], match["score"]["display"])
|
|
89
|
+
print(first.meta)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`.data` contains the current page. Call `.next_page()` for one more request or use `.iter_rows()` to continue until the cursor ends. A short page may still have a continuation. Historical pagination preserves the selected release. Each additional page can consume allowance. Keep large counts, epochs and exact decimal metrics as strings until your application chooses the numeric representation. Preserve nulls, especially for observed timestamps and statistics with missing denominators.
|
|
93
|
+
|
|
94
|
+
| Resource | Common operations |
|
|
95
|
+
|---|---|
|
|
96
|
+
| `free`, `coverage`, `releases` | Read a Free match, inspect coverage, choose a release |
|
|
97
|
+
| `players`, `tournaments`, `editions`, `draws`, `datasets` | List and inspect catalogue entities |
|
|
98
|
+
| `matches` | Find matches, read points, statistics, coverage and available enrichment |
|
|
99
|
+
| `research` | Compare players, read metric definitions, resolve supported identities, batch points and read changes |
|
|
100
|
+
| `exports` | Preview a private export, create a job, follow its status and stream a file |
|
|
101
|
+
| `live`, `predictions` | Read live REST data, request a stream ticket and read available predictions |
|
|
102
|
+
|
|
103
|
+
Use the reference Live V2 client for a WebSocket subscription with replay and reconnect. [Data for Tennis live-client](https://github.com/DataForTennis/live-client)
|
|
104
|
+
|
|
105
|
+
## Handle errors and retries
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from datafortennis import APIError, DataForTennis, NotFoundError, QuotaExceededError
|
|
109
|
+
|
|
110
|
+
def inspect_match(tennis: DataForTennis, match_id: str) -> None:
|
|
111
|
+
try:
|
|
112
|
+
print(tennis.free.match(match_id).data["status"])
|
|
113
|
+
except NotFoundError:
|
|
114
|
+
print("Choose a match from tennis.free.matches().")
|
|
115
|
+
except QuotaExceededError:
|
|
116
|
+
print("Check the allowance for your active period.")
|
|
117
|
+
except APIError as error:
|
|
118
|
+
print(error.status_code, error.code, error.request_id)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Use `AuthenticationError` to diagnose a missing or invalid key, `AuthorizationError` for a scope or plan mismatch and `RateLimitError.retry_after` for a temporary limit. On `410 CURSOR_EXPIRED`, return to the first page of the named selection. A replay conflict across subscription periods requires a new logical request. Errors retain a request ID when the service provides one. Keep credentials and full payloads out of support messages.
|
|
122
|
+
|
|
123
|
+
A client owns a reusable HTTP connection pool. Set `timeout` or `max_retries` in the constructor and close the client when finished. Eligible public reads and supported idempotent GETs can retry transient failures. The same logical read retains its idempotency key across attempts. Creating an export takes an explicit `idempotency_key`. After a lost acknowledgement, reuse that key with the same request. The client leaves retrying a write or streaming download to the caller.
|
|
124
|
+
|
|
125
|
+
## Develop and verify the package
|
|
126
|
+
|
|
127
|
+
From the SDK checkout, install the development extras and run the test suite. For contract parity, pass the path to the authoritative backend OpenAPI file. The SDK preserves the public response types and the caller's entitlements. [API documentation](https://docs.datafortennis.com)
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
python -m pip install -e '.[dev]'
|
|
131
|
+
python -m pytest
|
|
132
|
+
python -m mypy --strict src/datafortennis
|
|
133
|
+
python -m ruff check src tests examples
|
|
134
|
+
python tests/check_contract.py /path/to/your/backend/contracts/openapi.yaml
|
|
135
|
+
python -m build
|
|
136
|
+
```
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Data for Tennis for Python
|
|
2
|
+
|
|
3
|
+
Read matches, point-by-point records and statistics through the Data for Tennis API. Each historical result carries the release that produced it. The client also supports exports, live REST reads and stream tickets.
|
|
4
|
+
|
|
5
|
+
The SDK targets REST contract 1.12.1, SHA-256 `5409bc1a61fbdfd465abe4a7cbcc4d88d7aa515d4c41dac0f64774185d2a736e`. It covers 51 customer operations. The two infrastructure health probes are available directly over HTTP. [Public API documentation](https://docs.datafortennis.com)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Use Python 3.10 or later. In your virtual environment, install the wheel for release `v0.1.0`.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
python -m pip install "https://github.com/DataForTennis/datafortennis-python/releases/download/v0.1.0/datafortennis-0.1.0-py3-none-any.whl"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Check coverage without an account
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from datafortennis import DataForTennis
|
|
19
|
+
|
|
20
|
+
with DataForTennis() as tennis:
|
|
21
|
+
result = tennis.coverage.summary(
|
|
22
|
+
release="research-challenger-20261007-v1",
|
|
23
|
+
category="Challenger",
|
|
24
|
+
season=2025,
|
|
25
|
+
)
|
|
26
|
+
pbp = next(row for row in result.data if row["family"] == "pbp")
|
|
27
|
+
print(pbp["available"], "of", pbp["census"], "matches have point data")
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The December 2, 2026 coverage summary for this named release reported 10,177 of 10,302 matches. All 10,177 were classified as partial. Coverage counts use decimal strings. The corresponding 2019 query reported zero matches with point data among 5,223 matches. [Coverage summary](https://api.datafortennis.com/v1/coverage/summary?release=research-challenger-20261007-v1&category=Challenger&season=2025)
|
|
31
|
+
|
|
32
|
+
## Read the Free tournament
|
|
33
|
+
|
|
34
|
+
Create a managed API key in the Console. Put the key in the `DATAFORTENNIS_API_KEY` environment variable via your application's secret configuration. Keep it on your server or local machine. Every Free account receives the same published tournament edition and release. A new key or account sees the same matches. [Data for Tennis Console](https://console.datafortennis.com)
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from datafortennis import DataForTennis
|
|
38
|
+
|
|
39
|
+
with DataForTennis() as tennis:
|
|
40
|
+
edition = tennis.free.tournament()
|
|
41
|
+
print(edition.data["name"], edition.data["season"], edition.data["census_matches"])
|
|
42
|
+
matches = tennis.free.matches(limit=10)
|
|
43
|
+
if matches.data:
|
|
44
|
+
match = matches.data[0]
|
|
45
|
+
points = tennis.free.points(match["id"], limit=20)
|
|
46
|
+
stats = tennis.free.stats(match["id"], limit=20)
|
|
47
|
+
print(match["id"], match["score"]["display"])
|
|
48
|
+
print("First page:", len(points.data), "points and", len(stats.data), "metrics")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Free lists accept `limit` and `cursor`. They default to 20 rows and accept up to 50. Cursors expire after one hour. All keys belonging to one account share a limit of 60 tournament requests per minute. The fixed-match route has its own limit.
|
|
52
|
+
|
|
53
|
+
The service chooses the edition. Details, points and statistics for a match outside it return `NotFoundError`. An eligible match with no observed points returns an empty page. `tennis.free.sample_match()` reads the compatible fixed-match endpoint. Its result also belongs to the current Free edition. A cached fixed-match response can omit `meta.onboarding`. Tournament endpoints include `meta.onboarding.edition_id` and `meta.onboarding.quota_units_milli`. Free reads consume zero paid allowance in both cases.
|
|
54
|
+
|
|
55
|
+
Run `python examples/free_tournament.py` for a JSON summary of the first match. Add `--match-id` to choose another match from the same edition. To use a development server, set `DATAFORTENNIS_BASE_URL` for that example or pass `base_url` to the client constructor. Only use a server you trust with your key.
|
|
56
|
+
|
|
57
|
+
## Read your own selection
|
|
58
|
+
|
|
59
|
+
Paid access depends on your current plan, scope and release. This example lists Challenger matches from a named release. To narrow the selection, pass a player ID from that release as the `player` filter.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from datafortennis import DataForTennis
|
|
63
|
+
|
|
64
|
+
with DataForTennis() as tennis:
|
|
65
|
+
release = "research-challenger-20261007-v1"
|
|
66
|
+
first = tennis.matches.list(release=release, category="Challenger", season=2025, limit=10)
|
|
67
|
+
for match in first.data:
|
|
68
|
+
print(match["id"], match["status"], match["score"]["display"])
|
|
69
|
+
print(first.meta)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`.data` contains the current page. Call `.next_page()` for one more request or use `.iter_rows()` to continue until the cursor ends. A short page may still have a continuation. Historical pagination preserves the selected release. Each additional page can consume allowance. Keep large counts, epochs and exact decimal metrics as strings until your application chooses the numeric representation. Preserve nulls, especially for observed timestamps and statistics with missing denominators.
|
|
73
|
+
|
|
74
|
+
| Resource | Common operations |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `free`, `coverage`, `releases` | Read a Free match, inspect coverage, choose a release |
|
|
77
|
+
| `players`, `tournaments`, `editions`, `draws`, `datasets` | List and inspect catalogue entities |
|
|
78
|
+
| `matches` | Find matches, read points, statistics, coverage and available enrichment |
|
|
79
|
+
| `research` | Compare players, read metric definitions, resolve supported identities, batch points and read changes |
|
|
80
|
+
| `exports` | Preview a private export, create a job, follow its status and stream a file |
|
|
81
|
+
| `live`, `predictions` | Read live REST data, request a stream ticket and read available predictions |
|
|
82
|
+
|
|
83
|
+
Use the reference Live V2 client for a WebSocket subscription with replay and reconnect. [Data for Tennis live-client](https://github.com/DataForTennis/live-client)
|
|
84
|
+
|
|
85
|
+
## Handle errors and retries
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from datafortennis import APIError, DataForTennis, NotFoundError, QuotaExceededError
|
|
89
|
+
|
|
90
|
+
def inspect_match(tennis: DataForTennis, match_id: str) -> None:
|
|
91
|
+
try:
|
|
92
|
+
print(tennis.free.match(match_id).data["status"])
|
|
93
|
+
except NotFoundError:
|
|
94
|
+
print("Choose a match from tennis.free.matches().")
|
|
95
|
+
except QuotaExceededError:
|
|
96
|
+
print("Check the allowance for your active period.")
|
|
97
|
+
except APIError as error:
|
|
98
|
+
print(error.status_code, error.code, error.request_id)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Use `AuthenticationError` to diagnose a missing or invalid key, `AuthorizationError` for a scope or plan mismatch and `RateLimitError.retry_after` for a temporary limit. On `410 CURSOR_EXPIRED`, return to the first page of the named selection. A replay conflict across subscription periods requires a new logical request. Errors retain a request ID when the service provides one. Keep credentials and full payloads out of support messages.
|
|
102
|
+
|
|
103
|
+
A client owns a reusable HTTP connection pool. Set `timeout` or `max_retries` in the constructor and close the client when finished. Eligible public reads and supported idempotent GETs can retry transient failures. The same logical read retains its idempotency key across attempts. Creating an export takes an explicit `idempotency_key`. After a lost acknowledgement, reuse that key with the same request. The client leaves retrying a write or streaming download to the caller.
|
|
104
|
+
|
|
105
|
+
## Develop and verify the package
|
|
106
|
+
|
|
107
|
+
From the SDK checkout, install the development extras and run the test suite. For contract parity, pass the path to the authoritative backend OpenAPI file. The SDK preserves the public response types and the caller's entitlements. [API documentation](https://docs.datafortennis.com)
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
python -m pip install -e '.[dev]'
|
|
111
|
+
python -m pytest
|
|
112
|
+
python -m mypy --strict src/datafortennis
|
|
113
|
+
python -m ruff check src tests examples
|
|
114
|
+
python tests/check_contract.py /path/to/your/backend/contracts/openapi.yaml
|
|
115
|
+
python -m build
|
|
116
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""List the Free edition and inspect one match with bounded reads."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from datafortennis import APIError, DataForTennis, DataForTennisError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main() -> int:
|
|
11
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
12
|
+
parser.add_argument("--match-id", help="A match ID returned by the Free edition")
|
|
13
|
+
args = parser.parse_args()
|
|
14
|
+
base_url = os.environ.get("DATAFORTENNIS_BASE_URL", "https://api.datafortennis.com")
|
|
15
|
+
try:
|
|
16
|
+
with DataForTennis(base_url=base_url) as tennis:
|
|
17
|
+
scope = tennis.free.tournament()
|
|
18
|
+
first = tennis.free.matches(limit=10)
|
|
19
|
+
output: dict[str, object] = {
|
|
20
|
+
"edition": scope.data,
|
|
21
|
+
"release": (scope.meta or {}).get("release_id"),
|
|
22
|
+
"first_page_match_ids": [row["id"] for row in first.data],
|
|
23
|
+
"more_matches": first.page is not None and first.page.next_cursor is not None,
|
|
24
|
+
}
|
|
25
|
+
match_id = args.match_id or (first.data[0]["id"] if first.data else None)
|
|
26
|
+
if match_id is not None:
|
|
27
|
+
match = tennis.free.match(match_id).data
|
|
28
|
+
points = tennis.free.points(match_id, limit=20)
|
|
29
|
+
stats = tennis.free.stats(match_id, limit=20)
|
|
30
|
+
output["match"] = {
|
|
31
|
+
"id": match["id"],
|
|
32
|
+
"score": match["score"]["display"],
|
|
33
|
+
"status": match["status"],
|
|
34
|
+
"first_page_points": len(points.data),
|
|
35
|
+
"first_page_metrics": len(stats.data),
|
|
36
|
+
"more_points": points.page is not None and points.page.next_cursor is not None,
|
|
37
|
+
}
|
|
38
|
+
print(json.dumps(output, indent=2, ensure_ascii=False))
|
|
39
|
+
return 0
|
|
40
|
+
except APIError as error:
|
|
41
|
+
parser.exit(1, f"{error}. Check the Free edition and your managed key.\n")
|
|
42
|
+
except (DataForTennisError, ValueError) as error:
|
|
43
|
+
parser.exit(1, f"{error}\n")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.26,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "datafortennis"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
authors = [{name = "Data for Tennis"}]
|
|
9
|
+
description = "Typed synchronous client for the Data for Tennis API"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = ["httpx>=0.28.1,<0.29"]
|
|
13
|
+
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
"Typing :: Typed",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://datafortennis.com"
|
|
21
|
+
Documentation = "https://docs.datafortennis.com"
|
|
22
|
+
Source = "https://github.com/DataForTennis/datafortennis-python"
|
|
23
|
+
Releases = "https://github.com/DataForTennis/datafortennis-python/releases"
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = ["pytest>=8.3,<10", "mypy>=1.13,<2", "ruff>=0.9,<1", "build>=1.2,<2"]
|
|
27
|
+
|
|
28
|
+
[tool.hatch.version]
|
|
29
|
+
path = "src/datafortennis/_version.py"
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build.targets.wheel]
|
|
32
|
+
packages = ["src/datafortennis"]
|
|
33
|
+
|
|
34
|
+
[tool.pytest.ini_options]
|
|
35
|
+
testpaths = ["tests"]
|
|
36
|
+
pythonpath = ["src"]
|
|
37
|
+
|
|
38
|
+
[tool.mypy]
|
|
39
|
+
python_version = "3.10"
|
|
40
|
+
check_untyped_defs = true
|
|
41
|
+
|
|
42
|
+
[tool.ruff]
|
|
43
|
+
target-version = "py310"
|
|
44
|
+
line-length = 100
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Python client for DataForTennis."""
|
|
2
|
+
|
|
3
|
+
from ._types import Page, Response
|
|
4
|
+
from ._version import __version__
|
|
5
|
+
from .client import DataForTennis
|
|
6
|
+
from .errors import (
|
|
7
|
+
AmbiguousIdentityError,
|
|
8
|
+
APIError,
|
|
9
|
+
AuthenticationError,
|
|
10
|
+
AuthorizationError,
|
|
11
|
+
ConflictError,
|
|
12
|
+
DataForTennisError,
|
|
13
|
+
IdentityCandidate,
|
|
14
|
+
NotFoundError,
|
|
15
|
+
ProtocolError,
|
|
16
|
+
QuotaExceededError,
|
|
17
|
+
RateLimitError,
|
|
18
|
+
ServerError,
|
|
19
|
+
TransportError,
|
|
20
|
+
)
|
|
21
|
+
from .resources._base import Collection
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"APIError",
|
|
25
|
+
"AmbiguousIdentityError",
|
|
26
|
+
"AuthenticationError",
|
|
27
|
+
"AuthorizationError",
|
|
28
|
+
"Collection",
|
|
29
|
+
"ConflictError",
|
|
30
|
+
"DataForTennis",
|
|
31
|
+
"DataForTennisError",
|
|
32
|
+
"IdentityCandidate",
|
|
33
|
+
"NotFoundError",
|
|
34
|
+
"Page",
|
|
35
|
+
"ProtocolError",
|
|
36
|
+
"QuotaExceededError",
|
|
37
|
+
"RateLimitError",
|
|
38
|
+
"Response",
|
|
39
|
+
"ServerError",
|
|
40
|
+
"TransportError",
|
|
41
|
+
"__version__",
|
|
42
|
+
]
|