Skip to main content

Creating FastAPIs from Frictionless Data Packages

Project description

fastapi-from-frictionless

Status: Work in Progress — API and generated output are subject to change.

Overview

fastapifromfrictionless is a Python scaffolding tool that reads Frictionless Data Package schema files and generates a fully-functional FastAPI + SQLModel application — including models, CRUD endpoints, and dynamic query support — with no hand-written boilerplate.

The driving goal is to bridge the gap between familiar flat-file workflows (Excel workbooks, CSV files, Frictionless packages) and a production-grade relational database with a queryable REST API. Data stewards continue working in Excel; the package handles ingestion, validation, and API synchronization behind the scenes.

Core capabilities:

  • Generate models.py, app.py, and database.py from *.schema.yaml files
  • Automatic SQLModel class hierarchy per schema (base, table, create, update, public, public-with-relations)
  • Full CRUD + pagination + recent-records endpoints per resource
  • Excel workbook as a data-entry interface — create or update API records from a .xlsx file
  • Frictionless package wraps the workbook for field-level validation before ingestion
  • CLI entry point: fastapifromfrictionless generate <schema-folder>

Requirements

An ASGI server such as uvicorn is required to run the generated application.

Installation

pip install -e .

Quick Start

1. Generate application files from schemas

Place *.schema.yaml files in a folder (see doc/data/ for examples), then run:

fastapifromfrictionless generate path/to/schemas --output path/to/output

Or from Python:

from fastapifromfrictionless.load import build_database

build_database(schema_folder="path/to/schemas", db_filename="app.db")

2. Start the generated API

cd path/to/output
uvicorn app:app --reload

3. Generated endpoints

For each schema resource, the generated app exposes the following endpoints (replace {resource} with the schema name, e.g. sensor, location, permit):

Method Path Description
POST /{resource} Create a record
GET /{resource}/all List all (paginated: ?offset=0&limit=100)
GET /{resource}/recent Most recent records (?limit=10)
GET /{resource}/{id} Get one by primary key
PATCH /{resource}/{id} Update a record
DELETE /{resource}/{id} Delete a record
GET /{resource}/query Dynamic filter query (FK schemas only)
GET /excel/export Download all data as .xlsx
POST /excel/import Upload and sync an .xlsx workbook

4. Configuration via environment variables

Variable Default Description
DATABASE_URL sqlite:///database.db Database connection URL (overrides SQLite default)
ALLOWED_ORIGINS * Comma-separated CORS allowed origins
API_KEY (unset) If set, all requests require X-API-Key: <value> header
SCHEMA_FOLDER . Path to *.schema.yaml files (used by Excel import/export)
API_URL http://localhost:8000 Base URL of this app (used by Excel export)

5. Excel data workflow

from fastapifromfrictionless.load import empty_excel, create_package, update_api_from_package

# Create a blank workbook with one sheet per schema
empty_excel(schema_folder="path/to/schemas", output_filepath="data.xlsx")

# Fill in data, then validate and sync to the API
create_package(folder="path/to/schemas", filename="data.xlsx")
update_api_from_package(api_url="http://localhost:8000", package_file="data.package.yaml")

# Or export all current API data to Excel
from fastapifromfrictionless.load import dump_to_excel
dump_to_excel(api_url="http://localhost:8000", schema_folder="path/to/schemas", output_filepath="export.xlsx")

6. CLI reference

fastapifromfrictionless generate <schema_folder> [options]

Options:
  --output DIR      Output directory (default: current directory)
  --db FILENAME     SQLite database filename (default: database.db)
  --dry-run         Print generated code to stdout without writing files
  --no-models       Skip generating models.py
  --no-app          Skip generating app.py
  --no-db           Skip generating database.py

See doc/quickstart.ipynb for a step-by-step walkthrough of the full deployment workflow.

Deployment

A ready-to-use Podman deployment lives in podman/. It spins up three containers — PostGIS database, pgAdmin web UI, and the generated FastAPI app — with no manual setup beyond dropping schemas into a folder and filling in a .env file.

