Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Betwatch Python SDK

PyPI - Version PyPI - Python Version

Live Australian and New Zealand racing odds in Python: every race, every runner, and the current price from every bookmaker, tote and exchange Betwatch tracks, with a stream of changes as they happen.

from betwatch import Betwatch

with Betwatch() as client:
    race = client.events.list(sport="thoroughbred", country="au", status="open").next_open
    card = client.events.snapshot(race.id)
    for runner in card.entrants:
        print(runner.number, runner.name, card.best_price(runner))

Beta. 2.x targets the Betwatch Racing API /v2 and is in public beta. Pin the exact version; minor details may change before 2.0.0. The 1.x GraphQL client (get_races) is a different API and is not compatible.

Install

pip install --pre betwatch

--pre selects the 2.x beta. Pin the version you tested against, for example betwatch==2.0.0b5.

Python 3.11+. The only dependencies are httpx and msgspec. pip install "betwatch[pandas]" adds pandas for to_records() users.

Authenticate

Create a key at Account → API. The key is shown once, so store it somewhere safe, then export it:

export BETWATCH_API_KEY=bw_...

Betwatch() reads it from the environment, or pass Betwatch(api_key=...). The client talks to https://api-beta.betwatch.com unless you set BETWATCH_API_URL or base_url=.

The model

Betwatch Means
Event One race. client.events
Entrant A runner in a race. card.entrants
Odds One source's current win or place price on one runner. card.odds
Source A bookmaker, tote or exchange. client.sources.list(); bookmakers carry region (au, nz, gb)
Meeting / Venue A day's racing at a track / the track itself

Every response is a typed object with snake_case attributes, so your editor completes race.start_at, runner.racing.barrier and quote.source.id. Closed vocabularies are Literal types: race.status == "resulted" is a type error because the public word is "final".

Common tasks

Today's races

races = client.events.list(sport="thoroughbred", country="au", limit=20)
for race in races:
    print(race.start_at, race.name, race.status)

open_now = client.events.list(sport=["thoroughbred", "greyhound"], status=["open", "in_progress"])

With no time window you get races from a few minutes ago onwards. Pass start_from= / start_to= for history or a later day.

Prices for one race

card = client.events.snapshot(race.id)

runner = card.entrants[0]
card.best_price(runner)              # highest win price across sources
card.price(runner, "sportsbet")      # one source
card.quotes(runner, market="place")  # every priced place quote

Scratched runners carry runner.racing.scratched_at and the late-scratching runner.racing.deduction. Exchange quotes carry quote.exchange with back and lay ladders and the Betfair market_id / selection_id.

Add include="history" to client.odds.list(event=race.id, include="history") for each source's price fluctuations.

Compact comparisons and recent form (API 2.4)

card = client.events.snapshot(
    race.id, view="summary", source_kind="bookmaker", key=["win", "place"], max_age=120
)
for runner in card.summary:
    for price in runner.prices:
        print(runner.name, price.key, price.best, price.median, price.source_count)
        print([source.name for source in price.best_sources])  # includes ties

form = client.competitors.form(competitor_id, limit=10)
for run in form:
    print(run.start_at, run.venue, run.distance_meters, run.finish, run.field_size)
# Or walk the retained history, newest first:
for run in client.competitors.iter_form(competitor_id):
    print(run.event_id, run.finish)

These methods also exist on AsyncBetwatch. Form contains only known, entitled past starts, not a complete career record. Missing official starting prices, margins and other facts are None; do not substitute zero or last bookmaker odds.

Summary groups keep source kinds and place terms separate. Only available, confirmed quotes checked within max_age seconds qualify (default 120); an empty group means no eligible offer. Summary cards contain no raw odds and cannot be passed to follow(). Full snapshots with max_age, source_kind or depth="top" also omit a continuation. Use the ordinary full snapshot for streaming.

On full cards, quotes() / best_price() exclude unavailable and explicitly unconfirmed rows (older APIs without confirmation remain compatible). Use quote.checked_at for the latest successful source-product check, not observed_at, which can remain old when a price is unchanged. SSE does not emit every poll; its timestamps are not polling heartbeats. Use REST max_age for a point-in-time freshness check. Exchange rows expose best_back, best_lay and last; use depth="top" when full ladders are unnecessary.

client.odds.retrieve(odds_id, include="history") returns history too. Fixed-odds first_recorded / last_recorded are retained samples, not official opening or starting prices; legacy history may be incomplete. Settled history is not an available offer. events.retrieve(..., include="racing", pool=["win", "place"]) limits dividend pools. meetings.retrieve(..., include="events") attaches races; sources.list(event=race.id) provides race-specific observed activity.

