Awesome
Template for private python service
This is a cookiecutter template for an internal REST API service, written in Python, inspired by layout-golang. The stack is based on FastAPI and uvicorn and runs on docker and docker-compose.
Service layout
Below is the 1000ft structure of project's modules. Here, red ones are private, green ones are public. Package consists of both public and private sources.
We have some modules:
- Package. Publish to pypi registry
- Server. Server has some submodules for configuration handlers, logging and exceptions. Server has all business logic.
- Integration tests. Integration tests communicate with server as black box. You can read differences between unit and integration tests here
Notice. Bad practice to import any function from server module.
Read more on the project's main principles here. you can also read more on our approach here.
Service
Our service has built-in:
- prometheus endpoint
- vault-client
- healthcheck
- docker and docker-compose for local development and deploying
- isolated docker development
- loguru for logging
- autogeneration of README.md for your service
- swagger from FastAPI /docs
- FastAPI as service
- Uvicorn as asgi server
- console server
- templates for unit and integration tests
- interface for control your service via makefile
- completely to publishing package (private pypi-registry)
- completely to publishing dockerfile (private docker-registry)
- basic token (api-key) authentication
Usage
To use this project, you need to install cookiecutter:
pip install cookiecutter
cookiecutter https://github.com/U-Company/python-private-service-layout.git
Next, you need to have docker
and docker-compose
:
sudo apt-get install make docker.io docker-compose
Here you cand find all available commands for communicate with service with a command line.
If you have any errors, you can read about in documentary after project generation. You can communicate with Egor Urvanov by UrvanovCompany@yandex.ru or in telegram (@egor_urvanov)
For the full tutorial of service generation you can read here.
Execution and infrastructure
To deploy service WITHOUT dependencies, just run the docker-compose from the root via make:
make run
To deploy service WITH dependencies, just run the docker-compose from the root via make:
make run-full
(Default deployment is based on infrastructure)
That's it! Enjoy