Django REST Framework backend generator: schema to REST API
Auxen, by Auxen Prime, generates a Django REST Framework (Python) backend from your database schema or a plain-English description. The output is an ordinary Django REST Framework project that you download and own. Install the requirements and run it with manage.py or Gunicorn.
What you get
The table is read from a real generated project (83 files for the example schema). The last column is the file in that project.
| Area | What is generated | Where in the project |
|---|---|---|
| REST API | Create, read, update and delete endpoints for each entity, under /api/<entity> | example_app/views/customer_view.py |
| Authentication | Registration and login with JWT in this example. The builder also offers OAuth2, Session, API Key, Basic Auth and OpenID Connect. | example_app/views/auth_views.py |
| RBAC | Role and permission tables, and a permission check on the protected routes | example_app/permissions/rbac_permission.py |
| Migrations | An initial migration for the schema | sql/V1__initial_schema.sql |
| Tests | 3 test files in the example (unit and integration) | tests/test_customer.py |
| Dockerfile | Builds the image and runs the app as a non-root user (uid 10001) | Dockerfile |
| docker-compose | Runs the app with a PostgreSQL database beside it | docker-compose.yml |
| CI pipeline | A GitHub Actions workflow, when you choose it | .github/workflows/ci.yml |
| API description | An OpenAPI description of the API | example_app/urls.py |
| Health check | A health endpoint | example_app/urls.py |
| Configuration | An .env.example listing the settings | .env.example |
The example it was generated from
Entities Customer and Invoice, with Invoice many-to-one Customer, on PostgreSQL, JWT with RBAC. Options: unit tests, integration tests, Docker, GitHub Actions pipeline and migrations. Auxen adds the authentication tables (users, roles, permissions, sessions and others) around them.
.github/workflows/ 1 file
docs/ 2 files
example_app/ 63 files
example_app/authentication/ 2 files
example_app/management/ 3 files
example_app/middleware/ 3 files
example_app/models/ 8 files
example_app/permissions/ 3 files
example_app/queries/ 14 files
example_app/serializers/ 8 files
example_app/services/ 5 files
example_app/utils/ 2 files
example_app/views/ 9 files
sql/ 1 file
tests/ 6 files
(project root) 10 filesReal excerpts
example_app/views/customer_view.pyclass CustomerViewSet(viewsets.ModelViewSet):
"""
ViewSet for Customer CRUD operations.
Permissions required (when auth is enabled):
- CUSTOMER_READ: list, retrieve
- CUSTOMER_CREATE: create
- CUSTOMER_UPDATE: update, partial_update
- CUSTOMER_DELETE: destroy
"""
queryset = Customer.objects.all()
serializer_class = CustomerSerializer
permission_classes = [HasEntityPermission]
# Entity name for permission checkingexample_app/permissions/rbac_permission.pyclass HasPermission(BasePermission):
"""
Custom permission class for RBAC.
Usage: permission_classes = [IsAuthenticated, HasPermission]
Set required_permissions attribute on the view.
"""
def has_permission(self, request, view):
# Get required permissions from view
required_permissions = getattr(view, 'required_permissions', None)
if not required_permissions:sql/V1__initial_schema.sqlCREATE TABLE IF NOT EXISTS "customer" (
customer_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
customer_name VARCHAR(255) NOT NULL,
customer_email VARCHAR(255) UNIQUE NOT NULL,
customer_birthday DATE,
customer_active BOOLEAN NOT NULL,
customer_gender VARCHAR(255) NOT NULL,
customer_notes TEXT,
customer_created_at TIMESTAMP NOT NULL
);DockerfileFROM python:3.11-slim
# The root filesystem is read-only under the Helm chart: write no __pycache__.
ENV PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# The app's migrations are made from its models here, when the image is built
# (the root filesystem is read-only at run time). A project that keeps its own
# migrations gets only what its models changed since. The build reads no real
# database: SQLite in memory, and a throwaway key settings.py insists on.
RUN SECRET_KEY=build-only DB_ENGINE=django.db.backends.sqlite3 DB_NAME=:memory: \
python manage.py makemigrations example_app --noinput
# Run as an unprivileged user (uid and gid 10001) that owns /app.
RUN groupadd --system --gid 10001 app && useradd --system --no-create-home --gid app --uid 10001 app && chown -R app:app /app
USER 10001:10001tests/test_customer.pyclass TestCustomer:
def test_create(self, api):
row = api.create(Customer)
assert row["customer_id"]
def test_list(self, api):
row = api.create(Customer)
res = api.get(f"{PATH}/")
assert res.status_code == 200, res.content
assert row["customer_id"] in [item["customer_id"] for item in res.json()["results"]]
def test_get_by_id(self, api):What it is built on
Read from the generated manifest: Django (requirements.txt), Django REST framework (requirements.txt), SimpleJWT (requirements.txt), drf-spectacular (OpenAPI) (requirements.txt), pytest (requirements-dev.txt).
Databases
Django REST Framework generates for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle and Amazon Redshift. It does not generate for MongoDB.
How the generator is tested
These checks live in the Auxen repository and run against the generators themselves. They are listed here as what they do, not as a guarantee about every schema you might write.
- Generation test (npm run test:gen): generates this stack for several example schemas, then checks the syntax of the result with Python.
- Runtime test (npm run test:runtime): starts the generated application, connects it to a real database, registers a user, logs in, then creates and lists records over HTTP.
- Security scan: the generated project, including its Dockerfile and CI files, is scanned with Trivy for vulnerabilities, secrets and misconfiguration. The check fails on any secret, and on any high or critical finding that has a fix.
- Docker build test (npm run test:docker, run on demand): builds each stack's own Dockerfile.
Running and deploying it
Install the requirements and run it with manage.py or Gunicorn. You download the project and deploy it wherever you run software. Auxen does not deploy the generated backend for you yet. It has a hosted sandbox where you can run the code and try its API before you download it.
Review the code before it carries real traffic, as you would any code you did not write. The terms of service say the same: generated code is provided as is, and you are responsible for reviewing, testing and securing it.
More
- Backend generator How Auxen works across all stacks.
- Schema to REST API The example schema and the generated routes.
- Pricing Free to use, with paid plans for credits and the sandbox.
- User guide Step by step, from schema to download.
- Spring Boot generator Java output.
- Kotlin Spring Boot generator Kotlin output.
- NestJS generator TypeScript output.
- FastAPI generator Python output.
- Laravel generator PHP output.
- .NET (ASP.NET Core) generator C# output.
- Go Gin generator Go output.
- Express.js generator TypeScript or JavaScript output.
Auxen is made by Auxen Prime Technologies Limited and lives at auxenprime.com. It is not affiliated with other companies that use the name Auxen.