Migration: keep identical filters when reusing list cursors. Unsupported endpoint filters and include values now fail with 422 instead of being ignored. Check snapshot.stream before following a compact read. Prefer result.changed_at for result changes; it is absent on legacy results without a trustworthy clock. scheduled_start_at names the schedule; actual_start_at requires source evidence and is not inferred when the scheduled time passes.

Is a source's card fully priced?

With include="coverage" (or on any scope snapshot, and on the stream's coverage frames) each source's coverage row carries a book:

for row in card.coverage:
    book = row.book
    if book is None:
        continue
    print(row.source_id, row.key, book.status, f"{book.priced}/{book.active}")
    if book.first_full:                  # the first full card, kept forever
        print(book.full_at, {p.entrant_id: p.price for p in book.first_full})
  • book.status is "unpriced", "partial" or "full" (CoverageBookStatuses.FULL).
  • book.active counts runners that are not scratched, not a vacant box and not a reserve without a box; book.priced counts those with a current price.
  • book.full_at is when the book first became full, and book.first_full is every active runner's price at that moment. Both are set once; a later scratching or suspension does not move them.

Live prices

Take a snapshot, then follow it. The snapshot carries the exact stream position it was read at, so nothing that changes in between is missed:

from betwatch import OddsFrame

card = client.events.snapshot(race.id)
with client.follow(card) as live:
    for frame in live:
        if isinstance(frame, OddsFrame):
            print(frame.data.source.id, frame.data.entrant_id, frame.data.price)

To keep the card itself current, apply each frame to it. card.apply(frame) returns True only when something actually changed:

with client.follow(card) as live:
    for frame in live:
        if card.apply(frame):
            print(card.best_price(card.entrants[0]))

client.watch(race.id) does the snapshot and the follow in one call, and takes a fresh snapshot by itself if the server ever asks for one.

A whole raceday on one connection

Stream frames are not metered, so one filtered stream is both the cheapest and the fastest way to stay current. Polling costs quota on every call.

from betwatch import RacingScope

scope = RacingScope(sport="thoroughbred", country="au", key="win")
snap = client.snapshot(scope, limit=10)    # first page of races, plus their prices
with client.follow(snap) as live:          # live within seconds
    page = snap
    while page.next:                       # read the rest of the day while streaming
        page = client.snapshot_page(after=page.next)
    for frame in live:
        ...

Every page shares the first page's stream position, so races you read later still replay anything that changed while you were reading them.

snap.stream.url is the same follow request as a ready-made /v2/stream path and query (cursor and snapshot=none set), for clients other than this SDK. client.follow(snap) sends it for you.

Within one race a price frame always arrives before the coverage frame whose book it completed. The first coverage frame with book.status == "full" therefore means you already hold every price in that book. examples/first_full_book.py uses this to record the first full Sportsbet win card for every greyhound race in a day, and reads book.first_full from a snapshot for races that filled before it attached.

Resume after a restart

Persist the stream's continuation and follow it again later. It carries the position and the filters that produced it:

from pathlib import Path
from betwatch import StreamContinuation

Path("position.json").write_bytes(live.continuation.to_json())

position = StreamContinuation.from_json(Path("position.json").read_bytes())
with client.follow(position) as live:
    ...

If the position is too old to resume, the stream raises ResyncRequired; take a new snapshot and follow that (pass resync_token=err.resync_token when it has one, and that snapshot is not charged). client.watch() does this for you. Trainer, rider and owner merges do not cause a resync; they arrive as ordinary entrant frames.

Every page of a collection

for venue in client.venues.iter(country="au"):
    print(venue.name)

list() returns one page; iter() follows every page for you.

pandas

import pandas as pd

df = pd.DataFrame.from_records(card.to_records())  # one row per quote, with runner names

Async

AsyncBetwatch has the same methods, awaited:

from betwatch import AsyncBetwatch

async with AsyncBetwatch() as client:
    card = await client.events.snapshot(race_id)
    async with client.watch(race_id) as live:
        async for frame in live:
            ...

Errors, retries and limits

Every API error raises a typed exception carrying the problem's stable code, a human detail, and the request_id / trace_id to quote to support:

import time
from betwatch import NotFoundError, QuotaExceededError, RateLimitError

try:
    card = client.events.snapshot(race_id)
except RateLimitError as err:            # per-minute window; worth waiting out
    time.sleep(err.retry_after or 1)
except QuotaExceededError as err:        # monthly quota; resets in days, not seconds
    print("quota resets", err.rate_limit.monthly_reset)
except NotFoundError:
    ...
  • The client retries rate limits and transient server errors twice by default (Betwatch(max_retries=...)) and never retries an error that cannot succeed.
  • Streams reconnect by themselves after a dropped connection, from the last frame they delivered.
  • client.rate_limit shows the per-minute and monthly budget from the last response.
  • Too many concurrent streams raises StreamLimitError; a key used from an IP outside its allow-list raises IPNotAllowedError.

Upgrades

The API only grows. New fields are ignored, new stream frame types arrive as UnknownFrame, and a new vocabulary value (a new sport, odds state, or source kind) decodes as "unknown" instead of failing, so an older SDK keeps working against a newer API.

Benchmarks

2.0.0b4 against the 1.x GraphQL client (betwatch==1.7.4), measured with the published SDK code on 28 October 2026. Both clients ran on the same machine at the same time with production keys.

Live odds

Both SDKs streamed every race for 15 minutes (21:11–21:26 AEDT, evening thoroughbred, harness and greyhound meetings): client.follow() on one connection for 2.x, and subscribe_bookmaker_updates("") for 1.x. Each price was timestamped when the SDK handed it to user code. A move is one bookmaker's win price on one runner changing from one value to another. A move was paired when it happened exactly once on each stream within two minutes.

How far ahead 2.x delivered the same price move, by time to the advertised jump:

Time to jump Moves Average ahead Median ahead
30+ min 57 19.2 s 11.1 s
10–30 min 242 13.3 s 7.2 s
5–10 min 957 12.1 s 9.1 s
2–5 min 1,910 9.3 s 7.2 s
0–2 min 1,044 10.5 s 7.8 s
Past advertised start 510 12.6 s 7.9 s
All 4,720 10.8 s 7.9 s

"Ahead" is signed: the averages include the moves where 1.x was first.

Over the same 15 minutes 1.x 2.x
Win-price changes on the same 55 races and 46 bookmakers 9,299 13,005
Price updates delivered, all races 33,722 (win only) 72,454 (win, place and early markets)
Sources 53 76
Connections 1 websocket 1 SSE stream

Library and key paths

Path 1.x 2.x
import betwatch 235 ms 87 ms
Installed dependencies 22 packages, 16 MB 9 packages, 2.6 MB
Today's races, no prices (p50 of 5) 4.17 s for 416 races 1.03 s for 215 races
One race card with every price (p50 / p95 of 30) 0.72 s / 1.88 s, 367 prices 0.44 s / 0.75 s, 1,064 prices
Decode one race card, JSON bytes to typed objects 3.96 ms (85 KB) 0.72 ms (394 KB)
Decode the 15 minute live stream above 31.6 µs per price 5.1 µs per price
Live stream decode rate, one core 32,000 prices/s 196,000 prices/s
  • Race card: client.get_race(id, RaceProjection(markets=True, place_markets=True, betfair=True)) against client.events.snapshot(id), on the next 10 races to jump, three times each.
  • Decode: the best of several replays of the payloads each SDK received above. 1.x is json.loads plus typedload. 2.x is the SSE parser plus msgspec structs.
  • Network: request times include the network from a client in Oregon, US. Both APIs are behind the same CDN edge, so both pay the same round trip. From Australia they are lower.

More

Working on the SDK itself? See CONTRIBUTING.md.

Metadata

Release files for betwatch 2.0.0b7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for betwatch 2.0.0b7
File Size Uploaded Provenance Actions
betwatch-2.0.0b7.tar.gz 130.0 kB With provenance Details for betwatch-2.0.0b7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for betwatch 2.0.0b7
File Interpreter ABI Platform Actions
betwatch-2.0.0b7-py3-none-any.whl Python 3 none any Details for betwatch-2.0.0b7-py3-none-any.whl

Total release size: 191.3 kB

Release files / betwatch-2.0.0b7.tar.gz

Download URL betwatch-2.0.0b7.tar.gz
Size 130.0 kB
Tags Source
SHA-256 checksum
How to use checksums
758841065d1b3bd94e39fbf9c8daceaafe43bf432b6bdeaf89d8b1b99582cf88
BLAKE2b-256 checksum
How to use checksums
26c917b33423e31fce4aa444f9a46cb3cc668624ad011d6f76d3523bc72731da
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 Oct 31, 2026.

Transparency log

Release files / betwatch-2.0.0b7-py3-none-any.whl

Download URL betwatch-2.0.0b7-py3-none-any.whl
Size 61.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b1b2d2317e1fc207b8a7dc29905a35c5e277fc0df52a468d47d5c92bbe000f1
BLAKE2b-256 checksum
How to use checksums
fbb38cd41822b54e19665c2ba85ea05c2c2d64ea2930cb1edff13400ecb9a442
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 Oct 31, 2026.

Transparency log

Security for betwatch 2.0.0b7

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.

Select from 2 files

Attestation for betwatch-2.0.0b7.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 Oct 31, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page