This guide walks through setting up a new Python project using mise for Python version management, uv for fast dependency management, and pyproject.toml for project configuration.
- mise installed on your system
- uv installed on your system
- Basic familiarity with Python and virtual environments
mkdir my-project
cd my-projectCreate a .mise.toml file in your project root to specify the Python version:
[tools]
python = "3.12" # or your preferred versionmise trust
mise installThis will install the Python version specified in your .mise.toml file.
uv venvThis creates a .venv directory with your virtual environment.
source ./.venv/bin/activateYou should see (.venv) appear in your terminal prompt, indicating the virtual environment is active.
Create a pyproject.toml file for your project configuration:
[project]
name = "my-project"
version = "0.1.0"
description = "A brief description of your project"
requires-python = ">=3.12"
dependencies = [
# Add your runtime dependencies here
]
[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
"black>=23.0.0",
"ruff>=0.1.0",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"uv syncThis will:
- Read your
pyproject.toml - Create a
uv.lockfile with pinned versions - Install all dependencies (including dev dependencies) into your virtual environment
If you want to sync without dev dependencies:
uv sync --no-devOnce your project is set up, here's the typical workflow:
# Enter project directory
cd my-project
# Activate virtual environment
source ./.venv/bin/activate
# Sync dependencies (updates based on pyproject.toml)
uv sync
# Add a new dependency
uv add requests
# Add a dev dependency
uv add --dev pytest-cov
# Remove a dependency
uv remove requests
# Run your code
python your_script.py
# Deactivate when done
deactivateTo add a new dependency, you have two options:
uv add package-nameThis will automatically update your pyproject.toml and uv.lock file.
- Add it to the
dependenciesarray inpyproject.toml - Run
uv syncto install it
Don't forget to create a .gitignore file:
.venv/
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
dist/
*.egg-info/
# Note: uv.lock should typically be committed to track exact versions
# Only add it to .gitignore if you have a specific reason not to commit it