LuisBrime / ngr

FastAPI example to use on AWS Lambda

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SVG Blob from Blobmaker

NGR

master codecov Code style: black Imports: isort

FastAPI project example made for deployment with AWS Lambda.

Run locally πŸ’»

  1. Install dev dependencies with Makefile

This will install dependencies found at requirements-dev.txt and requirements.txt.

make install-dev
  1. Install an ASGI server, for example Uvicorn:
pip install uvicorn
  1. 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

Structure πŸ“

.
β”œβ”€β”€ 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 folder v1 contains the files for the routes of the API's first version.
    • db/: Contains handler for the fake DB. All data is contained on data.json generated with JSON-Generator.
  • tests/: Contains all the tests for the source code, it mimics the structure of ngr.

Commands πŸ› 

This project uses a Makefile to easily run commands for installation, format, lint, etc.

  • make venv: Generates a Python venv so you can install dependencies without making Python go crazy. Note that after running you need to run source venv/bin/activate to activate it.
  • make install: Installs all core dependencies of the project located in requirements.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.

Deploy to Lambda πŸš€

Follow my tutorial on Medium.

About

FastAPI example to use on AWS Lambda

License:MIT License


Languages

Language:Python 78.7%Language:Makefile 21.3%