Skip to main content

File-system based routing for FastAPI

Project description

fextapi

File-system based routing for FastAPI - Build APIs like Next.js App Router

Python Version License: MIT

๐Ÿš€ Features

  • Zero Configuration - Automatically map folder structure to API routes
  • Developer Friendly - Use standard FastAPI syntax with no learning curve
  • Convention over Configuration - Organized project structure out of the box
  • CLI Tools - Initialize and run projects with simple commands
  • Type Safe - Full Python type hints and IDE support

๐Ÿ“ฆ Installation

# Using uv (recommended)
uv add fextapi

# Using pip
pip install fextapi

๐ŸŽฏ Quick Start

# Initialize a new project
fextapi init

# Start development server
fextapi run

# Visit http://127.0.0.1:8000/docs

๐Ÿ“ Project Structure

my-api-project/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ main.py               # FastAPI application entry point
โ”‚   โ”œโ”€โ”€ components/           # Business logic and reusable components
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ””โ”€โ”€ route.py          # GET /api
โ”‚   โ”œโ”€โ”€ products/
โ”‚   โ”‚   โ”œโ”€โ”€ route.py          # GET /products
โ”‚   โ”‚   โ”œโ”€โ”€ [productid]/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ route.py      # GET /products/{productid}
โ”‚   โ”‚   โ””โ”€โ”€ stats/
โ”‚   โ”‚       โ””โ”€โ”€ route.py      # GET /products/stats
โ””โ”€โ”€ pyproject.toml

๐Ÿ“ Usage Examples

main.py

from fastapi import FastAPI
from fextapi import init

app = FastAPI()

# Automatically register all routes
init(app)

products/route.py

from fastapi import APIRouter

router = APIRouter()

@router.get("/", tags=["products"])
async def list_products():
    return [
        {"id": 1, "name": "Product A"},
        {"id": 2, "name": "Product B"}
    ]

products/[productid]/route.py

from fastapi import APIRouter, HTTPException

router = APIRouter()

@router.get("/", tags=["products"])
async def get_product_detail(productid: str):
    if productid == "999":
        raise HTTPException(status_code=404, detail="Product not found")
    return {"id": productid, "name": f"Product {productid}"}

๐ŸŽจ Routing Rules

Static Routes

  • app/api/route.py โ†’ /api
  • app/products/route.py โ†’ /products
  • app/products/stats/route.py โ†’ /products/stats

Dynamic Routes

  • app/products/[productid]/route.py โ†’ /products/{productid}
  • app/users/[userid]/orders/[orderid]/route.py โ†’ /users/{userid}/orders/{orderid}

Route Priority

Static routes are matched before dynamic routes

When accessing /products/stats:

  • โœ… Matches /products/stats/route.py (static)
  • โŒ Skips /products/[productid]/route.py (dynamic)

๐Ÿ› ๏ธ CLI Commands

# Initialize new project
fextapi init

# Start development server
fextapi run

# Start server with custom host/port
fextapi run --host 0.0.0.0 --port 3000

# Disable auto-reload
fextapi run --no-reload

# Show help
fextapi help

# Show version
fextapi version

๐Ÿงช Requirements

  • Python 3.13+
  • FastAPI 0.100.0+
  • Uvicorn 0.20.0+

๐Ÿ“„ License

MIT License - see LICENSE for details

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

๐Ÿ”— Links

โญ Acknowledgments

Inspired by Next.js App Router and built with FastAPI.

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

fextapi-0.1.10.tar.gz (45.7 kB view details)

Uploaded Source

Built Distribution

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

fextapi-0.1.10-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file fextapi-0.1.10.tar.gz.

File metadata

  • Download URL: fextapi-0.1.10.tar.gz
  • Upload date:
  • Size: 45.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.11

File hashes

Hashes for fextapi-0.1.10.tar.gz
Algorithm Hash digest
SHA256 f41688bcc0b602770543579aca0d1f5405b2615cdb4bf3f4921230fec91cceb8
MD5 06bf179819d935813e8f522b49cc4806
BLAKE2b-256 1301a5afce37206969d0058a574fdd491fc15bce01b56a0df8e1caec5d706895

See more details on using hashes here.

File details

Details for the file fextapi-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: fextapi-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.11

File hashes

Hashes for fextapi-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 56235fca05570a517f2f1ade0c4fd1d327dfda9bdfc0e3d8d990bdbac2629cf8
MD5 ea5eaf2c94f2efc50aef24e3a11ff7bd
BLAKE2b-256 03873c6f20135d2b6bf02abb5939242f9784f51ec33e59a84b45a62a77b9aa4a

See more details on using hashes here.

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