Skip to content

Brief demonstration of the integration between three tools: FastAPI, BeanieORM, DependencyInjector

License

Notifications You must be signed in to change notification settings

zhavir/python_fastapi_dependency_injection_beanie_template

Repository files navigation


ToDo List

Summary

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Structure
  5. Contributing
  6. Contact

About The Project

(back to top)

Built With

  • python
  • fastapi
  • beanie
  • dependencyInjector

(back to top)

Getting Started

The project is based on Poetry. Here you can find how to install and configure your local environment with poetry:

  • poetry
    curl -sSL https://install.python-poetry.org | python3 -

Docker

The service is already exported in Dockerfile and can easly be built through docker-compose. It will be setup with all their dependecies

docker compose up --build

for convenience, if you want to run natively the service and their dependencies dockerized you need to update your hosts file with

127.0.0.1    mongodb 

(back to top)

Usage

Swagger page is accessible at http://localhost:8080

(back to top)

Structure

src/
├─ core/
├─ models/
│  ├─ domain/
│  ├─ orm/
│  ├─ schemas/
├─ routers/
│  ├─ v1/
├─ services/
├─ utilities/
tests/
├─ unit/
├─ integration/

The application is strongly based on Dependency injection. All the dependency are then declared and instantiated inside the container.py. It means that dependencies are never instantiated directly, but they are passed into the constructor or the method signature by the framework

The folder structure follow the following logic:

  • Routers: definition of all the endpoints of the application, they can also be versioned and stored in different paths.
    • they can call only services
    • they can return only schema object
    • they do not execute any sort of business logic
    • they only validate input coming though the endpoint and then return the related schema response (after calling the underlying layer)
  • Services: definition of the business logic of the application
    • they can call only repositories and utility classes
    • a service cannot reference another service
    • a service works and returns a domain object
  • Repository: Abstraction layer for the database framework
    • they can only manipulate orm objects
    • the orm object must be mapped to a domain object before returning anything
    • it is the only layers allowed to manipulate data on database
    • a repository cannot reference another repository
routers (domain) -> service (domain) -> repository (orm)
routers (schema) <- service (domain) <- repository (domain) 

Contributing

Project use:

You can run formatting though pre-commit before commiting code to the remote

pre-commit run 

run the tests with

pytest

(back to top)

Contact

(back to top)

About

Brief demonstration of the integration between three tools: FastAPI, BeanieORM, DependencyInjector

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published