Metadata-Version: 2.3
Name: fastapi-autoloader
Version: 0.1.2
Summary: MVC style router autoload
License: MIT
Keywords: fastapi,autoloader,dynamic-router,mvc,router,autoload
Author: Juan Borda
Author-email: juanignacioborda@gmail.com
Requires-Python: >=3.8,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: fastapi (>=0.116.1,<0.117.0)
Project-URL: Repository, https://github.com/juanitomint/fastapi-autoloader.git
Description-Content-Type: text/markdown

# fastapi-autoloader

A Python package for dynamic routing in FastAPI.

## Features

- Automatically loads and registers routers from your controllers directory.
- Supports multilevel directory structures (HMVC-style modules).
- Minimal configuration required.

## Installation

```sh
pip install fastapi-autoloader
```

## Usage

Suppose your project structure is:

```
example/
	main.py
	controllers/
		users/
			users.py
		orders/
			orders.py
```

Each controller module should define a FastAPI `APIRouter` named `router`:

**example/controllers/users/users.py**
```python
from fastapi import APIRouter

router = APIRouter()

@router.get("/users")
def list_users():
	return [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]
```

**example/controllers/orders/orders.py**
```python
from fastapi import APIRouter

router = APIRouter()

@router.get("/orders")
def list_orders():
	return [{"id": 1, "item": "Book"}, {"id": 2, "item": "Pen"}]
```

**example/main.py**
```python
from fastapi import FastAPI
from fastapi_dynamic_router import DynamicRouter

app = FastAPI()

# Automatically loads all routers from controllers/ and subdirectories
controllers = DynamicRouter("controllers")
controllers.load(app)

@app.get("/")
def root():
	return {"message": "Hello"}
```

## Running

Start your app with Uvicorn:

```sh
uvicorn example.main:app --reload
```

## How it works

- The package recursively scans the target directory (`controllers/` by default).
- For each `.py` file (excluding `__init__.py`), it imports the module and looks for a variable named `router` of type `APIRouter`.
- All found routers are automatically registered with your FastAPI app.

