API
All public names are exported through elo_mmr_py.__all__, and the distribution
contains py.typed plus a stub for the native module.
elo_mmr_py.rate
rate(
contests: Sequence[Contest],
system: RatingSystem = 'mmr',
mu_noob: float = 1500.0,
sig_noob: float = 350.0,
load_checkpoint: StrPath | None = None,
save_checkpoint: StrPath | None = None,
) -> dict[str, Player]
Rate participants and return their complete histories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contests
|
Sequence[Contest]
|
Chronologically ordered competitions to process. |
required |
system
|
RatingSystem
|
Rating system name or an
EloMmrConfig. |
'mmr'
|
mu_noob
|
float
|
Initial mean rating for newly observed participants. |
1500.0
|
sig_noob
|
float
|
Initial rating uncertainty for newly observed participants. |
350.0
|
load_checkpoint
|
StrPath | None
|
Optional v2 or legacy v1 checkpoint to continue. |
None
|
save_checkpoint
|
StrPath | None
|
Optional path atomically replaced with a v2 checkpoint. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Player]
|
A mapping from participant names to latest ratings and all event objects. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If inputs or checkpoint contents are invalid. |
OSError
|
If a checkpoint cannot be read or written. |
RuntimeError
|
If the underlying Rust calculation fails unexpectedly. |
elo_mmr_py.rate_latest
rate_latest(
contests: Sequence[Contest],
system: RatingSystem = 'mmr',
mu_noob: float = 1500.0,
sig_noob: float = 350.0,
load_checkpoint: StrPath | None = None,
save_checkpoint: StrPath | None = None,
) -> dict[str, PlayerRating]
Rate participants without materializing their histories in Python.
This is the preferred API for leaderboards and services that only need each participant's current rating, uncertainty, and number of rated contests. Checkpoint semantics and validation are identical to rate.
elo_mmr_py.Rater
Incrementally maintain ratings without replaying previous contests.
ratings
property
ratings: dict[str, PlayerRating]
Return a new latest-rating snapshot containing O(players) objects.
extend
extend(contests: Sequence[Contest]) -> None
Validate and process a chronological batch in place.
load
classmethod
Restore an incremental rater from a canonical v2 checkpoint.
All operations on one Rater instance are serialized. In particular,
ratings waits for an in-progress add() or extend() to finish before it
builds a consistent snapshot; two simultaneous snapshot reads also run one at
a time. Separate Rater instances can compute in parallel.
The complete executable example is included from its tested source file:
"""Incrementally update and restore a leaderboard."""
from __future__ import annotations
from pathlib import Path
from tempfile import TemporaryDirectory
from elo_mmr_py import Contest, Rater
def main() -> None:
rater = Rater()
rater.add(
Contest(
[('Ada', 0, 0), ('Grace', 1, 1), ('Linus', 2, 2)],
name='Opening round',
time_seconds=1_700_000_000,
)
)
rater.extend(
[
Contest(
[('Grace', 0, 0), ('Ada', 1, 1), ('Linus', 2, 2)],
name='Final round',
time_seconds=1_700_003_600,
)
]
)
with TemporaryDirectory(prefix='elo-mmr-example-') as directory:
checkpoint = Path(directory) / 'ratings.json'
rater.save(checkpoint)
restored = Rater.load(checkpoint)
for player in sorted(restored.ratings.values(), key=lambda item: -item.rating):
print(player.name, player.rating, round(player.mu, 2), player.update_time_seconds)
if __name__ == '__main__':
main()
elo_mmr_py.Player
dataclass
Player(name: str, rating: int, events: list[PlayerEvent])
A participant's latest rounded rating and complete event history.
elo_mmr_py.Contest
__new__
__new__(
standings: Sequence[tuple[str, int, int]],
name: str | None = ...,
time_seconds: int | None = ...,
url: str | None = ...,
*,
weight: float = ...,
perf_ceiling: float | None = ...,
) -> Contest
Tie and ordering rules are explained in Contest representation.
elo_mmr_py.EloMmrConfig
__new__
__new__(
system: Literal['mmr', 'mmr-fast', 'mmx', 'mmx-fast'] = ...,
*,
weight_limit: float = ...,
noob_delay: Sequence[float] | None = ...,
sig_limit: float = ...,
drift_per_day: float = ...,
split_ties: bool = ...,
subsample_size: int | None = ...,
subsample_bucket: float | None = ...,
) -> EloMmrConfig
Defaults and validation are defined in the canonical rating-system configuration guide.
elo_mmr_py.PlayerEvent
elo_mmr_py.PlayerRating
contest_index is global across checkpoint batches. rating, rating_mu,
rating_sig, and perf_score are rounded integer presentation values.
mu and sig expose the corresponding full-precision posterior values.