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 fastapifromfrictionless

For environments that run the generated app (FK query endpoints, geo field types):

pip install "fastapifromfrictionless[app]"

Windows

The base install works on Windows without any prerequisites.

The [app] extra includes geoalchemy2, which requires GDAL. If your schemas use geographic field types, install GDAL first:

GDAL installation guide for Windows

Then install the extra:

pip install "fastapifromfrictionless[app]"

If your schemas do not use geo fields, pip install fastapifromfrictionless is sufficient and no GDAL install is needed.

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.scaffolding 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
POST /{resource}s/bulk Create many records in a single request (one commit)
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 (required) All requests require X-API-Key: <value> header. App refuses to start if unset unless ALLOW_NO_AUTH=true is also set.
ALLOW_NO_AUTH (unset) Set to true to start the app without API_KEY (dev only — logs a warning, do not use in production)
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.runtime import (
    empty_excel, create_package, update_api_from_package, dump_to_excel
)

# 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
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 container deployment lives in podman/. It spins up three containers — PostGIS database, pgAdmin web UI, and the generated FastAPI app — and works with Docker Desktop, Podman, or any docker compose-compatible tool on Linux, macOS, and Windows.

Multiple deployments can run simultaneously on the same machine by assigning each a unique SUBNET_BASE and port set (API_PORT, PGADMIN_PORT, DB_PORT).

The API image uses a two-stage build: Stage 1 installs the code-generator and produces FastAPI source from your schemas; Stage 2 installs only the runtime dependencies and serves the generated app. The pip install layer is cached, so schema-only rebuilds are fast.

cd podman/
cp .env.example .env          # set ports, passwords, and settings
# add *.schema.yaml files to schemas/
docker compose up -d          # or: podman-compose up -d

After schema changes, re-run docker compose build api then docker compose up -d api. To stop and clean up, run docker compose down.

See podman/README.md for full instructions.

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.19.tar.gz (29.6 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.19-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapifromfrictionless-0.2.19.tar.gz
  • Upload date:
  • Size: 29.6 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.19.tar.gz
Algorithm Hash digest
SHA256 f57a60be36c4c2ea96464a324ae188d41f5460b1b6ec03429df4e5096a589c41
MD5 d0a00bfeaed7ae1fd4db0a1a5e91a00e
BLAKE2b-256 a810c7c6e0efaa914778ce3ab267a6cfc61ec3c032d74ca283f5da39d183a3b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapifromfrictionless-0.2.19.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.19-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapifromfrictionless-0.2.19-py3-none-any.whl
Algorithm Hash digest
SHA256 785823188eeaf5b1024d2bd220dc791814cad2c1159d71d0ab7ea43982fd787f
MD5 500f08a4b7dc2859f75f7f881b2df62e
BLAKE2b-256 c2962a360a56271fef01b409e511541a4986a48ef19387f910fe05bb62d2b7ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapifromfrictionless-0.2.19-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