streamcom-scoreboard-client 2.0.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,43 @@
1
+ node_modules/
2
+ dist/
3
+ .next/
4
+ next-env.d.ts
5
+ .turbo/
6
+ coverage/
7
+ *.tsbuildinfo
8
+ .env
9
+ .env.local
10
+ .env.*.local
11
+ tools/seed/world.yaml
12
+ azurite-data/
13
+ .DS_Store
14
+ Thumbs.db
15
+ graphify-out/
16
+
17
+ # The browser suite's scratch (T92): the world it built, the account it made, and what a
18
+ # failing run left behind. The first two hold a live invitation token and freshly minted keys.
19
+ # Its portal build is `.next/e2e`, already covered above.
20
+ apps/portal/e2e/world.json
21
+ apps/portal/e2e/account.json
22
+ apps/portal/e2e/.report/
23
+ apps/portal/e2e/.results/
24
+ apps/portal/e2e/.logs/
25
+ apps/portal/e2e/.auth/
26
+
27
+ # MaxMind's GeoLite2 database: 60 MB, not redistributable, and fetched with
28
+ # `node scripts/fetch-geolite2.mjs` (infra/README.md §GeoLite2).
29
+ infra/geolite2/
30
+ *.mmdb
31
+
32
+ # A packed scoreboard-client (`pnpm pack:client`, to try a build). A build artifact, never a commit.
33
+ *.tgz
34
+
35
+ # Maven's build output for the Java SDK (sdks/java/).
36
+ sdks/java/*/target/
37
+
38
+ # The Python SDK's environment and caches (sdks/python/).
39
+ .venv/
40
+ __pycache__/
41
+ .pytest_cache/
42
+ .mypy_cache/
43
+ *.egg-info/
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ What changed in each version of `streamcom-scoreboard-client`, the Python SDK for StreamCom's
4
+ public API v2. It is the Python twin of the npm package `@streamcom/scoreboard-client` and the
5
+ Java SDK `eu.streamcom:scoreboard-client`.
6
+
7
+ Semver, written the Python way (a preview would be `2.0.0b1` for `2.0.0-beta.1`). Additions to API
8
+ v2 are additive: a new field or enum value is a minor release. A rename, a removal, a narrowed type
9
+ or a changed default is a major one.
10
+
11
+ ## 2.0.0 — 2026-12-02
12
+
13
+ The first version, with public API v2 stable: all of it, as the npm package and the Java SDK have
14
+ it.
15
+
16
+ - `StreamcomClient(token, url=…, timeout=…)` with `matches`, `competitions`, `clubs` and `courts`.
17
+ - `matches.all` walks every page; `matches.sync` keeps a set of matches up to date, as the Java
18
+ SDK's does. `clubs.logo` fetches a crest, with the key only for the API's own address.
19
+ - A request that got no answer, a 5xx or a 429 is tried again: `retries`, `retry_backoff`,
20
+ `max_retry_wait` (a 429 waits for its `Retry-After`). Your own `ssl_context`.
21
+ - `client.stream(...)`: the live stream, `/api/v2/stream`. Handlers (`on_live`, `on_board`, …) or
22
+ `for event in stream.events()`; reconnects and resubscribes on a configurable `backoff`,
23
+ respects `Retry-After`, redials after `silence`; `subscribe`/`unsubscribe` while it runs; reads
24
+ `board`, `board_of`, `match`, `matches`, `match_on`, `courts`, `connection_id`, `limits`. Held to
25
+ the shared cases in `sdks/cases/stream.json`.
26
+ - `stream.align_to(picture_time)`: the board, its clocks and the events in step with a delayed
27
+ video. The delay is worked out from the UTC moment of the picture on screen, and follows it as
28
+ the player reports new times. Held to the shared cases in `sdks/cases/delay.json`.
29
+ - `AsyncStreamcomClient` and `stream.aevents()` for asyncio.
30
+ - `Clock.read` resolves a clock anchor the way the platform does, held to the shared cases in
31
+ `sdks/cases/clock.json`.
32
+ - `ApiError` and `StreamError` with a stable `code`, held to `sdks/cases/api-errors.json`.
33
+ - Logs to the `streamcom_scoreboard` logger: retries at INFO, frames at DEBUG.
34
+ - Answers are the API's JSON, typed with `TypedDict`s that the tests hold to the v2 OpenAPI
35
+ document.
36
+ - Python 3.11 or newer; one dependency, `websockets` 17.4 or newer.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 StreamCom
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.
@@ -0,0 +1,237 @@
1
+ Metadata-Version: 2.5
2
+ Name: streamcom-scoreboard-client
3
+ Version: 2.0.0
4
+ Summary: Live data from Streamcom: matches, competitions and scoreboards on public API v2, with clocks resolved for you.
5
+ Author-email: StreamCom <support@streamcom.eu>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: broadcast,livescore,overlay,scoreboard,streamcom
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.11
14
+ Requires-Dist: websockets>=17.4
15
+ Provides-Extra: test
16
+ Requires-Dist: mypy>=2.4.1; extra == 'test'
17
+ Requires-Dist: pytest>=9.2; extra == 'test'
18
+ Requires-Dist: pyyaml>=6.0.4; extra == 'test'
19
+ Description-Content-Type: text/markdown
20
+
21
+ # streamcom-scoreboard-client
22
+
23
+ Live data from Streamcom for Python: matches, competitions, clubs and courts on public API v2,
24
+ with clocks resolved for you. The Python twin of the npm package `@streamcom/scoreboard-client`
25
+ and the Java SDK `eu.streamcom:scoreboard-client`.
26
+
27
+ Python 3.11 or newer. One dependency: `websockets` 17.4 or newer, for the live stream.
28
+
29
+ ```sh
30
+ pip install streamcom-scoreboard-client
31
+ ```
32
+
33
+ ## A first call
34
+
35
+ Make an API key on the portal's **Data feed** page.
36
+
37
+ ```python
38
+ import os
39
+ from streamcom_scoreboard import StreamcomClient
40
+
41
+ streamcom = StreamcomClient(os.environ["STREAMCOM_TOKEN"])
42
+
43
+ for match in streamcom.matches.all(competition="cp7k2pq9x"):
44
+ print(match["home"]["name"], "–", match["away"]["name"], match["status"])
45
+ ```
46
+
47
+ The key goes in an `Authorization` header and never in a URL, and the client follows no redirect.
48
+ Every call blocks until it answers (or use [`AsyncStreamcomClient`](#asyncio)). A client is safe
49
+ to share between threads: make one per key and keep it.
50
+
51
+ | Option | Default | What it does |
52
+ | --- | --- | --- |
53
+ | `url` | production | another API address; `wss://` is read as `https://` |
54
+ | `timeout` | `30.0` | seconds one request may wait on the network |
55
+ | `retries` | `2` | how often no answer, a 5xx or a 429 is tried again; `0` never |
56
+ | `retry_backoff` | `Backoff(min=0.5, max=8.0)` | the wait between tries, doubling, jittered a fifth either way |
57
+ | `max_retry_wait` | `60.0` | a 429 waits for its `Retry-After`, unless that is longer than this: then it raises at once |
58
+ | `ssl_context` | system | your own TLS settings, for REST and the stream |
59
+
60
+ A 4xx other than 429 is never tried again. The client logs to the `streamcom_scoreboard` logger:
61
+ each retry at INFO, the stream's frames at DEBUG.
62
+
63
+ ## What it reads
64
+
65
+ | Call | Route |
66
+ | --- | --- |
67
+ | `matches.list(**filters, cursor=None)` | one page of `GET /api/v2/matches` |
68
+ | `matches.all(**filters)` | every match, page after page as you iterate |
69
+ | `matches.get(id)` | one match |
70
+ | `matches.timeline(id, cursor=None, limit=None)` / `matches.events(id)` | what the board did |
71
+ | `matches.sync(since=None, **filters)` | keep a set of matches up to date |
72
+ | `competitions.list(season=…, series=…, federation=…, updated_since=…)` | the competitions this key reaches |
73
+ | `competitions.get(id)` | one competition with its teams and coverage |
74
+ | `clubs.get(id)` | a club's face and teams |
75
+ | `clubs.logo(logo_url)` | the crest as bytes; the key goes along only to the API's own address |
76
+ | `courts.list()` | the courts this key reads |
77
+ | `courts.get(id)` | one court's whole board now |
78
+
79
+ Match filters: `competition`, `series`, `club`, `team`, `court`, `venue`, `status` (one or a
80
+ list), `from_`, `to`, `updated_since` (timezone-aware `datetime`s) and `limit` (1 to 200). With
81
+ no filter the API answers twelve hours either side of now; with a competition, its whole season.
82
+
83
+ Answers are the API's JSON as dictionaries, typed with `TypedDict`s in `streamcom_scoreboard.types`:
84
+ snake_case keys and ISO-8601 strings for times, which `parse_time` turns into a `datetime`. API v2
85
+ only adds, so a field this version does not know is still in the dictionary.
86
+
87
+ ## Keeping matches up to date
88
+
89
+ ```python
90
+ sync = streamcom.matches.sync(competition="cp7k2pq9x")
91
+ store(sync.matches, sync.since)
92
+
93
+ # later, every few minutes, with the `since` you stored:
94
+ sync = streamcom.matches.sync(sync.since, competition="cp7k2pq9x")
95
+ ```
96
+
97
+ Replace what you hold by `id`; a match may come twice. Store `sync.since` with the matches.
98
+
99
+ ## Clocks
100
+
101
+ A clock arrives as an anchor: `remaining_ms` was true at `as_of`. Read it, never tick it yourself:
102
+
103
+ ```python
104
+ from datetime import datetime, timezone
105
+ from streamcom_scoreboard import Clock
106
+
107
+ clock = Clock.from_wire(board["clock"])
108
+ reading = clock.read(datetime.now(timezone.utc), status="online")
109
+ print(reading.text) # "9:55"
110
+ reading.ticking # drive a render loop from this, never from clock.running
111
+ ```
112
+
113
+ A `streamed` clock is shown as received, and a clock on a source that is not online stands still.
114
+
115
+ ## Errors
116
+
117
+ A refusal raises `ApiError`, with a stable `code` apart from the message for a human:
118
+
119
+ ```python
120
+ from streamcom_scoreboard import ApiError, ApiErrorCode
121
+
122
+ try:
123
+ match = streamcom.matches.get(match_id)
124
+ except ApiError as e:
125
+ if e.code == ApiErrorCode.NOT_FOUND: # or e.code == "not_found"
126
+ ...
127
+ if e.code == ApiErrorCode.RATE_LIMITED:
128
+ wait_ms = e.retry_after_ms
129
+ ```
130
+
131
+ | `code` | When |
132
+ | --- | --- |
133
+ | `unauthorized` | no key, or one unknown, revoked or expired (401) |
134
+ | `not_found` | it does not exist **or is out of this key's reach** (404; there is no 403) |
135
+ | `invalid_request` | a filter, cursor or limit is wrong (400, 422) |
136
+ | `rate_limited` | 60 requests a minute per key, v1 and v2 together (429) |
137
+ | `internal_error` | on Streamcom's side; retry with backoff (5xx) |
138
+ | `network` | no answer at all, or one that was not the API's |
139
+
140
+ ## The live stream
141
+
142
+ One WebSocket follows any number of courts, matches and competitions, and holds what it heard:
143
+
144
+ ```python
145
+ stream = streamcom.stream(competitions=["cp7k2pq9x"], courts=["ct9w3d5ke"])
146
+
147
+ @stream.on_live
148
+ def cue(match):
149
+ print(match["home"]["name"], "–", match["away"]["name"], "is live")
150
+
151
+ @stream.on_board
152
+ def draw(court_id, fields, change):
153
+ print(court_id, fields.home.score, "–", fields.away.score, fields.clock.text)
154
+
155
+ with stream: # opens; closes on leaving the block
156
+ stream.wait() # or stream.run_forever(), which also stops on Ctrl+C
157
+ ```
158
+
159
+ Or iterate instead of handlers; both see every event, in order:
160
+
161
+ ```python
162
+ with streamcom.stream(courts=["ct9w3d5ke"]) as stream:
163
+ for event in stream.events():
164
+ if event.type == "board":
165
+ render(event.fields)
166
+ ```
167
+
168
+ | Event | Handler arguments | When |
169
+ | --- | --- | --- |
170
+ | `match` | `match, previous` | a match arrived or changed; `previous` is `None` the first time |
171
+ | `status` | `match, previous_status` | a held match changed status |
172
+ | `live` / `ended` | `match` | a held match turned live or ended: moments this stream saw |
173
+ | `gone` | `kind, id` | something followed left this key's reach; the rest keeps streaming |
174
+ | `board` | `court_id, fields, change` | a court's board moved |
175
+ | `connection` | `connected, reason` | up, or down with why; down is not fatal |
176
+ | `error` | `error` | a `StreamError` to act on: a refused key, a rate limit, an id this key cannot read |
177
+
178
+ Reads, safe from any thread: `stream.board(court_id)` (every clock resolved to now; call it from
179
+ a render loop to animate), `board_of(match_id)`, `match(id)`, `matches`, `match_on(court_id)`,
180
+ `courts`, `connected`, `connection_id`, `limits`. `subscribe(...)` and `unsubscribe(...)` change
181
+ what is followed while it runs.
182
+
183
+ A board field can be **absent** (this board does not have it: `ABSENT`, which is falsy),
184
+ **`None`** (it has it but did not say) or a value. Draw them differently.
185
+
186
+ The stream reconnects by itself and subscribes everything again: on `backoff` (1 to 30 s,
187
+ jittered), after a refusal's `Retry-After`, and when nothing was heard for `silence` seconds
188
+ (35). All three are options of `streamcom.stream(...)`, with `open_timeout` for one dial.
189
+ Handlers run on the stream's own events thread, one at a time; one that raises is logged and the
190
+ rest still run. With no `error` handler and no iterator, an error is logged as a warning.
191
+
192
+ ### In step with a video
193
+
194
+ A broadcast runs behind the hall, so a board drawn live over it shows a goal before the picture
195
+ does. Give the stream the UTC moment of the picture on screen and it works out the delay itself:
196
+
197
+ ```python
198
+ stream = streamcom.stream(courts=["ct9w3d5ke"])
199
+ stream.align_to(player.program_date_time) # e.g. the HLS EXT-X-PROGRAM-DATE-TIME of the frame shown
200
+ stream.open()
201
+
202
+ # whenever the player reports a time, every segment or every frame:
203
+ stream.align_to(player.program_date_time) # returns the delay; also in stream.delay
204
+ ```
205
+
206
+ From then on `board()`, its clocks and every match and board event are what the video shows:
207
+ each message waits until the picture reaches the moment it arrived. Call `align_to` again
208
+ whenever the player reports a time and the delay follows the drift. A delay that grows holds the
209
+ view still until the video catches up; one that shrinks jumps it forward. The connection, the
210
+ `connection` and `error` events and `subscribe` stay live.
211
+
212
+ The moment is a timezone-aware `datetime` or an ISO-8601 string with its offset. One more than
213
+ `max_delay` (300 s, an option of `stream(...)`) back raises `ValueError`: usually a local time
214
+ passed as UTC. Before the first `align_to` the view is live, so call it before `open()` when the
215
+ delay is known by then.
216
+
217
+ ## asyncio
218
+
219
+ ```python
220
+ from streamcom_scoreboard import AsyncStreamcomClient
221
+
222
+ streamcom = AsyncStreamcomClient(os.environ["STREAMCOM_TOKEN"]) # the same options
223
+ match = await streamcom.matches.get("mt4n8w2qa")
224
+ async for match in streamcom.matches.all(competition="cp7k2pq9x"):
225
+ ...
226
+
227
+ with streamcom.stream(courts=["ct9w3d5ke"]) as stream:
228
+ async for event in stream.aevents():
229
+ ...
230
+ ```
231
+
232
+ Each request runs on a worker thread, so the event loop never blocks; the retries and errors are
233
+ the blocking client's.
234
+
235
+ ## Licence
236
+
237
+ MIT
@@ -0,0 +1,217 @@
1
+ # streamcom-scoreboard-client
2
+
3
+ Live data from Streamcom for Python: matches, competitions, clubs and courts on public API v2,
4
+ with clocks resolved for you. The Python twin of the npm package `@streamcom/scoreboard-client`
5
+ and the Java SDK `eu.streamcom:scoreboard-client`.
6
+
7
+ Python 3.11 or newer. One dependency: `websockets` 17.4 or newer, for the live stream.
8
+
9
+ ```sh
10
+ pip install streamcom-scoreboard-client
11
+ ```
12
+
13
+ ## A first call
14
+
15
+ Make an API key on the portal's **Data feed** page.
16
+
17
+ ```python
18
+ import os
19
+ from streamcom_scoreboard import StreamcomClient
20
+
21
+ streamcom = StreamcomClient(os.environ["STREAMCOM_TOKEN"])
22
+
23
+ for match in streamcom.matches.all(competition="cp7k2pq9x"):
24
+ print(match["home"]["name"], "–", match["away"]["name"], match["status"])
25
+ ```
26
+
27
+ The key goes in an `Authorization` header and never in a URL, and the client follows no redirect.
28
+ Every call blocks until it answers (or use [`AsyncStreamcomClient`](#asyncio)). A client is safe
29
+ to share between threads: make one per key and keep it.
30
+
31
+ | Option | Default | What it does |
32
+ | --- | --- | --- |
33
+ | `url` | production | another API address; `wss://` is read as `https://` |
34
+ | `timeout` | `30.0` | seconds one request may wait on the network |
35
+ | `retries` | `2` | how often no answer, a 5xx or a 429 is tried again; `0` never |
36
+ | `retry_backoff` | `Backoff(min=0.5, max=8.0)` | the wait between tries, doubling, jittered a fifth either way |
37
+ | `max_retry_wait` | `60.0` | a 429 waits for its `Retry-After`, unless that is longer than this: then it raises at once |
38
+ | `ssl_context` | system | your own TLS settings, for REST and the stream |
39
+
40
+ A 4xx other than 429 is never tried again. The client logs to the `streamcom_scoreboard` logger:
41
+ each retry at INFO, the stream's frames at DEBUG.
42
+
43
+ ## What it reads
44
+
45
+ | Call | Route |
46
+ | --- | --- |
47
+ | `matches.list(**filters, cursor=None)` | one page of `GET /api/v2/matches` |
48
+ | `matches.all(**filters)` | every match, page after page as you iterate |
49
+ | `matches.get(id)` | one match |
50
+ | `matches.timeline(id, cursor=None, limit=None)` / `matches.events(id)` | what the board did |
51
+ | `matches.sync(since=None, **filters)` | keep a set of matches up to date |
52
+ | `competitions.list(season=…, series=…, federation=…, updated_since=…)` | the competitions this key reaches |
53
+ | `competitions.get(id)` | one competition with its teams and coverage |
54
+ | `clubs.get(id)` | a club's face and teams |
55
+ | `clubs.logo(logo_url)` | the crest as bytes; the key goes along only to the API's own address |
56
+ | `courts.list()` | the courts this key reads |
57
+ | `courts.get(id)` | one court's whole board now |
58
+
59
+ Match filters: `competition`, `series`, `club`, `team`, `court`, `venue`, `status` (one or a
60
+ list), `from_`, `to`, `updated_since` (timezone-aware `datetime`s) and `limit` (1 to 200). With
61
+ no filter the API answers twelve hours either side of now; with a competition, its whole season.
62
+
63
+ Answers are the API's JSON as dictionaries, typed with `TypedDict`s in `streamcom_scoreboard.types`:
64
+ snake_case keys and ISO-8601 strings for times, which `parse_time` turns into a `datetime`. API v2
65
+ only adds, so a field this version does not know is still in the dictionary.
66
+
67
+ ## Keeping matches up to date
68
+
69
+ ```python
70
+ sync = streamcom.matches.sync(competition="cp7k2pq9x")
71
+ store(sync.matches, sync.since)
72
+
73
+ # later, every few minutes, with the `since` you stored:
74
+ sync = streamcom.matches.sync(sync.since, competition="cp7k2pq9x")
75
+ ```
76
+
77
+ Replace what you hold by `id`; a match may come twice. Store `sync.since` with the matches.
78
+
79
+ ## Clocks
80
+
81
+ A clock arrives as an anchor: `remaining_ms` was true at `as_of`. Read it, never tick it yourself:
82
+
83
+ ```python
84
+ from datetime import datetime, timezone
85
+ from streamcom_scoreboard import Clock
86
+
87
+ clock = Clock.from_wire(board["clock"])
88
+ reading = clock.read(datetime.now(timezone.utc), status="online")
89
+ print(reading.text) # "9:55"
90
+ reading.ticking # drive a render loop from this, never from clock.running
91
+ ```
92
+
93
+ A `streamed` clock is shown as received, and a clock on a source that is not online stands still.
94
+
95
+ ## Errors
96
+
97
+ A refusal raises `ApiError`, with a stable `code` apart from the message for a human:
98
+
99
+ ```python
100
+ from streamcom_scoreboard import ApiError, ApiErrorCode
101
+
102
+ try:
103
+ match = streamcom.matches.get(match_id)
104
+ except ApiError as e:
105
+ if e.code == ApiErrorCode.NOT_FOUND: # or e.code == "not_found"
106
+ ...
107
+ if e.code == ApiErrorCode.RATE_LIMITED:
108
+ wait_ms = e.retry_after_ms
109
+ ```
110
+
111
+ | `code` | When |
112
+ | --- | --- |
113
+ | `unauthorized` | no key, or one unknown, revoked or expired (401) |
114
+ | `not_found` | it does not exist **or is out of this key's reach** (404; there is no 403) |
115
+ | `invalid_request` | a filter, cursor or limit is wrong (400, 422) |
116
+ | `rate_limited` | 60 requests a minute per key, v1 and v2 together (429) |
117
+ | `internal_error` | on Streamcom's side; retry with backoff (5xx) |
118
+ | `network` | no answer at all, or one that was not the API's |
119
+
120
+ ## The live stream
121
+
122
+ One WebSocket follows any number of courts, matches and competitions, and holds what it heard:
123
+
124
+ ```python
125
+ stream = streamcom.stream(competitions=["cp7k2pq9x"], courts=["ct9w3d5ke"])
126
+
127
+ @stream.on_live
128
+ def cue(match):
129
+ print(match["home"]["name"], "–", match["away"]["name"], "is live")
130
+
131
+ @stream.on_board
132
+ def draw(court_id, fields, change):
133
+ print(court_id, fields.home.score, "–", fields.away.score, fields.clock.text)
134
+
135
+ with stream: # opens; closes on leaving the block
136
+ stream.wait() # or stream.run_forever(), which also stops on Ctrl+C
137
+ ```
138
+
139
+ Or iterate instead of handlers; both see every event, in order:
140
+
141
+ ```python
142
+ with streamcom.stream(courts=["ct9w3d5ke"]) as stream:
143
+ for event in stream.events():
144
+ if event.type == "board":
145
+ render(event.fields)
146
+ ```
147
+
148
+ | Event | Handler arguments | When |
149
+ | --- | --- | --- |
150
+ | `match` | `match, previous` | a match arrived or changed; `previous` is `None` the first time |
151
+ | `status` | `match, previous_status` | a held match changed status |
152
+ | `live` / `ended` | `match` | a held match turned live or ended: moments this stream saw |
153
+ | `gone` | `kind, id` | something followed left this key's reach; the rest keeps streaming |
154
+ | `board` | `court_id, fields, change` | a court's board moved |
155
+ | `connection` | `connected, reason` | up, or down with why; down is not fatal |
156
+ | `error` | `error` | a `StreamError` to act on: a refused key, a rate limit, an id this key cannot read |
157
+
158
+ Reads, safe from any thread: `stream.board(court_id)` (every clock resolved to now; call it from
159
+ a render loop to animate), `board_of(match_id)`, `match(id)`, `matches`, `match_on(court_id)`,
160
+ `courts`, `connected`, `connection_id`, `limits`. `subscribe(...)` and `unsubscribe(...)` change
161
+ what is followed while it runs.
162
+
163
+ A board field can be **absent** (this board does not have it: `ABSENT`, which is falsy),
164
+ **`None`** (it has it but did not say) or a value. Draw them differently.
165
+
166
+ The stream reconnects by itself and subscribes everything again: on `backoff` (1 to 30 s,
167
+ jittered), after a refusal's `Retry-After`, and when nothing was heard for `silence` seconds
168
+ (35). All three are options of `streamcom.stream(...)`, with `open_timeout` for one dial.
169
+ Handlers run on the stream's own events thread, one at a time; one that raises is logged and the
170
+ rest still run. With no `error` handler and no iterator, an error is logged as a warning.
171
+
172
+ ### In step with a video
173
+
174
+ A broadcast runs behind the hall, so a board drawn live over it shows a goal before the picture
175
+ does. Give the stream the UTC moment of the picture on screen and it works out the delay itself:
176
+
177
+ ```python
178
+ stream = streamcom.stream(courts=["ct9w3d5ke"])
179
+ stream.align_to(player.program_date_time) # e.g. the HLS EXT-X-PROGRAM-DATE-TIME of the frame shown
180
+ stream.open()
181
+
182
+ # whenever the player reports a time, every segment or every frame:
183
+ stream.align_to(player.program_date_time) # returns the delay; also in stream.delay
184
+ ```
185
+
186
+ From then on `board()`, its clocks and every match and board event are what the video shows:
187
+ each message waits until the picture reaches the moment it arrived. Call `align_to` again
188
+ whenever the player reports a time and the delay follows the drift. A delay that grows holds the
189
+ view still until the video catches up; one that shrinks jumps it forward. The connection, the
190
+ `connection` and `error` events and `subscribe` stay live.
191
+
192
+ The moment is a timezone-aware `datetime` or an ISO-8601 string with its offset. One more than
193
+ `max_delay` (300 s, an option of `stream(...)`) back raises `ValueError`: usually a local time
194
+ passed as UTC. Before the first `align_to` the view is live, so call it before `open()` when the
195
+ delay is known by then.
196
+
197
+ ## asyncio
198
+
199
+ ```python
200
+ from streamcom_scoreboard import AsyncStreamcomClient
201
+
202
+ streamcom = AsyncStreamcomClient(os.environ["STREAMCOM_TOKEN"]) # the same options
203
+ match = await streamcom.matches.get("mt4n8w2qa")
204
+ async for match in streamcom.matches.all(competition="cp7k2pq9x"):
205
+ ...
206
+
207
+ with streamcom.stream(courts=["ct9w3d5ke"]) as stream:
208
+ async for event in stream.aevents():
209
+ ...
210
+ ```
211
+
212
+ Each request runs on a worker thread, so the event loop never blocks; the retries and errors are
213
+ the blocking client's.
214
+
215
+ ## Licence
216
+
217
+ MIT
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.33"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "streamcom-scoreboard-client"
7
+ dynamic = ["version"]
8
+ description = "Live data from Streamcom: matches, competitions and scoreboards on public API v2, with clocks resolved for you."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "StreamCom", email = "support@streamcom.eu" }]
13
+ requires-python = ">=3.11"
14
+ dependencies = ["websockets>=17.4"]
15
+ keywords = ["scoreboard", "livescore", "streamcom", "broadcast", "overlay"]
16
+ classifiers = [
17
+ "Development Status :: 5 - Production/Stable",
18
+ "Intended Audience :: Developers",
19
+ "Programming Language :: Python :: 3",
20
+ "Typing :: Typed",
21
+ ]
22
+
23
+ [project.optional-dependencies]
24
+ test = ["pytest>=9.2", "pyyaml>=6.0.4", "mypy>=2.4.1"]
25
+
26
+ [tool.hatch.version]
27
+ path = "src/streamcom_scoreboard/_version.py"
28
+
29
+ [tool.hatch.build.targets.wheel]
30
+ packages = ["src/streamcom_scoreboard"]
31
+
32
+ [tool.hatch.build.targets.sdist]
33
+ include = ["src/streamcom_scoreboard", "README.md", "CHANGELOG.md", "LICENSE"]
34
+
35
+ [tool.pytest.ini_options]
36
+ testpaths = ["tests"]
37
+
38
+ [tool.mypy]
39
+ strict = true
40
+ files = ["src"]
@@ -0,0 +1,57 @@
1
+ """Live data from Streamcom: matches, competitions, clubs and courts on public API v2, with
2
+ clocks resolved for you, and the live stream that follows them."""
3
+
4
+ from ._core import Follow
5
+ from ._time import format_time, parse_time
6
+ from ._version import __version__
7
+ from .aio import AsyncStreamcomClient
8
+ from .backoff import Backoff
9
+ from .board import ABSENT, CourtChange, CourtFields, Declarable, Exclusion, Period, TeamFields
10
+ from .client import (
11
+ DEFAULT_API_URL,
12
+ ClubsApi,
13
+ CompetitionsApi,
14
+ CourtsApi,
15
+ MatchesApi,
16
+ MatchSync,
17
+ StreamcomClient,
18
+ )
19
+ from .clock import Clock, ClockReading, format_clock_text
20
+ from .errors import ApiError, ApiErrorCode
21
+ from .stream import MAX_DELAY, SILENCE, EventType, LiveStream, StreamEvent
22
+ from .stream_errors import StreamError, StreamErrorCode
23
+
24
+ __all__ = [
25
+ "ABSENT",
26
+ "DEFAULT_API_URL",
27
+ "MAX_DELAY",
28
+ "SILENCE",
29
+ "ApiError",
30
+ "ApiErrorCode",
31
+ "AsyncStreamcomClient",
32
+ "Backoff",
33
+ "Clock",
34
+ "ClockReading",
35
+ "ClubsApi",
36
+ "CompetitionsApi",
37
+ "CourtChange",
38
+ "CourtFields",
39
+ "CourtsApi",
40
+ "Declarable",
41
+ "EventType",
42
+ "Exclusion",
43
+ "Follow",
44
+ "LiveStream",
45
+ "MatchSync",
46
+ "MatchesApi",
47
+ "Period",
48
+ "StreamError",
49
+ "StreamErrorCode",
50
+ "StreamEvent",
51
+ "StreamcomClient",
52
+ "TeamFields",
53
+ "__version__",
54
+ "format_clock_text",
55
+ "format_time",
56
+ "parse_time",
57
+ ]