Thank you for your interest in contributing to py-alpaca-api! This guide will help you get started.
- Python 3.10 or higher
- uv package manager
- Fork and clone the repository:
git clone https://github.com/yourusername/py-alpaca-api.git
cd py-alpaca-api- Install dependencies:
make install- Set up pre-commit hooks:
make pre-commit- Set up environment variables:
export ALPACA_API_KEY=your_api_key
export ALPACA_SECRET_KEY=your_secret_keyWe use several tools to maintain code quality:
- Ruff: For linting and formatting
- MyPy: For static type checking
- Pre-commit: For automatic checks before commits
Use the Makefile for common development tasks:
# Run tests
make test
# Format code
make format
# Run linter
make lint
# Fix linting issues
make lint-fix
# Run type checker
make type-check
# Run all checks
make check
# Clean build artifacts
make cleanRun tests with:
./test.sh # Runs all tests with API credentials
make test # Alternative wayRun specific tests:
./test.sh tests/test_trading/test_orders.pyGenerate coverage report:
make coverage- Follow PEP 8 guidelines
- Use type hints for all function signatures
- Write docstrings for all public functions and classes (Google style)
- Keep line length under 88 characters
- Use meaningful variable and function names
Pre-commit hooks will automatically run before each commit to ensure code quality:
- Trailing whitespace removal
- End-of-file fixing
- YAML/JSON/TOML validation
- Ruff linting and formatting
- MyPy type checking
If pre-commit fails, fix the issues and try committing again.
- Create a new branch:
git checkout -b feature/your-feature-name- Make your changes and ensure tests pass:
make check
make test- Commit your changes:
git add .
git commit -m "feat: add new feature"- Push to your fork:
git push origin feature/your-feature-name- Create a pull request
Follow conventional commit format:
feat:New featurefix:Bug fixdocs:Documentation changesstyle:Code style changesrefactor:Code refactoringtest:Test changeschore:Maintenance tasks
- Ensure all tests pass
- Update documentation if needed
- Add tests for new functionality
- Ensure your code follows the project style
- Update the changelog if applicable
- Request review from maintainers
py-alpaca-api/
├── src/
│ └── py_alpaca_api/
│ ├── __init__.py # Main API entry point
│ ├── exceptions.py # Custom exceptions
│ ├── http/ # HTTP request handling
│ ├── models/ # Data models
│ ├── stock/ # Stock market operations
│ └── trading/ # Trading operations
├── tests/ # Test files
├── docs/ # Documentation
├── Makefile # Development commands
├── pyproject.toml # Project configuration
└── .pre-commit-config.yaml # Pre-commit hooks
- Open an issue for bugs or feature requests
- Join discussions in existing issues
- Ask questions in pull requests
By contributing, you agree that your contributions will be licensed under the same license as the project.