FastAPI project example made for deployment with AWS Lambda.
- Install dev dependencies with Makefile
This will install dependencies found at requirements-dev.txt
and requirements.txt
.
make install-dev
- Install an ASGI server, for example Uvicorn:
pip install uvicorn
- Run the server locally:
This will run the API locally and if you change anything in the code reload it.
uvicorn ngr.main:app --reload
.
βββ ngr/
βββ api/
βββ v1/
βββ bodies.py
βββ db/
βββ data.json
βββ db.py
βββ main.py
βββ tests/
βββ api/
βββ conftest.py
ngr/
: Contains all the FastAPI source code.api/
: Contains the API routes, within the folderv1
contains the files for the routes of the API's first version.db/
: Contains handler for the fake DB. All data is contained ondata.json
generated with JSON-Generator.
tests/
: Contains all the tests for the source code, it mimics the structure ofngr
.
This project uses a Makefile to easily run commands for installation, format, lint, etc.
make venv
: Generates a Pythonvenv
so you can install dependencies without making Python go crazy. Note that after running you need to runsource venv/bin/activate
to activate it.make install
: Installs all core dependencies of the project located inrequirements.txt
.make install-dev
: Installs all dependencies required to run project locally and run the tests, as well as core dependencies.make test
: Installs dependencies, lints and runs tests for the project.make format
: Formats all the files on the project using isort and black.make lint
: Lints project using flake8 and checks format.make clean
: Cleans all cached files and folders.
Follow my tutorial on Medium.