All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
Production-ready Python wrapper for the MLB Stats API with clean, Pythonic interface and comprehensive schema introspection.
- Direct parameter passing - parameters are function arguments, not dicts
- Automatic parameter routing from schema (path vs query handled internally)
- Preserved parameter names match MLB Stats API exactly (e.g.,
sportId,teamId) - Method overloading with automatic variant selection
- Type-safe parameter validation from schemas
- Access original JSON schemas programmatically
- Discover available parameters without external docs
- Get detailed parameter information including types, descriptions, and requirements
- Generate human-readable documentation from schemas
- Build tools and validators from schema definitions
- 39 BDD test scenarios covering all major endpoints
- Stub capture and replay system for fast, deterministic testing
- Multi-platform support (Ubuntu, macOS, Windows)
- Python 3.11, 3.12, 3.13 compatible
- Fully documented with examples
- GitHub Actions CI/CD pipeline
- Code coverage reporting
- ReadTheDocs integration
- Makefile for common tasks
- Pre-commit hooks for code quality
- Schedule (games, postseason, tied games)
- Game (live feed, boxscore, play-by-play, linescore, content)
- Team (rosters, stats, coaches, alumni)
- Person (player info, stats, awards)
- Season (all seasons, specific season data)
- Stats (hitting, pitching, fielding by group)
- League, Division, Sports (reference data)
from pymlb_statsapi import api
# Get schedule
response = api.Schedule.schedule(sportId=1, date="2025-06-01")
data = response.json()
# Get live game data
response = api.Game.liveGameV1(game_pk="747175")
data = response.json()
# Discover parameters
method = api.Schedule.get_method("schedule")
params = method.list_parameters()- Python 3.11 or higher
- requests library
This section documents the evolution of the library during the pre-1.0 development phase.
- Eliminated dict-based parameter passing: Parameters are now function arguments, not dicts
- Automatic parameter routing: Schema-driven path vs query parameter handling
- Preserved MLB API parameter names: No conversion to snake_case (e.g.,
sportId, notsport_id) - Method overloading support: Automatic variant selection based on path parameters
- Type-safe validation: All validation from JSON schemas
Before:
api.Game.liveGameV1(
path_params={"game_pk": "747175"},
query_params={"timecode": "20241027_000000"}
)After:
api.Game.liveGameV1(game_pk="747175", timecode="20241027_000000")- 39 BDD test scenarios covering all major endpoints
- Stub capture/replay system for fast, deterministic testing
- Multi-platform CI/CD via GitHub Actions (Ubuntu, macOS, Windows)
- Code quality tools: Ruff linting, Bandit security, pre-commit hooks
- Coverage reporting via Codecov
- ReadTheDocs integration for automated documentation
- Comprehensive README with badges and examples
- API usage guides and architecture documentation
- BDD testing guide in
features/README.md - Makefile for common development tasks
- GitHub workflows for automated testing
Added powerful introspection capabilities to discover API structure programmatically:
EndpointMethod Methods:
get_schema()- Get complete original JSON schemaget_parameter_schema(param_name)- Get specific parameter detailslist_parameters()- List all parameters organized by path/queryget_long_description()- Human-readable formatted descriptions
Endpoint Methods:
get_method(method_name)- Get EndpointMethod for introspectiondescribe_method(method_name)- Get formatted descriptionget_method_schema(method_name)- Get original schema JSON
- Self-documentation: No external API docs needed
- IDE integration: Foundation for type hints and autocomplete
- Debugging: Inspect schemas when API calls fail
- Validation: Check parameters before making requests
- Doc generation: Auto-generate API documentation from schemas
- Tool building: Build CLIs, GUIs, or other interfaces programmatically
- Testing: Generate test cases from schemas
Example:
# Discover API without external docs
method = api.Schedule.get_method("schedule")
print(method.get_long_description())
# Check parameter details
param = method.get_parameter_schema("sportId")
print(f"Type: {param['type']}, Required: {param['required']}")
# List all parameters
params = method.list_parameters()
for p in params["query"]:
print(f"{p['name']}: {p['description']}")Created fully dynamic model system that eliminates hardcoded endpoint classes:
Key Components:
APIResponse- Response wrapper with metadataEndpointMethod- Method representation with schema-based validationDynamicEndpoint- Dynamically generated endpoint classesDynamicStatsAPI- Registry with automatic schema discovery
Benefits:
- Zero hardcoded model files needed
- All endpoints/methods auto-generated from schemas
- Config-based method exclusions
- Direct data access via
.json() - Method overloading with intelligent routing
Automatic handling of MLB API endpoints with multiple variants:
# seasons() has 2 variants:
# 1. GET /v1/seasons (list all)
# 2. GET /v1/seasons/{seasonId} (get specific)
# Call without path params → variant 1
all_seasons = api.Season.seasons()
# Call with seasonId → variant 2
season_2024 = api.Season.seasons(path_params={"seasonId": "2024"})Other overloaded methods:
Schedule.schedule()- base and scheduleType variantsPerson.currentGameStats()- base, personId, and personId+gamePk variantsLeague.allStarFinalVote(),League.allStarWriteIns()- leagueId variants
- Environment variables:
PYMLB_STATSAPI__MAX_RETRIES,PYMLB_STATSAPI__TIMEOUT - Method exclusions: Config-based via
EXCLUDED_METHODSdict - Schema versioning: Support for multiple API versions
- Initialization: ~100ms to load all 21 endpoints (one-time)
- Method calls: Same as direct HTTP (no overhead)
- Memory: Minimal overhead (~1MB for all endpoint definitions)
- Schema-driven architecture with JSON schemas
endpoint-model.yamlconfiguration systemSchemaLoaderfor resource management- Base
EndpointModelandOperationModelclasses StatsAPIObjectfor HTTP requests and file operations- Support for 20+ MLB Stats API endpoints
- HTTP request handling with retry logic
- File system operations (save/load/gzip)
- Path and query parameter resolution
- Validation from JSON schemas
- Default storage in
./.var/local/mlb_statsapi
- Python: 3.11, 3.12, 3.13 supported
- Platforms: Ubuntu, macOS, Windows tested in CI
- Dependencies: Minimal (requests)
No breaking changes between development phases. All phases coexist:
- Original hardcoded models still available
- Dynamic system available as alternative
- Clean API refactor maintains backward compatibility
- Schema introspection adds methods without removing existing ones
Users can adopt features gradually:
- Phase 1: Start using dynamic system for new code
- Phase 2: Add schema introspection for API discovery
- Phase 3: Migrate to clean function signatures
Or continue using the original system - all approaches work.
Planned enhancements for post-1.0 releases:
- POST/PUT endpoint support (currently GET only)
- Async/await support for concurrent requests
- Batch request execution
- Automatic rate limit handling
- Generate type stubs from schemas (
.pyifiles) - Create Pydantic models for validation
- Export to OpenAPI/Swagger format
- Interactive schema explorer CLI
- Generate mock data from schemas
- Auto-generate API docs from schemas
- Build documentation site from schemas
- Add more real-world usage examples
- Video tutorials and guides
- Increase unit test coverage to >90%
- Add integration tests for all endpoints
- Performance benchmarking suite
- Capture comprehensive stub library
Future changes will be documented above following Semantic Versioning:
- MAJOR version for incompatible API changes
- MINOR version for new functionality in a backward compatible manner
- PATCH version for backward compatible bug fixes