PySumoAPI
A Python client library for the Sumo API, providing easy access to sumo wrestling data including rikishi information, statistics, shikona history, measurements, and rank history.
Features
- Asynchronous API client using
httpx - Strongly typed data models using
pydantic - Comprehensive error handling
Installation
# Using pip
pip install pysumoapi
Quick Start
import asyncio
from pysumoapi.client import SumoClient
async def main():
async with SumoClient() as client:
# Get rikishi information
rikishi = await client.get_rikishi(1511)
print(f"Name: {rikishi.shikona_en}")
# Get rikishi statistics
stats = await client.get_rikishi_stats(1511)
print(f"Total matches: {stats.total_matches}")
# Get shikona history
shikonas = await client.get_shikonas(rikishi_id=1511, sort_order="asc")
for shikona in shikonas:
print(f"Basho: {shikona.basho_id}, Shikona: {shikona.shikona_en}")
if __name__ == "__main__":
asyncio.run(main())
Synchronous Usage (SumoSyncClient)
For environments where asyncio is not ideal (e.g., scripts, Jupyter notebooks), SumoSyncClient provides a synchronous interface:
from pysumoapi import SumoSyncClient
# All constructor arguments from SumoClient are also available for SumoSyncClient
with SumoSyncClient(base_url="https://sumo-api.com") as client:
try:
rikishi = client.get_rikishi(rikishi_id="1") # Example call
print(rikishi.shikona_en)
except Exception as e:
print(f"An error occurred: {e}")
The SumoSyncClient wraps the asynchronous SumoClient and manages an event loop internally when its methods are called. It must be used as a context manager (with a with statement).
API Reference
SumoClient
The main client class for interacting with the Sumo API.
from pysumoapi.client import SumoClient
# Initialize with custom base URL and SSL verification
async with SumoClient(base_url="https://sumo-api.com", verify_ssl=True) as client:
# Use the client here
Methods
-
get_rikishi(rikishi_id: str) -> Rikishi: Get information about a rikishi- Raises
ValueErrorif rikishi_id is invalid
- Raises
-
get_rikishi_stats(rikishi_id: str) -> RikishiStats: Get statistics for a rikishi- Raises
ValueErrorif rikishi_id is invalid
- Raises
-
get_rikishis(shikona_en: Optional[str] = None, heya: Optional[str] = None, sumodb_id: Optional[int] = None, nsk_id: Optional[int] = None, intai: Optional[bool] = None, measurements: bool = True, ranks: bool = True, shikonas: bool = True, limit: int = 10, skip: int = 0) -> RikishiList: Get a list of rikishi with optional filters- Raises
ValueErrorif any ID parameters are invalid
- Raises
-
get_rikishi_matches(rikishi_id: int, basho_id: Optional[str] = None) -> RikishiMatchesResponse: Get all matches for a specific rikishi- Raises
ValueErrorif:- rikishi_id is not positive
- basho_id is not in YYYYMM format
- Raises
-
get_rikishi_opponent_matches(rikishi_id: int, opponent_id: int, basho_id: Optional[str] = None) -> RikishiOpponentMatchesResponse: Get all matches between two specific rikishi- Raises
ValueErrorif:- rikishi_id or opponent_id is not positive
- basho_id is not in YYYYMM format
- Raises
-
get_basho(basho_id: str) -> Basho: Get details for a specific basho tournament- Raises
ValueErrorif:- basho_id is not in YYYYMM format
- basho date is in the future
- Raises
-
get_banzuke(basho_id: str, division: str) -> Banzuke: Get banzuke details for a specific basho and division- Raises
ValueErrorif:- basho_id is not in YYYYMM format
- basho date is in the future
- division is not one of: Makuuchi, Juryo, Makushita, Sandanme, Jonidan, Jonokuchi
- Automatically converts match records to unified Match model
- Raises
-
get_torikumi(basho_id: str, division: str, day: int) -> Torikumi: Get torikumi details for a specific basho, division, and day- Raises
ValueErrorif:- basho_id is not in YYYYMM format
- basho date is in the future
- division is not one of: Makuuchi, Juryo, Makushita, Sandanme, Jonidan, Jonokuchi
- day is not between 1 and 15
- Automatically converts matches to unified Match model
- Raises
-
get_kimarite(sort_field: Optional[str] = None, sort_order: Optional[str] = "asc", limit: Optional[int] = None, skip: Optional[int] = 0) -> KimariteResponse: Get statistics on kimarite usage- Raises
ValueErrorif:- sort_field is not one of: count, kimarite, lastUsage
- sort_order is not 'asc' or 'desc'
- limit is not positive
- skip is negative
- Raises
-
get_kimarite_matches(kimarite: str, sort_order: Optional[str] = "asc", limit: Optional[int] = None, skip: Optional[int] = 0) -> KimariteMatchesResponse: Get matches where a specific kimarite was used- Raises
ValueErrorif:- kimarite is empty
- sort_order is not 'asc' or 'desc'
- limit is not positive or exceeds 1000
- skip is negative
- Raises
-
get_measurements(basho_id: Optional[str] = None, rikishi_id: Optional[int] = None, sort_order: Optional[str] = "desc") -> MeasurementsResponse: Get measurement changes by rikishi or basho- Raises
ValueErrorif:- Neither basho_id nor rikishi_id is provided
- basho_id is not in YYYYMM format
- rikishi_id is not positive
- sort_order is not 'asc' or 'desc'
- Automatically sorts results by basho_id if requested
- Raises
-
get_ranks(basho_id: Optional[str] = None, rikishi_id: Optional[int] = None, sort_order: Optional[str] = "desc") -> RanksResponse: Get rank changes by rikishi or basho- Raises
ValueErrorif:- Neither basho_id nor rikishi_id is provided
- basho_id is not in YYYYMM format
- rikishi_id is not positive
- sort_order is not 'asc' or 'desc'
- Automatically sorts results by basho_id if requested
- Raises
-
get_shikonas(basho_id: Optional[str] = None, rikishi_id: Optional[int] = None, sort_order: Optional[str] = "desc") -> ShikonasResponse: Get shikona changes by rikishi or basho- Raises
ValueErrorif:- Neither basho_id nor rikishi_id is provided
- basho_id is not in YYYYMM format
- rikishi_id is not positive
- sort_order is not 'asc' or 'desc'
- Automatically sorts results by basho_id if requested
- Raises
Data Models
Rikishi: Information about a rikishiRikishiList: List of rikishi with pagination informationRikishiStats: Statistics for a rikishiRikishiMatchesResponse: Response containing rikishi matchesRikishiOpponentMatchesResponse: Response containing matches between two rikishiBasho: Information about a basho tournamentBanzuke: Banzuke details for a divisionRikishiBanzuke: Individual rikishi entry in a banzukeTorikumi: Match schedule for a specific dayYushoWinner: Information about a yusho winnerMatch: Unified model for sumo matches across all endpointsKimariteResponse: Statistics about kimarite usageKimariteMatch: Information about a match where a specific kimarite was usedKimariteMatchesResponse: Response containing matches with a specific kimariteMeasurement: Physical measurements of a rikishiMeasurementsResponse: Response containing measurement recordsRank: Rank information for a rikishiRanksResponse: Response containing rank recordsShikona: Shikona (ring name) informationShikonasResponse: Response containing shikona recordsDivisionStats: Statistics broken down by divisionSansho: Special prize informationRikishiPrize: Information about a rikishi who won a prize
Examples
See the examples directory for more detailed examples:
- Shikona Example: Demonstrates retrieving and displaying shikona history
- Comprehensive Example: Shows how to use multiple endpoints together to create a comprehensive rikishi profile
Development
Setup
# Clone the repository
git clone https://github.com/colebrumley/pysumoapi.git
cd pysumoapi
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
Using Make
This project includes a Makefile to automate common development tasks:
# Show available commands
make help
# Install the package in development mode
make setup
# Clean build artifacts and caches
make clean
# Run tests
make test
# Run linters
make lint
# Format code
make format
# Build the package
make build
# Publish to PyPI (requires PYPI_API_TOKEN environment variable)
make publish
# Show current version
make version
# Bump version (major, minor, or patch)
make version-bump TYPE=patch
# Set version explicitly
make version-set VERSION=1.0.0
Version Management
The package includes a version management script (scripts/version.py) to help with versioning:
# Show current version
python scripts/version.py show
# Bump version (major, minor, or patch)
python scripts/version.py bump --type patch
# Set version explicitly
python scripts/version.py set --version 1.0.0
The script automatically:
- Updates version in
pyproject.toml - Updates
CHANGELOG.mdwith a new version entry - Validates version format
- Handles version bumping according to semantic versioning
Release Process
To create a new release:
-
Ensure you're on the
mainbranch and it's up to date:git checkout main git pull origin main
-
Run the release script:
# For a patch release (0.1.0 -> 0.1.1) make release TYPE=patch # For a minor release (0.1.0 -> 0.2.0) make release TYPE=minor # For a major release (0.1.0 -> 1.0.0) make release TYPE=major
The release script (
scripts/release.py) performs the following checks and steps:- Verifies git working directory is clean
- Confirms you're on the main branch
- Ensures local branch is up to date with remote
- Checks for required dependencies
- Verifies PyPI token is set (if publishing)
- Bumps version using version.py
- Runs tests
- Runs linters
- Builds the package
- Publishes to PyPI (if PYPI_API_TOKEN is set)
- Creates a git tag
- Commits changes
- Pushes to GitHub
You can skip certain steps using flags:
# Skip tests and linting make release TYPE=patch --skip-tests --skip-lint # Skip publishing to PyPI make release TYPE=patch --skip-publish # Skip creating a git tag make release TYPE=patch --skip-tag # Skip pre-release checks make release TYPE=patch --skip-checks
-
The script will prompt you to:
- Review the changes
- Confirm the release
- Push the changes and tag
Note: The release process requires:
- Python 3.11 or later
uvfor dependency managementPYPI_API_TOKENenvironment variable for publishing to PyPI- Git configured with proper credentials
Release files for pysumoapi 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pysumoapi-0.3.0.tar.gz | 15.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pysumoapi-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.3 kB
Release files / pysumoapi-0.3.0.tar.gz
| Download URL | pysumoapi-0.3.0.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4fa2dabb7e222e4b06ac4c98feda302998eefb35c41418dcce2ae10dee72fc2
|
|
BLAKE2b-256 checksum How to use checksums |
1cd802a2f87236327af95ee1b9f52e337e572ce9348abe38ad8d4e0d213680aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Release files / pysumoapi-0.3.0-py3-none-any.whl
| Download URL | pysumoapi-0.3.0-py3-none-any.whl |
|---|---|
| Size | 20.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f60672a2155d3f7da5ae2702fa0021d31cc1e5ac07492dcc36fc6e8f1dde7a5f
|
|
BLAKE2b-256 checksum How to use checksums |
315c3ea728f21bc04d3f554e3567e37b712e1365dc24d99147cf4a79b967afca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|