xmartlabs / python-template

10 stars 0 forks source link

Xmartlabs Python Template

python version fastAPI version

Components

Project setup

You only need to install Docker and Docker Compose. To start the containers, just run docker-compose up (or docker-compose up -d if you want to run the containers in background); or docker-compose create and docker-compose start if you don't want to see the logs. Once the containers are running, you can go to http://localhost:8000/docs to see the automatic interactive API documentation.

Migrations

We use Alembic as database migration tool. To run its commands you can open an interactive shell inside the backend container (you can use ./exec.sh bash shortcut), or use the following shortcuts under the /scripts directory:

Code tools

Linters, formatters, etc.

There is a shortcut under the /scripts directory that runs all this tools for you (./exec.sh format).

Screenshot

Tests

We use FastAPI's TestClient and pytest for testing. ./exec.sh test shortcut can be used to run all tests.

Shell

There is a shortcut under the /scripts directory that opens a python interactive shell inside the docker container. It's ./exec.sh shell and has some useful pre-imported stuff:

Screenshot

Admin

The template includes an admin interface via SQLAdmin. It's a flexible admin that can be configured in many ways.

One note: You should be careful when adding relationships to the list or detail pages (specially large many-to-many / one-to-many relationships), because it's not very optimal in terms of DB querys in those cases (all the related objects would be loaded in memory).

Screenshot