Thank you for your interest in contributing to SAHI! This guide will help you get started.
git clone https://github.com/YOUR_USERNAME/sahi.git
cd sahiWe recommend Python 3.12 for development:
pip install uv
uv venv --python 3.12
source .venv/bin/activate # On Windows: .venv\Scripts\activate# Install core + dev dependencies
uv sync --group dev
# For testing specific models, install their dependencies.We use ruff for code formatting and linting. To format your code:
# Check formatting
uv run ruff check .
uv run ruff format --check .
# Fix formatting
uv run ruff check --fix .
uv run ruff format .Or use the convenience script:
# Check formatting
python scripts/format_code.py check
# Fix formatting
python scripts/format_code.py fix# Run all tests
uv run pytest
# Run specific test file
uv run pytest tests/test_predict.py
# Run with coverage
uv run pytest --cov=sahi- Create a new branch:
git checkout -b feature-name - Make your changes
- Format your code:
python scripts/format_code.py fix - Run tests:
uv run pytest - Commit with clear message:
git commit -m "Add feature X" - Push and create PR:
git push origin feature-name
If the CI build fails due to formatting:
-
Check the CI output for the specific Python version that failed
-
Create environment with that Python version:
uv venv --python 3.X # Replace X with the version from CI source .venv/bin/activate
-
Install dev dependencies:
uv sync --group dev
-
Fix formatting:
python scripts/format_code.py fix
-
Commit and push the changes
To add support for a new detection framework:
- Create a new file under
sahi/models/your_framework.py - Implement a class that inherits from
DetectionModel - Add your framework to
MODEL_TYPE_TO_MODEL_CLASS_NAMEinsahi/auto_model.py - Add tests under
tests/test_yourframework.py - Add a demo notebook under
docs/notebooks/inference_for_your_framework.ipynb - Update
README.mdand related docs underdocs/to include your new model
See existing implementations like sahi/models/ultralytics.py for reference.
Feel free to start a discussion if you have questions!