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 (default: host=127.0.0.1, port=8000)
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.12.tar.gz (46.0 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.12-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fextapi-0.1.12.tar.gz
Algorithm Hash digest
SHA256 5bfa169ce73d9dd28b2f3e7d64c37854bda0eef07cfa739a4f4442cd45cb9da8
MD5 c6fccc9cfb4499be25d11aba23e068b5
BLAKE2b-256 a88fef2982617aeddb22a050322bc9fd32d063c9d02c35a331be42cca027933c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fextapi-0.1.12-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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 094ca8a99bfdd90b3d4cb2adc7d07d4e5cbe8af4c77555db6cfaa611e647a097
MD5 1c4aa2a88da740e26303f958a7d3bc01
BLAKE2b-256 55607de6ad0a05fb41ec205dbf706190648bd266ee34acdb9334274fb1dd1feb

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