This is a template for creating microservices with FastAPI
.
This template uses cookiecutter for creating the project and provides a basic directory structure to create microservices, separating routers and API versioning.
The dependencies are handled with poetry
with fastapi
and uvicorn
packages pre-defined.
- Linux
- python
- poetry
- cookiecutter
Once cookiecutter
is installed, you can download this repository with it:
cookiecutter [email protected]:ArturLinnik/fastapi-microservice-template.git
Then, after filling the different fields that cookiecutter
needs, you have to enter to the new directory
cd <directory-name>
give permissions of execution to setup.sh
chmod +x setup.sh
execute setup.sh
and enter the virtual environment
./setup.sh && source .venv/bin/activate
In order to execute the example of the template you can run python3 run.py
.
Then, you can verify that it is working by opening in the browser http://localhost:8000/docs
.
-
If you haven't configured
ssh
in your machine you can usecookiecutter
with HTTPS -
You can install
cookiecutter
with:
pip install cookiecutter
- If
cookiecutter
is not in yout PATH you can either add it to your PATH
PATH=$PATH:$HOME/.local/bin
or use it like:
python -m cookiecutter ...
This way you will need to repeat the command every time you enter a new terminal, for avoiding that, you can put it in your .zshrc
or your .bashrc
.
- Artur Linnik
- @ArturLinnik