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.11.tar.gz (45.9 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.11-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fextapi-0.1.11.tar.gz
Algorithm Hash digest
SHA256 ba97d920199714e2eeb6fc8e26b045c00fbffa9e79fe7634a2059b5974e20e68
MD5 e2fd2d6b43fba62db4b47ffaf19ff02b
BLAKE2b-256 e01d6232e9985f6f4f5c134741a89c263fd305614991f0dcec3691ad93bd6524

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fextapi-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 611dc1d1d7622bb67947a9e1ab05937302301143d5fba0d6075e56e9d069eceb
MD5 f0a492d6aeaa15a26d51d520e3f88faf
BLAKE2b-256 2903c72603b11bf7680a1c18b782558fef6fe74c39f288d3ec07b8f42f4409c8

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