Skip to content

Releases: zero-sum-seattle/python-mlb-statsapi

v0.7.1

14 Jan 03:34
4bf811b

Choose a tag to compare

Release Notes v0.7.1

🎉 Major Changes

Removed Key Transformation Layer

Removed the _transform_keys_in_data() function that was lowercasing all API response keys. Models now directly use the MLB Stats API's native camelCase format, simplifying the codebase and ensuring accurate representation of API responses.

Complete Pydantic Migration

This release includes the complete migration from Python dataclasses to Pydantic v2 models across the entire codebase (from v0.7.1). All models now use Pydantic for validation, serialization, and data handling.

Key Benefits:

  • Automatic data validation with clear error messages
  • Built-in serialization with model_dump() and model_dump_json()
  • Pythonic snake_case field names while maintaining API camelCase compatibility
  • Better type safety and IDE support

📝 Breaking Changes

⚠️ This is a major version release with breaking changes:

  1. Field Access: All model fields now use snake_case instead of camelCase:

    # Before
    game.gamedata.weather
    
    # After
    game.game_data.weather
  2. Validation Errors: Invalid data now raises pydantic.ValidationError instead of TypeError

  3. Serialization: Use Pydantic methods for serialization:

    # New methods
    model.model_dump()
    model.model_dump_json()

🔧 Model Updates

Core Models

  • All models migrated to Pydantic MLBBaseModel
  • Field aliases updated to match actual API camelCase format
  • Optional fields properly marked for fields that may be missing

Specific Model Fixes

  • Game Models: gamePk, gameData, liveData, metaData aliases corrected
  • HomeRunDerby: homeRun, tieBreaker, isHomeRun, isTieBreaker aliases fixed
  • Stats Models: wobaCon, pitchArsenal aliases corrected
  • Schedule Models: calendarEventId made optional
  • Standings Models: wildcardGamesBack, wildcardEliminationNumber made optional

🐛 Bug Fixes

  • Fixed missing fields in various stat models
  • Added age and caughtstealingpercentage to SimplePitchingSplit
  • Fixed flyballpercentage field in AdvancedPitchingSplit
  • Updated models for new MLB API fields
  • Fixed missing keys in live feed data

📚 Documentation

  • Updated README with Pydantic migration examples
  • Added "Working with Pydantic Models" section
  • Added Contributing section to README
  • Updated all code examples to use snake_case field names

🔄 Migration Guide

If you're upgrading from v0.5.x or v0.6.x:

  1. Update field access: Change all camelCase field names to snake_case

    # Old
    game.gamedata.weather
    stat.totalsplits
    
    # New
    game.game_data.weather
    stat.total_splits
  2. Update error handling: Catch ValidationError instead of TypeError

    from pydantic import ValidationError
    
    try:
        game = Game(**data)
    except ValidationError as e:
        # Handle validation error
  3. Use Pydantic serialization: Replace __dict__ access with model_dump()

    # Old
    data = game.__dict__
    
    # New
    data = game.model_dump()

📦 Dependencies

  • Added pydantic>=2.0 as a core dependency
  • Migrated from setuptools to Poetry for dependency management

🧪 Testing

  • Removed all mock tests (22,370+ lines)
  • External tests updated and passing
  • CI/CD pipelines updated to remove mock test runs

Full Changelog: v0.5.3...v0.7.0

v0.5.3

09 Jan 23:29
dedb2b9

Choose a tag to compare

v0.5.3 of python-mlb-statsapi