File-system based routing for FastAPI
Project description
fextapi
File-system based routing for FastAPI - Build APIs like Next.js App Router
๐ 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โ/apiapp/products/route.pyโ/productsapp/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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bfa169ce73d9dd28b2f3e7d64c37854bda0eef07cfa739a4f4442cd45cb9da8
|
|
| MD5 |
c6fccc9cfb4499be25d11aba23e068b5
|
|
| BLAKE2b-256 |
a88fef2982617aeddb22a050322bc9fd32d063c9d02c35a331be42cca027933c
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
094ca8a99bfdd90b3d4cb2adc7d07d4e5cbe8af4c77555db6cfaa611e647a097
|
|
| MD5 |
1c4aa2a88da740e26303f958a7d3bc01
|
|
| BLAKE2b-256 |
55607de6ad0a05fb41ec205dbf706190648bd266ee34acdb9334274fb1dd1feb
|