Skip to main content

Python SDK for the Paircraft API - Chess Tournament Management

Project description

Paircraft - Chess Tournament API SDK

A Python library for interacting with the Paircraft API. Manage chess tournaments, players, pairings, and results programmatically.

Installation

pip install paircraft

Quick Start

from paircraft import ChessTournamentClient

# Initialize the client
client = ChessTournamentClient(api_key="your-api-key")

# Create a tournament
tournament = client.tournaments.create(
    name="Spring Open 2024",
    date="2024-03-15",
    rounds=5,
    time_control="G/60+5"
)

# Add players
client.players.add(tournament.id, [
    {"name": "Magnus Carlsen", "rating": 2830},
    {"name": "Hikaru Nakamura", "rating": 2780},
    {"name": "Fabiano Caruana", "rating": 2766},
    {"name": "Wesley So", "rating": 2750},
])

# Generate pairings for round 1
pairings = client.pairings.generate(tournament.id, round=1)

# Enter results
for pairing in pairings:
    client.pairings.set_result(tournament.id, pairing.id, result="1-0")

# Get standings
standings = client.tournaments.standings(tournament.id)
for player in standings:
    print(f"{player.rank}. {player.name}: {player.total_points} points")

# Get prize winners
prizes = client.tournaments.prizes(tournament.id)
for section in prizes.sections:
    print(f"\n{section.name} Section:")
    for winner in section.winners:
        print(f"  {winner.position}. {winner.player_name} - {winner.prize_name}")

Features

  • Tournament Management: Create, update, delete, and list tournaments
  • Player Management: Add, import, update, and remove players
  • Pairing Generation: Swiss system pairings with configurable options
  • Result Entry: Single and batch result submission
  • Standings: Real-time standings with tiebreakers
  • Prize Calculation: Automatic prize distribution by section

API Reference

ChessTournamentClient

The main client for interacting with the API.

client = ChessTournamentClient(
    api_key="your-api-key",
    base_url="https://chess-tournament-director-6ce5e76147d7.herokuapp.com"
)

Tournaments

# List all tournaments
tournaments = client.tournaments.list()

# Get a specific tournament
tournament = client.tournaments.get(tournament_id)

# Create a tournament
tournament = client.tournaments.create(
    name="Tournament Name",
    date="2024-03-15",
    rounds=5,
    time_control="G/60+5",
    location="Chess Club",
    format="swiss"  # or "round_robin"
)

# Update a tournament
client.tournaments.update(tournament_id, name="New Name")

# Delete a tournament
client.tournaments.delete(tournament_id)

# Get standings
standings = client.tournaments.standings(tournament_id, section="Open")

# Get prizes/winners
prizes = client.tournaments.prizes(tournament_id)

Players

# List players in a tournament
players = client.players.list(tournament_id)

# Get a specific player
player = client.players.get(tournament_id, player_id)

# Add a single player
player = client.players.add(tournament_id, {
    "name": "John Doe",
    "rating": 1500,
    "uscf_id": "12345678"
})

# Import multiple players
result = client.players.import_players(tournament_id, [
    {"name": "Player 1", "rating": 1500},
    {"name": "Player 2", "rating": 1600},
])

# Update a player
client.players.update(tournament_id, player_id, rating=1550)

# Remove a player
client.players.delete(tournament_id, player_id)

# Withdraw a player
client.players.withdraw(tournament_id, player_id)

Pairings

# Get pairings for a round
pairings = client.pairings.list(tournament_id, round=1)

# Generate pairings
pairings = client.pairings.generate(tournament_id, round=1)

# Set a result
client.pairings.set_result(tournament_id, pairing_id, result="1-0")

# Batch results
client.pairings.set_results(tournament_id, [
    {"pairing_id": "id1", "result": "1-0"},
    {"pairing_id": "id2", "result": "0-1"},
    {"pairing_id": "id3", "result": "1/2-1/2"},
])

# Check round status
status = client.pairings.round_status(tournament_id, round=1)

Result Formats

The API accepts the following result formats:

Result Meaning
"1-0" White wins
"0-1" Black wins
"1/2-1/2" or "0.5-0.5" Draw
"1F-0F" White wins by forfeit
"0F-1F" Black wins by forfeit
"0F-0F" Double forfeit
"1-0 bye" Full-point bye
"0.5-0.5 bye" Half-point bye

Error Handling

from paircraft import ChessTournamentClient
from paircraft.exceptions import (
    APIError,
    AuthenticationError,
    NotFoundError,
    ValidationError,
    RateLimitError
)

client = ChessTournamentClient(api_key="your-api-key")

try:
    tournament = client.tournaments.get("invalid-id")
except NotFoundError:
    print("Tournament not found")
except AuthenticationError:
    print("Invalid API key")
except ValidationError as e:
    print(f"Validation error: {e.message}")
except RateLimitError:
    print("Rate limit exceeded, try again later")
except APIError as e:
    print(f"API error: {e}")

Testing

For testing, use the test API key:

client = ChessTournamentClient(api_key="test-api-key-full-access")

License

MIT License - see LICENSE for details.

Links

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

paircraft-1.0.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

paircraft-1.0.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file paircraft-1.0.0.tar.gz.

File metadata

  • Download URL: paircraft-1.0.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for paircraft-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9dcf783e5f5f47245c35bfcd75e2d9193629ce44743f5ad106017cd2fe1ec28a
MD5 f2eb1004566aca066ba953fd84cae609
BLAKE2b-256 6d6fbd7ca4c04a16c0d942aa25a7dcaa3c86043993a66da74732c8b94182a2cf

See more details on using hashes here.

File details

Details for the file paircraft-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: paircraft-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for paircraft-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb83c62f9b4ea15e3f5fdf85da84ce3e57a35558cb3dd81d83a8551ac9f81df2
MD5 eb299f0c3e98b32999937625acabca0c
BLAKE2b-256 3a3edd3da1ae8e9dfbb8e4993d11373ba32451d6f27933c51c3b26d667e324d3

See more details on using hashes here.

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