The API image uses a two-stage build: Stage 1 generates FastAPI code from your schemas; Stage 2 produces a lean runtime image. Both stages pull pre-built base images from ghcr.io, so only the copy and generation steps run locally — no pip installs required.

cd podman/
cp .env.example .env          # fill in passwords and settings
# add *.schema.yaml files to schemas/
podman-compose build api      # generate app code from your schemas (~20 s)
podman-compose up -d          # start all three containers

After schema changes, re-run podman-compose build api then podman-compose up -d api.

See podman/README.md for full instructions.

Roadmap

Items are grouped by priority. Checked items are complete.

Foundation

  • Generate SQLModel class hierarchies from Frictionless schemas
  • Generate FastAPI CRUD + query endpoints per resource
  • Generate database.py with SQLite engine setup
  • Excel workbook as data-entry interface (create and update)
  • Frictionless package wrapping for field-level validation
  • Export API data back to Excel (dump all records to workbook)
  • Validate schemas before code generation; surface clear error messages on malformed input

Code Quality & Reliability

  • Add a test suite (unit tests for generators, integration tests for generated app)
  • Add CI pipeline (lint, type-check, tests on push)
  • Enforce type hints throughout; run mypy in CI
  • Replace raw string generation with a templating engine (e.g. Jinja2) for maintainability
  • Structured logging with configurable verbosity

Production Readiness

  • Async database support (replace sync SQLModel sessions with async SQLAlchemy)
  • Database migrations via Alembic instead of create_all
  • Configuration management — accept settings via environment variables or a config file (database URL, allowed origins, etc.)
  • CORS and security headers in generated app.py
  • API key / token authentication (FastAPI security)
  • Pagination on list endpoints
  • Proper HTTP error responses with consistent JSON error bodies

Developer Experience

  • CLI entry point (fastapifromfrictionless generate <schema-folder>) so users do not need to write Python
  • Dry-run / preview mode that prints generated code without writing files
  • Configurable output — opt in/out of specific endpoint types, choose database backend
  • Package versioning and automated releases (GitHub Actions → PyPI)
  • Expand documentation and examples in doc/

Optional / Future

  • Support for PostgreSQL and other SQLAlchemy-compatible backends
  • Podman/container deployment (Compose stack with PostGIS, pgAdmin, and FastAPI; multi-stage Dockerfile with pre-built base images on ghcr.io for fast builds)
  • Auto-generated front-end form from schema fields
  • DrawIO ERD → Frictionless schema converter
  • Default query routes for common patterns derived from schema metadata
  • GET/POST file endpoints for uploading and downloading the Excel workbook directly via the API

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapifromfrictionless-0.2.3.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapifromfrictionless-0.2.3-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapifromfrictionless-0.2.3.tar.gz.

File metadata

  • Download URL: fastapifromfrictionless-0.2.3.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastapifromfrictionless-0.2.3.tar.gz
Algorithm Hash digest
SHA256 ca8a13492f4259b5e0553812e3cfaeabe5e364bdbfe0a1a52d286f1c62390931
MD5 7a8a5f050ac71f2ac73f7c0ab21344bc
BLAKE2b-256 89fb946e444f3f87cc5943ae22e42acfc5f8025b25c36880e80f25c2abb58ddd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapifromfrictionless-0.2.3.tar.gz:

Publisher: python-publish.yml on jinskeep-morpc/fastapi-from-frictionless

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastapifromfrictionless-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapifromfrictionless-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 389ba15f09588eeca1e91e89b79061bbb4b2f5926b1dbbab1247a50df0780da7
MD5 66921f54ab1ede16d52f54ee63e139ed
BLAKE2b-256 7ebe6461d9573144b31a5e5f8aa6468ca8340ed9cd8db5b6801f71915c57957e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapifromfrictionless-0.2.3-py3-none-any.whl:

Publisher: python-publish.yml on jinskeep-morpc/fastapi-from-frictionless

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page