This is an example Starlite project using SQLAlchemy + Alembic + postgresql, Redis, SAQ and Docker.
Starlite is a light and flexible ASGI API framework.
$ cp .env.example .env
$ docker-compose build
$ docker-compose run --rm app alembic upgrade head
$ docker-compose up --build
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.
pre-commit install
$ docker-compose run --rm app alembic revision --autogenerate -m "revision description"
$ docker-compose run --rm app alembic upgrade head
To run the tests, have tox
installed and on your path. I recommend pipx
which is a tool for
installing python applications in isolated environments.
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install tox
You'll now be able to run $ pipx run tox
, but that's still a little verbose. I choose to add an
alias for this, e.g.,:
# ~/.bashrc
# ...
alias tox="pipx run tox"
Close and reopen your shell, or $ source ~/.bashrc
to get the alias working in your current shell.
tox -e lint
# run a specific hook
tox -e lint mypy
tox -e test
tox -e integration