Jawfish / python-template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python+PostgreSQL development virtual environment template

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:

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.

Getting Started

  1. Clone this repository:

    git clone https://github.com/Jawfish/python-template.git
  2. Open the repository in Visual Studio Code:

    cd python-template
    code .
  3. Copy .env.example to .env. The example environment variables are for the example project and will work out of the box.

  4. 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.

  5. 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

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.

About

License:MIT License


Languages

Language:Python 93.2%Language:Dockerfile 6.8%