A minimal Python project template using uv - an extremely fast Python package and project manager, written in Rust.
Just clone this repo, install uv with pip install uv and run uv run main
project_name/
├── pyproject.toml # Project configuration and dependencies
├── src/
│ └── project_name/ # Must match name in pyproject.toml
│ ├── __init__.py
│ ├── main.py # Main entry point
│ └── moduleA/ # Package name
│ ├── __init__.py
│ └── operations.py # Module
│
├── tests # Tests location: uv run pytest
├── uv.lock # Exact dependency versions (auto-created by uv)
└── .venv/ # Virtual environment (auto-created by uv)pyproject.toml: Central configuration file defining your project, dependencies, and scriptsuv.lock: Lock file that pins exact dependency versions for reproducible buildssrc/project_name/: Source code directory following Python packaging standards.venv/: Virtual environment automatically created and managed by uv
uv is a modern Python package and project manager designed to be a faster, simpler alternative to traditional tools like pip and virtualenv. It:
- Automatically manages virtual environments - no more manual
venvcreation - Resolves dependencies faster - up to 10-100x faster than pip
- Uses modern standards - fully compliant with PEP 621 (pyproject.toml)
| Traditional Workflow | uv Workflow |
|---|---|
python -m venv .venv |
uv sync |
source .venv/bin/activate |
(automatic) |
pip install -r requirements.txt |
(handled by uv sync) |
python script.py |
uv run python script.py |
pip install uv# In your project root
uv syncWhat uv sync does:
- Creates a virtual environment (
.venv/) - Installs all dependencies from
pyproject.toml - Updates the
uv.lockfile with exact versions
# Run the main script
uv run src/project_name/main.py
# Run any module
uv run python -m project_name.main
uv run python -m project_name.moduleA.operationsWhy use uv run?
- Automatically uses the project's virtual environment
- No need to manually activate/deactivate environments
- Works consistently across different operating systems
Define convenient scripts (aliases) in pyproject.toml:
[project.scripts]
main = "project_name.main:main"
moduleA = "project_name.moduleA.operations:main"Run them directly:
# Run the main script
uv run main
# Run the moduleA script
uv run moduleA# Option 1: Run as a module
python -m project_name.main
# Option 2: Run the Python file directly
python src/project_name/main.pyNote: For direct execution, make sure you've activated the virtual environment first:
# macOS and Linux
source .venv/bin/activate
# Windows (Command Prompt)
.venv\Scripts\activate
# Windows (PowerShell)
.venv\Scripts\Activate.ps1uv makes dependency management simple and intuitive.
# Add multiple packages at once
uv add requests pytest
# Add as development dependencies
uv add --dev pytestWhat happens when you add a package:
- Updates
pyproject.tomlwith the new dependency - Updates
uv.lockwith the exact version - Installs the package in the virtual environment
# Remove a package
uv remove requests
# Remove development dependencies
uv remove --dev pytest# Update all dependencies to latest compatible versions
uv sync --upgrade
# Update a specific package
uv add --upgrade requests
# Update only dev dependencies
uv sync --upgrade --dev# List all installed packages
uv pip list
# Show dependency tree
uv pip tree
# Check for outdated packages
uv pip list --outdatedReminder: uv run <cmd> will run the <cmd> in the virtual environment but not load the environment into the terminal.
If desired, to activate the virtual environment check the uv docs for linux, windows, fish.
uv run pip -> uses the .venv
pip -> uses the main python environment
source .venv/bin/activate && pip -> pip now uses the .venv
# Create a new virtual environment
uv venv
# Use a specific Python version
uv venv --python 3.11
# Remove the virtual environment
uv venv --delete- Always use
uv syncafter cloning - ensures all dependencies are installed - Commit
uv.lockto version control - ensures reproducible builds - Use
uv addanduv remove- don't editpyproject.tomlmanually - Run commands with
uv run- avoids environment activation issues - Regularly update dependencies -
uv sync --upgradeto get security updates
If you encounter issues:
- Check uv documentation: https://docs.astral.sh/uv/
- Run with verbose output:
uv --verbose sync - Check for known issues: https://github.com/astral-sh/uv/issues
Build you package as a .whl or .exe
# Package your application
uv build
# Create a standalone executable
uv pip install PyInstaller
uv run python -m PyInstaller --onefile src/project_name/main.py