This template is a complete Visual Studio Code devcontainer for developing Python applications that use PostgreSQL.
In addition to Python and PostgreSQL, this template contains:
- Poetry for packaging and dependency management
- Ruff for unified linting and black-compatible formatting
- An example project that uses Litestar and SQLAlchemy
The purpose of this template is more for the environment itself plus pre-configured Poetry, Ruff, etc. than the example application. The example demonstrates a simple (but functional) CRUD flow for API <-> SQLAlchemy <-> PostgreSQL. The project's file structure is inspired by domain-driven design and is overkill for the example.
If you would like to learn more about designing and structuring Litestar/FastAPI applications, I recommend giving FastAPI Best Practices a read.
-
Clone this repository:
git clone https://github.com/Jawfish/python-template.git
-
Open the repository in Visual Studio Code:
cd python-template code .
-
Copy
.env.example
to.env
. The example environment variables are for the example project and will work out of the box. -
Open the command palette and select
Remote-Containers: Reopen in Container
. This will build the devcontainer and open the project in a container. This may take a few minutes the first time.poetry install
will be run automatically when the container is built to install the project dependencies. -
To run the example application, open a terminal in VSCode and run:
poetry run app
This will start the application on port 8000. VSCode's integrated devcontainer functionally should forward this port for host access. Head to http://localhost:8000/schema/swagger to see the API documentation for the example application.
Configuration for the devcontainer can be managed in .devcontainer/devcontainer.json
. This file is used by VSCode to build the devcontainer (in addition to Dockerfile
and docker-compose.yml
). Everything there should be relatively self-explanatory.