This guide explains how to use py_template to start your own Python project.
- Clone/fork this repository
- Rename the package directory
- Update pyproject.toml
- Update all imports
- Customize or remove example modules
- Update documentation
- Initialize your git repository
- Start developing!
Option A: GitHub Template (Recommended)
- Click "Use this template" on GitHub
- Create your new repository
- Clone your repository
Option B: Manual Clone
git clone <this-repo-url> my-awesome-project
cd my-awesome-project
rm -rf .git # Remove template's git history
git init # Start freshManual Renaming:
-
Rename directory:
mv src/py_template src/my_package
-
Update pyproject.toml:
name = "my_package" [tool.hatch.version] path = "src/my_package/__version__.py" [tool.hatch.build.targets.wheel] packages = ["src/my_package"] [project.scripts] my_cli = "my_package.cli.commands:main"
-
Update all imports (use find & replace):
# Find all occurrences grep -r "py_template" src/ tests/ # Replace in all Python files find src tests -name "*.py" -type f -exec sed -i '' 's/py_template/my_package/g' {} +
-
Update Docker files:
- Dockerfile: Update paths and usernames
- docker-compose.yml: Update service names and commands
Update pyproject.toml:
[project]
name = "my-awesome-project"
description = "Your project description here"
authors = [{ name = "Your Name", email = "your.email@example.com" }]
keywords = ["your", "keywords", "here"]
dependencies = [
"pydantic>=2.11.5",
"click>=8.1.0",
# Add your dependencies here
]Update src/my_package/__version__.py:
__version__ = "0.1.0"Update LICENSE:
- Replace with your chosen license
- Update copyright holder
The template includes an example service module:
src/py_template/services/
Option A: Keep and Extend
If the service pattern fits your domain, keep it and add your implementations:
from py_template.services import BaseService
class MyService(BaseService):
def execute(self, data):
# Your service logic
return resultOption B: Replace
Rename it to match your domain (e.g., handlers/, controllers/, models/, etc.)
Option C: Remove
If you don't need it:
rm -rf src/my_package/services
# Update src/my_package/__init__.py to remove BaseService exportEdit src/my_package/cli/commands.py:
@click.group()
@click.version_option(version=__version__, prog_name="my-cli")
def main():
"""My Awesome CLI Tool."""
# Add your commands
@main.command()
def my_command():
"""My custom command."""
click.echo("Hello from my command!")# Remove old virtual environment
rm -rf .venv
# Install with new configuration
uv sync --extra dev
# Install pre-commit hooks
uv run pre-commit install
# Test your CLI
uv run my-cli --version
uv run my-cli --help
# Run tests
uv run pytest- README.md: Update with your project's purpose and usage
- docs/api.md: Document your API
- docs/development.md: Update development instructions
- Remove this file: Delete
docs/TEMPLATE_USAGE.mdonce setup is complete
git add .
git commit -m "Initial commit from py_template"
git branch -M main
git remote add origin <your-repo-url>
git push -u origin main-
Secrets (for GitHub Actions):
- No secrets needed for basic CI
- Add
CODECOV_TOKENfor coverage reporting (optional)
-
Branch Protection (optional):
- Protect
mainbranch - Require PR reviews
- Require status checks to pass
- Protect
-
Enable Workflows:
- Go to Actions tab
- Enable workflows if needed
# Add runtime dependency
uv add requests
# Add development dependency
uv add --dev mypy
# Update lock file
uv lockEdit pyproject.toml:
[tool.ruff]
line-length = 120 # Change line length
[tool.ruff.lint]
ignore = ["E501"] # Ignore specific rulesEdit .pre-commit-config.yaml to add/remove hooks.
Create new files in .github/workflows/:
name: My Custom Workflow
on:
push:
branches: [main]
jobs:
custom:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Add your stepsIf you need database support:
-
Add dependencies:
uv add sqlalchemy alembic # or asyncpg, psycopg2, etc. -
Create
src/my_package/db/module -
Add database configuration
-
Update Docker Compose to include database service
To convert this into a web API:
-
Add FastAPI:
uv add fastapi uvicorn
-
Create
src/my_package/api/module -
Update Dockerfile to expose ports
-
Update CLI to include
servecommand
# Clear Python cache
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
# Reinstall
rm -rf .venv
uv sync --extra dev# Run hooks manually to see details
uv run pre-commit run --all-files
# Update hooks
uv run pre-commit autoupdate# Clear Docker cache
docker builder prune -a
# Rebuild without cache
docker build --no-cache -t my-project:dev .Here's a complete example of converting this template into a FastAPI project:
# Step 1: Clone and rename
git clone <template-repo> my-api
cd my-api
mv src/py_template src/my_api
# Step 2: Add FastAPI
uv add fastapi uvicorn
# Step 3: Update imports
find src tests -name "*.py" -exec sed -i '' 's/py_template/my_api/g' {} +
# Step 4: Update pyproject.toml
# ... edit file ...
# Step 5: Create API module
mkdir src/my_api/api
cat > src/my_api/api/main.py << 'EOF'
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello World"}
EOF
# Step 6: Update CLI to add serve command
# ... edit src/my_api/cli/commands.py ...
# Step 7: Test
uv sync --extra dev
uv run uvicorn my_api.api.main:app --reload- Check Development Guide for workflow details
- Review Project Standards for code conventions
- Open an issue on the template repository for template-specific questions
Once setup is complete:
- Write your first feature
- Add tests for your feature
- Update documentation
- Create your first release
Happy coding!