Modern Python development workflow using uv for project management, code formatting, docstring generation with numpy style, and code optimization. Use when creating new Python projects, formatting code, optimizing existing Python code, managing dependencies, or setting up development environments.
This skill provides a complete modern Python development workflow using uv for fast project management, code formatting with ruff, numpy-style docstring generation, and code quality assurance.
uv init my-project
cd my-project
# Initialize with specific Python version
uv init my-project --python 3.11
# Create library structure
uv init my-library --lib
# Add common development dependencies
uv add --dev pytest ruff mypy black coverage pre-commit
# Add production dependencies
uv add requests pandas fastapi
# Format all code (replaces black)
uv run ruff format .
# Check formatting without changes
uv run ruff format . --check
# Sort imports
uv run ruff check . --select I --fix
# Run all linting checks
uv run ruff check .
# Auto-fix issues where possible
uv run ruff check . --fix
# Check specific rules (e.g., imports)
uv run ruff check . --select I,E,W,F
# Run type checking
uv run mypy src/
# Type check with specific config
uv run mypy . --strict
# Run tests
uv run pytest
# Run with coverage
uv run coverage run -m pytest
uv run coverage report
uv run coverage html
Use numpy-style docstrings for all functions and classes:
def process_data(data: pd.DataFrame, threshold: float = 0.5) -> pd.DataFrame:
"""
Process dataframe by filtering and transforming values.
Parameters
----------
data : pd.DataFrame
Input dataframe to process
threshold : float, default 0.5
Filtering threshold value
Returns
-------
pd.DataFrame
Processed dataframe
Examples
--------
>>> df = pd.DataFrame({'values': [0.1, 0.7, 0.3]})
>>> result = process_data(df, threshold=0.4)
>>> len(result)
2
"""
class DataProcessor:
"""
Data processing utility class.
Provides methods for cleaning, transforming, and analyzing
pandas DataFrames with configurable parameters.
Parameters
----------
config : dict
Configuration parameters for processing
Attributes
----------
threshold : float
Processing threshold value
processed_count : int
Number of processed items
Examples
--------
>>> processor = DataProcessor({'threshold': 0.5})
>>> result = processor.process(data)
"""
# 1. Start development
uv sync # Install/update dependencies
# 2. During development
uv run ruff format . # Format code
uv run ruff check . --fix # Fix linting issues
uv run mypy src/ # Type check
# 3. Before commit
uv run pytest # Run tests
uv run coverage run -m pytest && uv run coverage report
# 4. Run application
uv run -m mymodule
uv run src/main.py
my-project/
├── pyproject.toml
├── README.md
├── .gitignore
├── src/
│ └── my_project/
│ ├── __init__.py
│ ├── main.py
│ └── utils.py
├── tests/
│ ├── __init__.py
│ └── test_main.py
└── docs/
└── README.md
# Add dependencies
uv add package-name
uv add --dev dev-package
# Remove packages
uv remove package-name
# Update dependencies
uv sync --upgrade
# Show dependency tree
uv tree
# Create virtual environment
uv venv
# Activate environment
source .venv/bin/activate # Linux/Mac
.venv\Scripts\activate # Windows
# Run in environment
uv run script.py
uv run pytest
# One-command quality check
uv run ruff format . && uv run ruff check . --fix && uv run mypy src/ && uv run pytest
uv init my-app --python 3.11
cd my-app
uv add --dev pytest ruff mypy coverage
uv add requests fastapi uvicorn
echo "pytest\nruff\ncoverage" > requirements-dev.txt
# Install pre-commit
uv add --dev pre-commit
# Create .pre-commit-config.yaml
cat > .pre-commit-config.yaml << EOF