Skip to main content

Python API wrapper for the Puget Sound Senior Baseball League (PSSBL)

Project description

pssbl-api

PyPI version Python versions License: MIT

A Python API wrapper for the Puget Sound Senior Baseball League (PSSBL). Provides both async and sync clients for fetching team, player, and statistics data.

Table of Contents

Installation

pip install pssbl-api

Quick Start

Async Client (recommended for applications)

from pssbl_api import PSSBLClientAsync

async with PSSBLClientAsync() as client:
    teams = await client.get_team_names(year=2025)
    for team in teams:
        print(f"{team.team_name} ({team.division_name})")

Sync Client (for simple scripts)

from pssbl_api import PSSBLClient

client = PSSBLClient()
teams = client.get_team_names(year=2025)
for team in teams:
    print(f"{team.team_name} ({team.division_name})")

Configuration

Set defaults via environment variables:

export SEASON_YEAR=2025
export DEFAULT_TEAM_ID=1404
export DEFAULT_DIVISION_NAME=Denali

Or pass a Config object:

from pssbl_api import PSSBLClientAsync, Config

config = Config(
    season_year=2025,
    default_team_id=1404,
    default_division_name="Denali",
)

async with PSSBLClientAsync(config=config) as client:
    roster = await client.get_roster()  # Uses default team_id

API Reference

Team & Division Endpoints

Method Description
get_team_names(year) All teams in the league
get_divisions(year) All divisions in the league
get_division(division, year) Teams in a specific division
get_games(division, year) All games for a division

Player Endpoints

Method Description
get_all_players(year) All registered players
get_roster(team_id, year) Players on a specific team

Stats Endpoints

All stats methods use a StatType enum: BATTING, PITCHING, or BOTH.

Method Description
get_player_stats(player_id, stat_type, year, show_career) Stats for a single player
get_team_stats(team_id, stat_type, year) Stats for all players on a team
get_division_player_stats(division, stat_type, year) Stats for all players in a division
get_division_team_stats(division, stat_type, year) Aggregated team stats in a division

Stats Examples

from pssbl_api import PSSBLClient, StatType

client = PSSBLClient()

# Get 2024 batting stats for a player
result = client.get_player_stats(player_id=1404, stat_type=StatType.BATTING, year=2024)
print(result["batting"])

# Get career pitching stats for a player
result = client.get_player_stats(player_id=1404, stat_type=StatType.PITCHING, show_career=True)
print(result["pitching"])

# Get both batting and pitching stats for current year
result = client.get_player_stats(player_id=1404, stat_type=StatType.BOTH)
print(result["batting"], result["pitching"])

# Get team batting stats
result = client.get_team_stats(team_id=1500, stat_type=StatType.BATTING, year=2024)
print(result["batting"])

# Get division-wide player stats
result = client.get_division_player_stats(division="Denali", stat_type=StatType.BOTH)
print(result["batting"], result["pitching"])

# Get aggregated team stats for a division
result = client.get_division_team_stats(division="Denali", stat_type=StatType.BATTING)
print(result["batting"])  # Team averages and totals

Caching

Responses are cached for 24 hours by default. To clear the cache:

from pssbl_api import clear_cache

clear_cache()

To disable caching:

client = PSSBLClient(use_cache=False)

Error Handling

All methods return None on error and log exceptions. This design prevents exceptions from bubbling up in async contexts like Slack bots.

teams = client.get_team_names()
if teams is None:
    print("Failed to fetch teams")

Project Structure

pssbl-api/
├── src/
│   └── pssbl_api/
│       ├── __init__.py      # Public API exports
│       ├── cache.py         # Caching layer (24h TTL with hishel)
│       ├── client.py        # Async and sync API clients
│       ├── config.py        # Configuration and environment variables
│       └── models/
│           ├── __init__.py  # Model exports
│           ├── enums.py     # StatType enum
│           ├── games.py     # Game model
│           ├── players.py   # Player and roster models
│           ├── stats.py     # Batting and pitching stats models
│           └── teams.py     # Team and division models
├── tests/
│   ├── test_client.py       # Async client tests
│   ├── test_config.py       # Configuration tests
│   ├── test_models.py       # Model parsing tests
│   └── test_sync_client.py  # Sync client tests
├── pyproject.toml           # Package configuration
├── LICENSE                  # MIT License
├── CONTRIBUTING.md          # Contribution guidelines
└── README.md                # This file

Development

# Clone the repository
git clone https://github.com/YOUR_USERNAME/pssbl-api.git
cd pssbl-api

# Create virtual environment
python -m venv .venv
source .venv/bin/activate

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black .

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines on:

  • Setting up a development environment
  • Code style and testing requirements
  • Submitting pull requests
  • Reporting issues

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credits and Acknowledgements

Data Source

All baseball data is provided by PSSBL.com, the official website of the Puget Sound Senior Baseball League.

Disclaimer

This project is not affiliated with, endorsed by, or officially connected to the Puget Sound Senior Baseball League (PSSBL) in any way. It is an independent, community-driven project that provides a convenient Python interface to publicly available league data.

Tech Stack

  • httpx - HTTP client with async support
  • Pydantic - Data validation and parsing
  • hishel - HTTP caching layer

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

pssbl_api-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

pssbl_api-0.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file pssbl_api-0.1.0.tar.gz.

File metadata

  • Download URL: pssbl_api-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pssbl_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0b3efe75ad179c16cfcd600af5ba35117203e7586e3a0d18aef620a3579508b
MD5 fd67f7489bb659d0c7c1e1cf5f3a7faf
BLAKE2b-256 88b948df6155234b747a2b1eea55d5ecdb06571914bfe69fc4582fa534bde0fb

See more details on using hashes here.

File details

Details for the file pssbl_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pssbl_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pssbl_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 904f5fe1325c04bbe049e9ae33a7f96ffedaa4417c52ca44fde621b854346f11
MD5 4a3b0b6728aa3bd61b59a6bb92ee465f
BLAKE2b-256 12736b7f8288da378955f07aca6152289d62fccc4fa2b1a3f22babc0af05a79a

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