Loading repository data…
Loading repository data…
SamsWebs / repository
Django + Django Ninja template for public REST APIs on AWS Lambda with API Gateway v2
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
This is a template for creating a public REST API using Django, Django Ninja, and AWS Lambda with API Gateway. It is intended to be used as a starting point for new projects.
This template is written in Python 3.9 and uses the Django Ninja framework for handling HTTP requests/responses. Our API is stateless, has no database, and is intended to run ephemerally on serverless environments (currently AWS Lambda via API Gateway v2). We achieve this by wrapping our ASGI application with Mangum, an ASGI adapter for AWS Lambda. You can still develop locally by running Django's built-in development server.
python -m venv .venv && source .venv/bin/activatepip install -r requirements-dev.txt..envrc via cp .envrc.example .envrc and fill in the necessary environment variables. This file type assumes you are using direnv to manage your environment variables. If you are not, export the variables in your shell or use a different method.python -m django runserver --settings=app.settings.Enable git hooks by running pre-commit install --hook-type pre-commit --hook-type pre-push in the root of your project.
On every commit:
ruff format — formats code (Black-compatible)ruff check --fix — lints and auto-fixes imports, style, annotations, and moreOn every push:
pytest — runs the full test suite and blocks the push if any tests failYou can also run these manually at any time:
ruff format app/ specs/ # format
ruff check app/ specs/ # lint
pytest # test
pytest --cov=app --cov-report term # test with coverage
Important things to note:
/api/docs.Run the test suite with:
pytest
Run the linter with:
ruff check .
This template is intended to be deployed to AWS Lambda via API Gateway v2. You can deploy your code by running the push-images-and-update-lambda.yml GitHub Action. A pre-requisite is the necessary infrastructure to be set up in AWS via the Terraform code in the .infrastructure directory. This will create the necessary resources for your Lambda function to run. Please see the README in the .infrastructure directory for more information.
For the GitHub Action to work, you will need to set up the necessary secrets in your repository:
AWS_ACCOUNT_ID - Your AWS account IDAWS_ACCESS_KEY_ID - Your AWS access key IDAWS_SECRET_ACCESS_KEY - Your AWS secret access key