Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

🐍 Python Development Container

Modern Python development environment with latest tools, linting, and popular frameworks

📋 Overview

This development container provides a complete Python development environment with:

  • ✅ Python 3.12
  • ✅ FastAPI (pre-installed)
  • ✅ Django, Flask support (optional)
  • ✅ Linting and formatting (Black, isort, flake8, pylint)
  • ✅ Testing with pytest
  • ✅ Poetry package manager
  • ✅ Type checking with mypy

🚀 Quick Start

  1. Open in VS Code

    code .
  2. Reopen in Container

    • Press F1Dev Containers: Reopen in Container
  3. Create your first project

    FastAPI:

    # main.py already configured
    uvicorn main:app --reload --host 0.0.0.0 --port 8000

    Flask:

    pip install flask
    flask run --host 0.0.0.0 --port 5000

    Django:

    pip install django
    django-admin startproject myproject
    cd myproject
    python manage.py runserver 0.0.0.0:8000

🛠️ Included Tools

Python Runtime

  • 🐍 Python 3.12 - Latest stable Python

Code Quality

  • Black - Code formatter
  • 🔀 isort - Import sorter
  • 📏 Flake8 - Linter
  • 🔍 Pylint - Static analyzer
  • 🔤 MyPy - Type checker

Testing

  • pytest - Testing framework
  • 📊 pytest-cov - Coverage plugin
  • pytest-asyncio - Async testing

Package Managers

  • 📦 pip - Default package manager
  • 🎭 poetry - Modern dependency manager

Web Frameworks

  • FastAPI - Modern async API framework (pre-installed)
  • 🌐 Django - Full-featured web framework (optional)
  • 🧪 Flask - Micro web framework (optional)

Development Tools

  • 💻 IPython - Enhanced REPL
  • 🐛 ipdb - Debugger

📦 VS Code Extensions

  • ms-python.python - Python language support
  • ms-python.vscode-pylance - Fast language server
  • ms-python.black-formatter - Black formatter
  • ms-python.isort - Import organizer
  • ms-python.flake8 - Linter
  • njpwerner.autodocstring - Docstring generator
  • visualstudioexptteam.vscodeintellicode - AI-assisted IntelliSense

🎨 Customization

Multi-Stage Dockerfile

The Dockerfile is organized in stages:

  1. base - Python 3.12 base image
  2. dev-tools - Linting, formatting, testing tools
  3. frameworks - Web frameworks (customize here!)
  4. tools - Additional utilities, poetry
  5. development - Final dev environment
  6. production - Minimal production runtime

Enable Additional Frameworks

Edit .devcontainer/Dockerfile at the frameworks stage:

FROM dev-tools AS frameworks
# Django
RUN pip install django djangorestframework celery

# Flask
RUN pip install flask flask-restful flask-sqlalchemy

# Data Science
RUN pip install numpy pandas scikit-learn matplotlib seaborn jupyter

💡 Usage Examples

Create a Virtual Environment

python -m venv venv
source venv/bin/activate

Using Poetry

# Initialize new project
poetry init

# Add dependencies
poetry add fastapi uvicorn

# Install dependencies
poetry install

# Run in poetry environment
poetry run python main.py

Install Packages

# Using pip
pip install requests pandas numpy

# Using poetry
poetry add requests pandas numpy

# Install from requirements.txt
pip install -r requirements.txt

Run Web Servers

# FastAPI (with auto-reload)
uvicorn main:app --reload --host 0.0.0.0 --port 8000

# Flask
flask run --host 0.0.0.0 --port 5000

# Django
python manage.py runserver 0.0.0.0:8000

Testing

# Run tests
pytest

# Run with coverage
pytest --cov=.

# Run specific test file
pytest tests/test_example.py

# Run with verbose output
pytest -v

Code Quality

# Format code with Black
black .

# Sort imports
isort .

# Lint with flake8
flake8 .

# Analyze with pylint
pylint your_module

# Type check with mypy
mypy .

🐛 Debugging

Press F5 and select:

  • Python: Current File - Debug current file
  • Python: FastAPI - Debug FastAPI application
  • Python: Flask - Debug Flask application
  • Python: Django - Debug Django application

📊 Project Structure

your-project/
├── .devcontainer/
│   ├── devcontainer.json
│   └── Dockerfile
├── .vscode/
│   ├── settings.json
│   └── launch.json
├── src/
│   └── your_module/
├── tests/
├── requirements.txt
├── pyproject.toml  # For poetry
└── README.md

🔧 Common Commands

Command Description
python main.py Run Python script
pip list List installed packages
pip freeze > requirements.txt Export dependencies
python -m pytest Run tests
black . Format code
flake8 . Lint code
mypy . Type check

🌐 Ports

  • 8000 - FastAPI/Django default
  • 5000 - Flask default

📚 Resources

🤝 Contributing

Feel free to customize this container for your specific needs!


Happy Coding! 🎉