Thank you for your interest in contributing to PyMLB StatsAPI! This document provides guidelines and instructions for contributing.
- Code of Conduct
- Getting Started
- Development Workflow
- Pull Request Process
- Coding Standards
- Testing
- Documentation
- Issue Reporting
This project adheres to a Code of Conduct that all contributors are expected to follow. Please read CODE_OF_CONDUCT.md before contributing.
- Python 3.11 or higher
- uv package manager (recommended)
- Git
-
Fork the repository on GitHub
-
Clone your fork:
git clone https://github.com/YOUR_USERNAME/pymlb_statsapi.git cd pymlb_statsapi -
Add upstream remote:
git remote add upstream https://github.com/power-edge/pymlb_statsapi.git
-
Install dependencies:
uv sync
-
Install pre-commit hooks:
uv run pre-commit install
Always create a new branch for your work:
# Update your main branch
git checkout main
git pull upstream main
# Create a feature branch
git checkout -b feature/your-feature-name
# or
git checkout -b fix/your-bug-fixBranch naming conventions:
feature/- New featuresfix/- Bug fixesdocs/- Documentation changesrefactor/- Code refactoringtest/- Test additions or modificationschore/- Maintenance tasks
-
Make your changes following the coding standards
-
Run tests to ensure nothing breaks:
# Run unit tests uv run pytest # Run BDD tests (with stubs) STUB_MODE=replay uv run behave
-
Run code quality checks:
# Linting uv run ruff check . # Formatting uv run ruff format . # Or run all pre-commit hooks uv run pre-commit run --all-files
-
Commit your changes using conventional commits:
git add . git commit -m "feat: add new feature"
Commit message format:
feat:- New featurefix:- Bug fixdocs:- Documentation changesstyle:- Formatting changesrefactor:- Code refactoringtest:- Test changeschore:- Maintenance tasks
We provide a helper script for common git operations:
bash scripts/git.shThis provides an interactive menu for:
- Format & commit changes
- Create release (bump version & tag)
- Push to remote
- Full release workflow
- Status check
-
Update your branch with the latest upstream changes:
git fetch upstream git rebase upstream/main
-
Run all tests and ensure they pass:
uv run pytest --cov=pymlb_statsapi STUB_MODE=replay uv run behave
-
Run code quality checks:
uv run ruff check . uv run ruff format --check . uv run bandit -r pymlb_statsapi/ -ll
-
Update documentation if needed
-
Push your branch to your fork:
git push origin feature/your-feature-name
-
Open a Pull Request on GitHub
-
Fill out the PR template completely:
- Describe your changes
- Link related issues
- List any breaking changes
- Include screenshots if applicable
-
Wait for CI checks to complete:
- All tests must pass
- Code coverage should not decrease significantly
- Linting and formatting checks must pass
-
Address review feedback promptly:
- Make requested changes
- Push updates to your branch
- Respond to comments
- PRs require at least 1 approving review from a maintainer
- All CI checks must pass (tests, linting, build, docs)
- Conversations must be resolved before merging
- Maintainers may request changes or ask questions
- Line length: 100 characters maximum
- Python version: 3.11+ features allowed
- Style: Follow PEP 8 (enforced by ruff)
- Type hints: Use type annotations where appropriate
- Docstrings: Use Google-style docstrings
- Schema is Truth: JSON schemas define everything
- No Hardcoding: Generate, don't write
- Parameter Naming: Preserve exact names from schemas (no camelCase conversion)
- Testing: All new features need tests
- Documentation: Update docs for user-facing changes
from pymlb_statsapi import api
# Good: Clean, schema-driven parameter passing
response = api.Schedule.schedule(sportId=1, date="2024-10-27")
data = response.json()
# Bad: Don't create hardcoded classes or models
class Schedule: # Don't do this!
def __init__(self, sport_id: int):
self.sport_id = sport_id- Located in
tests/unit/ - Use pytest
- Aim for high coverage of new code
# Run unit tests
uv run pytest
# With coverage
uv run pytest --cov=pymlb_statsapi --cov-report=html
# Specific test
uv run pytest tests/unit/pymlb_statsapi/model/test_factory.py- Located in
tests/bdd/ - Use behave with stub capture/replay
- Test real-world API scenarios
# Run with stubs (fast)
STUB_MODE=replay uv run behave
# Capture new stubs (makes real API calls)
STUB_MODE=capture uv run behave features/schedule.feature
# Test specific endpoint
uv run behave features/game.feature- Use completed games from past seasons
- Example: World Series 2024 games (game_pk=747175, 747176)
- Use stable dates: October 2024 for schedules
- Always gzip test stubs
Documentation is built with Sphinx and hosted on ReadTheDocs.
# Build documentation locally
cd docs
make html
# View in browser
open _build/html/index.html- Update docstrings for new methods
- Add examples for new features
- Update schema reference if schemas change
- Keep README.md examples up to date
- Search existing issues to avoid duplicates
- Check documentation for solutions
- Test with latest version
- Use issue templates (bug report or feature request)
- Provide clear, concise description
- Include code examples and error messages
- Specify Python version and OS
- Include relevant logs or screenshots
Maintainers will label issues:
bug- Something isn't workingenhancement- New feature requestdocumentation- Documentation improvementsgood first issue- Good for newcomershelp wanted- Extra attention neededquestion- Further information requested
When MLB adds new endpoints:
- Get JSON schema from MLB Stats API documentation
- Add to resources:
pymlb_statsapi/resources/schemas/statsapi/stats_api_1_0/{endpoint}.json - Create BDD tests:
tests/bdd/{endpoint}.feature - Capture stubs:
STUB_MODE=capture uv run behave tests/bdd/{endpoint}.feature - Update documentation: Add examples to schema reference
No code changes needed - the system is fully schema-driven!
- GitHub Discussions: Ask questions and discuss ideas
- Issue Tracker: Report bugs or request features
- Documentation: Read the full docs at https://pymlb-statsapi.readthedocs.io/
Contributors will be:
- Listed in release notes
- Acknowledged in the project
- Added to GitHub contributors page
Thank you for contributing to PyMLB StatsAPI!