
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Sveltekit ruined me 🤓! I made this package because:
- File-based routing is the bees knees.
- I like to watch the world burn.
- It's just easier, bro.
This Python module dynamically loads FastAPI routes from a specified directory structure. It is designed to streamline the integration of API routes into a FastAPI app, making it easy to manage large applications with many endpoints.
You can import routes and API Routers as usual, but whenever you want, if you structure your endpoints like below, it will loop over the directory and put all the routes correctly.
📁 project_root/
├ 📁 routes/ # This folder is set as the directory in the load_routes function
│ ├ 📄 route.py # Translates to /api (base route of the directory)
│ │
│ ├ 📁 users/
│ │ ├ 📄 route.py # /api/users
│ │ ├ 📄 [user_id].py # /api/users/{user_id}
│ │ └ 📄 profile.py # /api/users/profile
│ │
│ ├ 📁 products/
│ │ ├ 📄 route.py # /api/products
│ │ └ 📁 [product_id]/
│ │ ├ 📄 route.py # /api/products/{product_id}
│ │ └ 📄 reviews.py # /api/products/{product_id}/reviews
│ │
│ └ 📁 settings/
│ ├ 📄 route.py # /api/settings
│ └ 📁 notifications/
│ ├ 📄 route.py # /api/settings/notifications
│ └ 📄 email.py # /api/settings/notifications/email
├ 📁 templates/
│ └ 📄 home.html # Not relevant to FastAPI routes
└ 📄 main.py # Where you set up your FastAPI app and call load_routes
Clone this repository or copy the script into your project directory:
pip install fastapi-file-router
from fastapi import FastAPI
from fastapi_file_router import load_routes
app = FastAPI()
load_routes(server, "routes", verbose=True)
# Optional
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
)
Enable verbose logging to get detailed output during the route loading process, which can be helpful for debugging:
load_routes(app, Path("./routes"), verbose=True)
Contributions are welcome! Please fork the repository and open a pull request with your features or fixes.
Don't be a bozo.
FAQs
File-based routing for FastAPI
We found that fastapi-file-router demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.