FastAPI backend generator: schema to REST API
Auxen, by Auxen Prime, generates a FastAPI (Python) backend from your database schema or a plain-English description. The output is an ordinary FastAPI project that you download and own. Install the requirements and run it with Uvicorn.
What you get
The table is read from a real generated project (102 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> | app/routers/customer.py |
| Authentication | Registration and login with JWT in this example. The builder also offers OAuth2, Session, API Key, Basic Auth and OpenID Connect. | app/routers/auth.py |
| RBAC | Role and permission tables, and a permission check on the protected routes | app/dependencies/rbac.py |
| Migrations | An initial migration for the schema | alembic/versions/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 | app/main.py |
| Health check | A health endpoint | app/main.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
alembic/versions/ 1 file
app/ 84 files
app/core/ 2 files
app/dependencies/ 3 files
app/migrations/ 1 file
app/models/ 14 files
app/queries/ 14 files
app/repositories/ 14 files
app/routers/ 9 files
app/schemas/ 15 files
app/seeds/ 2 files
app/services/ 3 files
app/utils/ 4 files
docs/ 2 files
tests/ 5 files
(project root) 9 filesReal excerpts
app/routers/customer.py@router.get("/", response_model=PaginatedResponse)
@require_permission("CUSTOMER_READ")
def get_all(
page: int = Query(1, ge=1, description="Page number"),
limit: int = Query(20, ge=1, le=100, description="Items per page"),
sort_by: str = Query("customer_id", description="Field to sort by"),
sort_order: str = Query("asc", pattern="^(asc|desc)$", description="Sort order"),
db: Session = Depends(get_db), current_user: User = Depends(get_current_user)
):
# Get total count
total = db.query(Customer).count()
# Apply sorting (whitelist sort_by to prevent column injection)
safe_sort_by = sort_by if sort_by in SORTABLE_FIELDS else "customer_id"app/dependencies/rbac.pydef require_permission(permission_name: str):
"""
Route decorator that checks the authenticated user has the given permission
(matched by permission_name, e.g. "CUSTOMER_CREATE"); the ADMIN role bypasses.
The wrapped handler must declare current_user + db dependencies; they're
injected by FastAPI and read here from kwargs.
Usage:
@router.get("/")
@require_permission("CUSTOMER_READ")
async def get_all(..., db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
"""alembic/versions/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 . .
# 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:10001
EXPOSE 8000
# The port: PORT when the platform sets one (Heroku, Cloud Run), else 8000.
CMD ["sh", "-c", "exec uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8000}"]tests/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.text
assert row["customer_id"] in [item["customer_id"] for item in res.json()["data"]]
def test_get_by_id(self, api):What it is built on
Read from the generated manifest: FastAPI (requirements.txt), SQLAlchemy (requirements.txt), Pydantic (requirements.txt), PyJWT (requirements.txt), pytest (requirements-dev.txt).
Databases
FastAPI generates for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, MongoDB and Amazon Redshift.
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 Uvicorn. 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.
- Django REST Framework 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.