Code Monkey home page Code Monkey logo

python-template's Introduction

Xmartlabs Python Template

python version fastAPI version

Components

  • Rest API built with FastAPI and SQLAlchemy
  • PostgreSQL database

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:

  • ./exec.sh migrate -> runs all the migrations
  • ./exec.sh makemigrations -> compares the actual status of the DB against the table metadata, and generates the migrations based on the comparison

Code tools

Linters, formatters, etc.

  • Pycln: Formatter for finding and removing unused import statements.
  • isort: Tool to sort imports alphabetically and automatically separate into sections by type.
  • flake8: Linting tool
  • mypy: Static type checker
  • black: PEP 8 compliant opinionated formatter

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:

  • session: A SQLAlchemy Session object
  • settings: An instance of the app settings class
  • All the SQLAlchemy models classes

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

python-template's People

Contributors

federicovallcorbax avatar jorgexmartlabs avatar jrg091 avatar pgrill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-template's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.