This guide provides instructions for setting up the development environment for the Story Protocol Python SDK.
- Python 3.10 or higher
- Git
- uv - Fast Python package installer and resolver
uv is a fast Python package installer and resolver written in Rust. It's a drop-in replacement for pip and pip-tools.
curl -LsSf https://astral.sh/uv/install.sh | shpowershell -c "irm https://astral.sh/uv/install.ps1 | iex"pip install uvgit clone https://github.com/storyprotocol/python-sdk.git
cd python-sdk# Create a virtual environment
uv venv
# Activate the virtual environment
# On macOS/Linux:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate# Install the package in editable mode with all dependencies
uv pip install -e .
# Install additional development dependencies
uv pip install pytest pytest-cov black isort ruff pre-commit python-dotenv# Install pre-commit hooks
pre-commit install
# Run pre-commit on all files to ensure everything is set up correctly
pre-commit run --all-files# Run all integration tests (default)
pytest
# Run unit tests with coverage
coverage run -m pytest tests/unit -v -ra -q
coverage report
# Run specific test file
pytest tests/integration/test_integration_ip_asset.py -v
# Run tests with specific markers
pytest -m integration # Run only integration tests
pytest -m unit # Run only unit testsThe project uses several tools to maintain code quality:
-
Black - Code formatter
black . -
isort - Import sorter
isort . --profile black -
Ruff - Fast Python linter
ruff check . --fix
All these tools are automatically run as pre-commit hooks when you commit code.
mypy .To manually run all pre-commit checks:
pre-commit run --all-filesTo run a specific hook:
pre-commit run black --all-files
pre-commit run ruff --all-filesThe project uses the following pre-commit hooks:
| Hook | Purpose |
|---|---|
trailing-whitespace |
Removes trailing whitespace |
end-of-file-fixer |
Ensures files end with a newline |
check-yaml |
Validates YAML syntax |
check-added-large-files |
Prevents large files from being committed |
check-json |
Validates JSON syntax |
check-merge-conflict |
Checks for merge conflict markers |
check-toml |
Validates TOML syntax |
debug-statements |
Checks for debugger imports |
mixed-line-ending |
Normalizes line endings |
black |
Formats Python code |
isort |
Sorts Python imports |
ruff |
Lints Python code and auto-fixes issues |
# Add to setup.py's install_requires, then:
uv pip install -e .# Upgrade specific package
uv pip install --upgrade package-name
# Upgrade all packages
uv pip install --upgrade -e .uv is significantly faster than pip:
- Installation: 10-100x faster than pip
- Resolution: More efficient dependency resolver
- Caching: Better cache utilization
Create a .env file in the project root for local development:
WALLET_PRIVATE_KEY=your_private_key_here
RPC_PROVIDER_URL=https://aeneid.storyrpc.io-
Ensure all tools are installed:
uv pip install black isort ruff pre-commit
-
Update pre-commit hooks:
pre-commit autoupdate
-
Clear pre-commit cache:
pre-commit clean
-
Ensure you're in the virtual environment:
which python # Should point to .venv/bin/python -
Reinstall in editable mode:
uv pip install -e .
If uv is not working properly:
- Try installing via pip:
pip install uv - Ensure it's in your PATH:
which uv - On Windows, restart your terminal after installation
Before submitting a pull request:
- Ensure all tests pass:
pytest - Run pre-commit checks:
pre-commit run --all-files - Update tests if adding new functionality
- Follow the existing code style and patterns
See CONTRIBUTING.md for more details.