---
name: python-rest-api-builder
description: "Turns an endpoint list and data model definitions into a runnable Python REST API starter: app file, models, requirements.txt, and config, that starts with pip install and python app.py. Use when an endpoint list and data model lines need turning into the smallest runnable Python API starter that starts with python app.py. Do not use for a full production project layout with OpenAPI and async, or a lone FastAPI endpoint. Related topics: coding, python."
---

# Python REST API Builder

Turns an endpoint list and data model definitions into a runnable Python REST API starter: app file, models, requirements.txt, and config, that starts with pip install and python app.py.

## When to use

Use this skill when an endpoint list and data model lines need turning into the smallest runnable Python API starter that starts with python app.py. Do not use it for a full production project layout with OpenAPI and async, or a lone FastAPI endpoint.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Turn each data model line into a class for the chosen framework and database with the field names and types unchanged.
3. Map every endpoint to a handler that does the obvious operation for its method with 201, 204, 400, and 404 handled.
4. Apply the chosen auth as one decorator or dependency on every endpoint except the credential-issuing one.
5. Default the database to a local connection from an environment variable and pin compatible versions in requirements.txt.
6. Make app.py start the dev server on port 8000 and output the tree plus every file in fenced blocks headed by path.

## Inputs

- **API name** (free text, e.g. "MyAPI")
- **Framework** (choose one: Flask, FastAPI, Django REST)
- **Endpoints (one per line as /path METHOD)** (longer free text)
- **Authentication** (choose one: None, JWT, API Key, OAuth2)
- **Database** (choose one: SQLite, PostgreSQL, MySQL, MongoDB, None)
- **Data models** (longer free text)

## Output

A markdown document with the folder tree and the full content of app.py, the models file, config, and requirements.txt in fenced blocks headed by their paths, runnable with pip install -r requirements.txt and python app.py.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Python REST API Builder

Build a runnable REST API starter project from my endpoint list and data models.

- API name: {{API name}}
- Framework: {{Framework}}
- Endpoints (one per line as /path METHOD): {{Endpoints (one per line as /path METHOD)}}
- Authentication: {{Authentication}}
- Database: {{Database}}
- Data models: {{Data models}}

Aim for the smallest project that runs, not the most complete. Parse the data models into classes for the chosen framework and database (ORM models plus schemas, or plain dataclasses when there is no database) and keep the field names and types exactly as given. Map every endpoint to a handler that does the obvious thing for its method and path: list or fetch for GET, create for POST with 201, update for PUT and PATCH, delete with 204; return 404 for a missing id and 400 for a body that fails the model's types. Apply the chosen auth as one decorator or dependency on every endpoint except the one that issues credentials. Default the database to a local file or local connection string from an environment variable so it runs with no setup. Pin the dependencies in requirements.txt to versions that work together. Make app.py the entry point that starts the dev server on port 8000. Return a markdown document with the folder tree and the full content of every file (app.py, models, config, requirements.txt) in fenced blocks headed by their paths, ready to copy into a directory and run with pip install -r requirements.txt and python app.py.

## Pitfalls

- Leaving requirements.txt unpinned, so the starter breaks the first time a major version of the framework ships.
- Requiring a running PostgreSQL or Mongo before the app starts, when a local default would let it run immediately.
- Renaming or retyping the model fields to look conventional, which breaks the client code the user already wrote against them.
