π A modern, production-ready Python development environment using VS Code DevContainers with UV package management and comprehensive code quality tools.
This template provides a complete, containerized Python development environment that works consistently across different machines and operating systems. Perfect for teams who want to standardize their development setup and onboard new developers quickly.
- Python 3.12 - Latest stable Python version
- UV Package Manager - Lightning-fast Python package installer and resolver
- PEP 621 Compliant - Modern
pyproject.tomlconfiguration - Development Dependencies - Pre-configured with essential dev tools
- VS Code DevContainer - Complete development environment in a container
- Docker Compose Setup - Multi-service architecture ready for databases, OTEL collectors, and other services
- Cross-platform Support - Works on Intel, AMD, and Apple Silicon
- Instant Setup - Zero configuration required for new team members
- Ruff - Ultra-fast Python linter and formatter (replaces Black + isort + flake8)
- MyPy - Static type checking for better code reliability
- Pre-commit Hooks - Automated code quality checks before commits
- Security Scanning - Bandit for security vulnerability detection
- Secret Detection - Prevent accidental commits of sensitive data
- Rich Extensions - Python, Ruff, MyPy, GitLens, GitHub Copilot, and more
- IntelliSense - Advanced code completion and navigation
- Debugging Support - Full debugging capabilities pre-configured
- Integrated Terminal - All tools available in the integrated terminal
- Docker Compose Ready - Easily add databases, message queues, OTEL collectors, and other services
- Service Networking - Pre-configured backend network for service communication
- Environment Configuration - Flexible environment variable management
- Development Scaling - Support for complex local development scenarios
- Quick Start
- Prerequisites
- Installation
- Usage
- Project Structure
- Development Tools
- Code Quality
- Configuration
- Adding Services
- Troubleshooting
- Contributing
- License
- Click "Use this template" button at the top of this repository
- Clone your new repository:
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name - Open in VS Code and select "Reopen in Container" when prompted
- Start coding! π
Before you begin, ensure you have the following installed:
- Docker Desktop (Latest version)
- VS Code (Latest version)
- Dev Containers Extension for VS Code
- Operating System: Windows 10/11, macOS, or Linux
- Memory: 8GB RAM minimum (16GB recommended)
- Storage: 10GB free space minimum
- Architecture: x86_64 or ARM64 (Apple Silicon supported)
git clone https://github.com/yourusername/python-devcontainer.git
cd python-devcontainercode .When VS Code opens, you'll see a notification:
"Folder contains a Dev Container configuration file. Reopen folder to develop in a container"
Click "Reopen in Container" or:
- Press
F1β Type "Dev Containers: Reopen in Container" - Use Command Palette:
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS)
The first time will take a few minutes to:
- Download the base Docker images
- Install Python dependencies
- Configure VS Code extensions
- Set up the development environment
# Test the sample application
python main.py
# Expected output:
# Hello from python-devcontainer!# Install a new package
uv add requests
# Install development dependency
uv add --dev pytest
# Install from lock file
uv sync
# Update dependencies
uv lock --upgrade
# Show installed packages
uv pip list# Run linting
ruff check .
# Auto-fix issues
ruff check --fix .
# Format code
ruff format .
# Type checking
mypy main.py
# Run all pre-commit hooks
pre-commit run --all-files
# Security scan
bandit -r .python-devcontainer/
βββ .devcontainer/
β βββ devcontainer.json # VS Code DevContainer configuration
β βββ Dockerfile # Python development environment
β βββ docker-compose.yml # Multi-service setup
β βββ setup.sh # Post-creation setup script
β βββ .env.example # Environment variables template
βββ .pre-commit-config.yaml # Pre-commit hooks configuration
βββ pyproject.toml # Python project configuration
βββ uv.lock # Dependency lock file
βββ main.py # Sample Python application
βββ README.md # This file
| Tool | Purpose | Configuration |
|---|---|---|
| UV | Package management | pyproject.toml |
| Ruff | Linting & formatting | pyproject.toml |
| MyPy | Type checking | pyproject.toml |
| Bandit | Security scanning | pyproject.toml |
| **PyUpgrade | automatically upgrade syntax | pyproject.toml |
| Pre-commit | Git hooks | .pre-commit-config.yaml |
Pre-installed extensions for the best development experience:
- Python - Python language support
- Ruff - Python linting and formatting
- MyPy Type Checker - Static type checking
- Python Typehint - Enhanced type hint support
- Python Indent - Correct Python indentation
- IntelliCode - AI-assisted development
- GitLens - Enhanced Git capabilities
- GitHub Copilot - AI pair programming
- TODO Tree - Task management
This template enforces code quality through multiple layers:
- File checks: Large files, merge conflicts, YAML/TOML syntax
- Security: Private key detection, secret scanning
- Python: AST validation, debug statement detection
- Formatting: Trailing whitespace, end-of-file fixes
- Code Quality: Ruff linting and formatting
- Ruff: Comprehensive linting (replaces flake8, isort, and more)
- MyPy: Static type checking for better code reliability
- Bandit: Security vulnerability scanning
All tools are configured in pyproject.toml:
[tool.ruff]
line-length = 88
target-version = "py312"
[tool.mypy]
python_version = "3.12"
strict = true
[tool.bandit]
exclude_dirs = ["tests"]The template includes an .env.example file for environment variable configuration. Copy and customize it for your needs:
cp .devcontainer/.env.example .devcontainer/.envAdd your environment variables to the .env file:
# Example environment variables
API_KEY=your_api_key_here
DATABASE_URL=postgresql://user:pass@host:port/dbname
DEBUG=true# Production dependency
uv add package-name
# Development dependency
uv add --dev package-name
# Optional dependency group
uv add --group group-name package-nameCustomize VS Code settings in .devcontainer/devcontainer.json:
{
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python"
},
"extensions": [
"ms-python.python"
]
}
}
}This template uses Docker Compose, making it easy to add additional services for local development. The setup includes a pre-configured backend network for service communication.
Add a PostgreSQL database to your docker-compose.yml:
services:
python-devcontainer:
# ... existing configuration ...
depends_on:
- postgres
postgres:
image: postgres:15
environment:
POSTGRES_DB: myapp
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- backend
volumes:
postgres_data:services:
# ... existing services ...
redis:
image: redis:7-alpine
ports:
- "6379:6379"
networks:
- backendservices:
# ... existing services ...
otel-collector:
image: otel/opentelemetry-collector:latest
command: ["--config=/etc/otel-collector-config.yml"]
volumes:
- ./otel-collector-config.yml:/etc/otel-collector-config.yml
ports:
- "8888:8888" # Prometheus metrics
- "8889:8889" # Prometheus exporter metrics
- "13133:13133" # health_check extension
- "4317:4317" # OTLP gRPC receiver
- "4318:4318" # OTLP HTTP receiver
networks:
- backendServices can communicate using their service names as hostnames:
# Connect to PostgreSQL from Python container
import psycopg2
conn = psycopg2.connect(
host="postgres", # Service name as hostname
port=5432,
database="myapp",
user="postgres",
password="postgres"
)
# Connect to Redis
import redis
r = redis.Redis(host="redis", port=6379, db=0)# Rebuild container
Ctrl+Shift+P β "Dev Containers: Rebuild Container"
# Or rebuild without cache
Ctrl+Shift+P β "Dev Containers: Rebuild Container Without Cache"# Reinstall all packages
uv sync --refresh
# Clear UV cache
uv cache clean# Check all container status
docker ps
# View logs for specific service
docker logs python-devcontainer-<service-name>-1
# Restart specific service
docker restart python-devcontainer-<service-name>-1
# Check network connectivity
docker network ls
docker network inspect python-devcontainer_backend# Fix file permissions
sudo chown -R $USER:$USER .- Enable Docker BuildKit for faster builds
- Allocate more memory to Docker (8GB recommended)
- Use SSD storage for better I/O performance
- Close unnecessary VS Code windows to save resources
- Use Docker volumes for data that needs to persist
We welcome contributions! Please see our contributing guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Run tests and quality checks:
pre-commit run --all-files - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow PEP 8 style guidelines (enforced by Ruff)
- Add type hints to all functions
- Write tests for new functionality
- Update documentation as needed
- Ensure all quality checks pass
This project follows the Contributor Covenant Code of Conduct.
- VS Code DevContainers
- UV Package Manager
- Ruff Linter
- Pre-commit Hooks
- Docker Compose
- Python Type Hints
- β‘ Zero setup time - Start coding immediately
- π§ Best practices built-in - Modern tooling pre-configured
- π‘οΈ Quality assurance - Automated checks prevent issues
- π Learning opportunity - Discover modern Python tooling
- π― Consistent environments - Same setup for everyone
- π Faster onboarding - New team members productive in minutes
- π₯ Better collaboration - Shared tooling and standards
- π Security by default - Built-in security scanning
- ποΈ Production-ready - Follows industry best practices
- π Scalable foundation - Easy to extend and customize
- π§ͺ Testing-friendly - Set up for comprehensive testing
- π¦ Deployment-ready - Container-based development to production
- π³ Multi-service ready - Easy integration with databases, caches, and other services
This project is licensed under the MIT License - see the LICENSE file for details.
- UV Team for the amazing package manager
- Astral for Ruff and the excellent Python tooling
- Microsoft for VS Code and DevContainers
- Docker for containerization technology
- Python Community for the incredible ecosystem
Made with β€οΈ for the Python community