Skip to content

litestar-org/litestar-pg-redis-docker

Repository files navigation

Warning

This repository has not been updated recently and will be receiving some TLC. Please see: Discord discussion on litestar-pg-redis-docker

If you would like to help, feel free to discuss in Discord or open a pull request.

Litestar Logo - Light Litestar Logo - Dark

Quality Gate Status Coverage Technical Debt Maintainability Rating Reliability Rating Vulnerabilities Bugs

Discord Matrix Reddit

litestar-pg-redis-docker

This is an example Litestar project using SQLAlchemy + Alembic + postgresql, Redis, SAQ and Docker.

Litestar

Litestar is a light and flexible ASGI API framework.

Litestar documentation 📚

Run the application

Setup

  • $ cp .env.example .env
  • $ docker compose build
  • $ docker compose run --rm app alembic upgrade head

Run

$ docker compose up --build

Async Worker Emails

To demonstrate usage of the asynchronous SAQ workers, when an Author is created we trigger a worker function that sends an email.

mailhog is included in docker-compose.yaml, and includes a GUI that can be accessed at http://localhost:8025.

Create an Author:

$ curl -w "\n" -X POST -H "Content-Type: application/json" -d '{"name": "James Patterson", "dob": "1974-3-22"}' http://localhost:8000/v1/authors
{"id":"6f395bdf-3e77-481d-98b2-3471c2342654","created":"2022-10-09T23:18:10","updated":"2022-10-09T23:18:10","name":"James Patterson","dob":"1974-03-22"}

Then check the mailhog GUI to see the email that has been sent by the worker.

Development

Install pre-commit hooks

  • pre-commit install

Migrations

Revision

$ docker compose run --rm app alembic revision --autogenerate -m "revision description"

Migration

$ docker compose run --rm app alembic upgrade head