devcontainer-examples/python-fastapi-postgres-ai at main · reaktor/devcontainer-examples · GitHub
Skip to content

Latest commit

 

History

History

Folders and files

README.md

Python FastAPI PostgreSQL AI

This example uses a custom Dockerfile and docker-compose.yml to provide a Python development container with a PostgreSQL service.

It is intended as a starting point for a repository that will contain a FastAPI application with a local PostgreSQL database.

Included

  • Python 3.12 on Debian Bookworm slim, built through Dockerfile
  • Git, OpenSSH client, and PostgreSQL client tools
  • uv for Python dependency management
  • Node.js 22 LTS for AI CLI installation
  • PostgreSQL 17 in a separate Compose service
  • PostgreSQL credentials for local development:
    • database: app
    • username: postgres
    • password: postgres
    • host from the app container: postgres
    • connection string: postgresql+asyncpg://postgres:postgres@postgres:5432/app
  • VS Code extensions:
    • Codex - OpenAI's coding agent: openai.chatgpt
    • Claude Code for VS Code: Anthropic.claude-code
    • Python, Pylance, Ruff, and SQLTools PostgreSQL support
  • CLIs installed by scripts/post-create.sh:
    • Codex CLI: @openai/codex
    • Claude Code CLI: @anthropic-ai/claude-code
  • Startup database readiness check through scripts/post-start.sh

Files

  • devcontainer.json: devcontainer configuration, VS Code customizations, and lifecycle commands
  • Dockerfile: app container image with Python, Node.js, uv, and database client tools
  • docker-compose.yml: app container plus PostgreSQL service
  • scripts/post-create.sh: installs AI CLIs and optionally Python dependencies after the container is created
  • scripts/post-start.sh: waits for PostgreSQL and verifies the connection

There is no initializeCommand script in this example because no host-side initialization is required.

Use

Copy all files from this folder into a target repository's .devcontainer/ folder, then rebuild or reopen the project in a devcontainer-compatible editor.

The workspace itself is mounted at /workspace. The devcontainer does not create application source code automatically, so it is safe to copy into an existing repository.

For a new project, create the application files after the container starts. Example commands:

uv init
uv add fastapi "uvicorn[standard]" sqlalchemy[asyncio] asyncpg alembic

Both AI CLIs require authentication before use:

codex
claude

The PostgreSQL service stores data in the named Compose volume postgres-data. Remove that volume if you need to reset the local database.