Coder Social home page Coder Social logo

whenessel / fast-api-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hulvdan/fast-api-template

0.0 0.0 0.0 241 KB

Having fun with pre-commits, FastAPI, Dependency Injection and Clean Architecture

Shell 1.59% Python 91.63% Makefile 1.69% Mako 0.69% Dockerfile 4.40%

fast-api-template's Introduction

fast-api-template

Русский язык Русский язык

Rationale

I decided to create this project for enlightening purposes to spread the application of good practices for running and maintaining a Python project.

Best-practices, used in this project

This framework makes it much easier to work with hooks in git.

It can be used to set up a number of commit quality checks - ranging from formatting, linking, code validity, to the messages of those commits.

This is an uncompromising python file formatter, which in my opinion is better, than the alternatives autopep8 and yapf.

I have not been able to get them to work together with isort, so I have to live with black's PEP8 violations.

A tool for sorting imports in python files.

A static code analyzer from the world of Python. It allows you to use type annotations for premature code validation.

If there is invalid python code, for example:

from typing import Any
def sum_str_and_int(string: str, number: int) -> Any:
    return string + number

Then mypy will generate the following error:

$ mypy .
a.py:3: error: Unsupported operand types for + ("str" and "int")
Found 1 error in 1 file (checked 1 source file)

If you take into account that mypy can be strictly customized, you can be sure that the repository won't leak obviously broken code, that the developer may have been careless.

In my practice, using mypy greatly reduces the number of such errors during refactoring and reworking of existing functionality.

Flake8 is a linter. Linters help to keep the code consistent and easy to understand. Flake8 functionality is extended by adding plugins that introduce new code validation rules.

I'm a firm believer that at this moment poetry is the best manager of python packages.

If you don't use poetry... use poetry...

Clean Architecture

There were a lot of discussions about Clean Architecture. I believe, this is a thing that every developer should know, but don't be too fanatical about it.

Dependency Injection

Dependency injection is an approach that allows an object to receive other objects on which it depends at the design stage.

For some reason this approach is not actively used in Python projects, although it is far from being a novelty in programming.

The punq library was chosen and slightly modified as a DI solution.

I made this decision after watching a presentation by Alexander Shibaev, Tinkoff. In it he reviewed the existing python libraries and frameworks, that allow the use of DI and explained why they settled on punq.

Further reading

You can enjoy the clean architecture by navigating to the folder backend

Development

Initial configuration after cloning the repository

Configuration of the development environment is performed with a single command: make.

It will install and configure pre-commit.

fast-api-template's People

Contributors

hulvdan avatar

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.