Skip to main content

A minimal tournament pairing library for Python.

Project description

NYIG TD

A minimal Python library for tournament pairings.

Features

  • Swiss pairing with score-based matching and repeat prevention.
  • Seed-based matching (1 vs N, 2 vs N-1).

Installation

pip install nyig-td

Usage

Swiss Pairings

from nyig_td import Participant, create_swiss_pairings

# ... setup players, scores, history ...
pairings = create_swiss_pairings(players, scores, history, round_number=1, bye_history=bye_history)

McMahon Pairings

McMahon pairing is common in Go tournaments. Players start with an initial score based on their rank. The library can automatically extract ranks from participant metadata.

# Participants with rank in metadata
players = [
    Participant(id="P1", name="Alice", metadata={"rank": 20}),
    Participant(id="P2", name="Bob", metadata={"rank": 19}),
]

t = Tournament(id="T1", name="City Open", participants=players)

# Generate round 1 using metadata ranks automatically
pairings = t.create_round(
    type="mcmahon",
    top_bar=20,
    bottom_bar=10
)

# Inspect match properties
match = pairings[0]
if not match.is_bye:
    print(f"Board 1: {match.p1.name} vs {match.p2.name}")

Standings and Metrics

The library provides a powerful metrics engine to calculate standings with custom tie-breaking rules, supporting both Swiss and McMahon formats.

from nyig_td.models import Tournament, MetricsConfig, TieBreaker

# 1. Setup tournament and record matches
t = Tournament(id="T1", name="City Open", participants=players)
# ... add matches and results ...

# 2. Configure standings (optional)
config = MetricsConfig(
    tie_breakers=[
        TieBreaker.MAIN_SCORE,
        TieBreaker.SOS,         # Sum of Opponents' Scores
        TieBreaker.SODOS,       # Sum of Defeated Opponents' Scores
        TieBreaker.SOSOS        # Sum of Opponents' SOS
    ],
    bye_points=1.0  # Points awarded for a bye
)

# 3. Get standings
standings = t.get_standings(config)
for entry in standings["General"]:
    print(f"{entry.rank}. {entry.participant.name} - {entry.main_score} ({entry.record})")

Tournament Divisions

You can automatically group standings by player rank:

from nyig_td.models import DivisionConfig

config = MetricsConfig(
    divisions=[
        DivisionConfig(name="Open", min_rank=20),
        DivisionConfig(name="Intermediate", min_rank=10, max_rank=19),
        DivisionConfig(name="Novice", max_rank=9)
    ]
)

standings_by_div = t.get_standings(config)
# returns {"Open": [...], "Intermediate": [...], "Novice": [...]}

McMahon Standings

To use McMahon Scores (Initial Rank + Points) as the primary metric:

config = MetricsConfig(
    use_mcmahon=True,
    top_bar=20,    # McMahon scores are capped at 20
    bottom_bar=5   # McMahon scores are floored at 5
)
standings = t.get_standings(config)

Development

This project uses uv for dependency management.

uv sync
uv run mypy
uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nyig_td-0.1.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nyig_td-0.1.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file nyig_td-0.1.1.tar.gz.

File metadata

  • Download URL: nyig_td-0.1.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nyig_td-0.1.1.tar.gz
Algorithm Hash digest
SHA256 112e35097bcaeb3fdcccbc42b633d8a9795181ac45e51959b74141c32d508eb5
MD5 f525dc6364820421b48e56697e280752
BLAKE2b-256 db9d54319f81171363d16c302dccb84c5a32fa069d3aa576ff4b5a869e293195

See more details on using hashes here.

Provenance

The following attestation bundles were made for nyig_td-0.1.1.tar.gz:

Publisher: publish.yml on liryan1/nyig-td

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nyig_td-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nyig_td-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nyig_td-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a633ce30f2c2692b075062e117df7c219a6f0de7a2e3e3e85284df2925a0c49
MD5 b336198b98cdc659787f3c7a5d9abbbf
BLAKE2b-256 57c4c9bfb3b2d3096d8d921bb1eb523a3ba1b16f73c1a6e21a5911c03ed464de

See more details on using hashes here.

Provenance

The following attestation bundles were made for nyig_td-0.1.1-py3-none-any.whl:

Publisher: publish.yml on liryan1/nyig-td

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page