Skip to main content

Python client library for RaceResult Web API

Project description

RaceResult Python Web API Library

A Python client library for the RaceResult Web API that mirrors the functionality of the Go library.

Features

  • Pythonic API design with dataclasses
  • Session management with automatic cleanup
  • Event and participant operations
  • Raw timing data retrieval
  • Easy-to-use endpoint classes
  • Type hints for better IDE support

Installation

pip install -e .
# or for development:
pip install -r requirements.txt

Quick Start

Environment Setup

Create a .env file with your credentials:

RACERESULT_API_KEY=your_api_key_here
RACERESULT_USERNAME=your_username
RACERESULT_PASSWORD=your_password

Basic Usage

from rr_webapi import API
import os

# Create API client
api = API("events.raceresult.com", use_https=True)

# Login with API key
api.public().login(api_key=os.getenv("RACERESULT_API_KEY"))

try:
    # Get your events
    events = api.public().event_list()
    print(f"You have {len(events)} events")
    
    # Open an event
    if events:
        event_api = api.event_api(events[0].id)
        
        # Get participants
        participants = event_api.data.list([
            "ID", "BIB", "FIRSTNAME", "LASTNAME", "CONTEST.NAME"
        ])
        print(f"Event has {len(participants)} participants")
        
        # Get raw data for a participant
        if participants:
            raw_data = event_api.rawdata.get_by_pid(participants[0][0])  # ID is first field
            print(f"Participant has {len(raw_data)} raw data entries")

finally:
    # Always logout
    api.public().logout()

API Structure

Main Components

  • API: Main client with session management
  • Public: Authentication and account operations
  • EventAPI: Event-specific operations

Event API Endpoints

  • data: Participant data retrieval and filtering
  • participants: Participant management (CRUD)
  • contests: Contest/category management
  • rawdata: Raw timing data access

Authentication

API Key Authentication

api.public().login(api_key="your_api_key")

Username/Password Authentication

api.public().login(username="username", password="password")

Bulk Operations

Adding Multiple Participants at Once

# Prepare multiple participants
participants = []
for i in range(1001, 1006):
    participant = {
        "Bib": i,
        "FirstName": "Test",
        "LastName": str(i),
        "Sex": "m",
        "DateOfBirth": "1990-01-01",
        "Contest": contest_id
    }
    participants.append(participant)

# Save all participants in bulk
event_api.participants().save(participants, no_history=False)

Manual Raw Data Entry

# Add a manual timing entry
event_api.rawdata().add_manual(
    timing_point="Finish",
    identifier_name="bib",  # or "pid"  
    identifier_value=1001,
    time=3600.5,  # Time in decimal seconds
    add_t0=False
)

Data Models

The library uses dataclasses for structured data:

@dataclass
class EventListItem:
    id: str
    name: str
    date: str
    participants: int
    # ... other fields

Examples

See the ../../examples/python/ directory for complete examples:

  • basic_usage.py: Authentication and basic operations
  • participant_and_rawdata.py: Advanced participant and timing data operations
  • bulk_participant_save.py: Bulk saving multiple participants at once

Development

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run tests
python -m pytest tests/

Requirements

  • Python 3.7+
  • requests
  • python-dateutil
  • python-dotenv

Package Structure

rr_webapi/
├── __init__.py          # Main API class
├── api.py              # Core HTTP client
├── public.py           # Public API endpoints
├── eventapi.py         # Event API wrapper
├── general.py          # General utilities
└── endpoints/          # Endpoint implementations
    ├── data.py
    ├── contests.py
    ├── participants.py
    └── rawdata.py

License

This library follows the same license as the original Go library.

Contributing

  1. Follow the existing code patterns
  2. Add tests for new functionality
  3. Update documentation
  4. Ensure examples work with changes

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

rr_webapi-0.1.13.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

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

rr_webapi-0.1.13-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file rr_webapi-0.1.13.tar.gz.

File metadata

  • Download URL: rr_webapi-0.1.13.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for rr_webapi-0.1.13.tar.gz
Algorithm Hash digest
SHA256 be6764ca9a277a2dbd8e9854121e576dca6813d163eeda0864c521b7b8830dae
MD5 737ff875a5fc3e5fac3e63a69b692bdd
BLAKE2b-256 4421de168dd7b4af5050e40714dce662fa66648d432230383d66aefd4f70e6d5

See more details on using hashes here.

File details

Details for the file rr_webapi-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: rr_webapi-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for rr_webapi-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 f559e04daa2dd50de6352b04cdcc0edb4dac8242838959100df3a62df7c67cf4
MD5 bff4979e0115c0f4b602ce58a4181c16
BLAKE2b-256 9c9502c059ba9f868d99853db4c0a8125660cf621d3e8ae52f8fca0f5cd2f940

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