This is a walkthrough of the steps taken to write a small application in fastapi using the fastapi cookiecutter
- cookicutter For Project templating
- cookiecutter-fastapi For project templating
- poetry For dependency management
- black for code formatting
- isort python import sorting and formatting
Downloading cookiecutter dependencies
pip install cookiecutter black isort
Run the cookiecutter and Select Project Options
As you can see there are a lot of options to choose from so lets back up and explain each one:
project_name
Is the common name of your projectproject_slug
Is the name of your project as you would see it in a python import statement or URL with no special punctuation save underscores and hyphensproject_description
Be specific but also brief. This will be used to initialize your README.mdauthor
That's You! make sure to include an email you can be reached at by fellow contributors and userscopyright_year
Choose the current yearlicense
I always select MIT for public open source projects, but for a quick explanation of the differences see this explanation from attorney Joseph Morris- Selecting a Database is a much more important choice and will influence the way you build the rest of your application. The cookiecutter exposes two options to you tortoise and beanie. Tortoise is a traditional ORM for relational databases similar to the Django ORM, but with async support. This allows you to quickly map records in a SQL database to python objects. Whereas beanie is used with document-style databases such as MongoDB. I will be going forward with tortoise because I plan to use PostgreSQL later on in this example.
use_sentry
Sentry is used for error monitoring and I will set up an example configuration later in this articlemail_service
the cookiecutter includes templating for sending emails via SMTP. If you are an amazon SES user feel free to select this option but for this example, we will be using GMailrender_html
Optionally use Jinja for HTML rendering. We will not be selecting this for our purposes. Spoiler we will be building a Vue frontend application for this API.use_docker
We will be using docker for our production deployment. This will containerize our application and make and standardize the environment in which our application will run.use_heroku
For our initial production deployments, we will be using Heroku