You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the FastAPI documentation, with the integrated search.
I already searched in Google "How to X in FastAPI" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to FastAPI but to Pydantic.
I already checked if it is not related to FastAPI but to Swagger UI.
I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
I commit to help with one of those options 👆
Example Code
classAPIRouters(FastAPI):
# include all routes in 'routes'def__init__(self):
super().__init__()
routes= [fforfinglob.glob("employee/routes/*.py") ifos.path.basename(f) notin ("__init__.py", "api_routers.py")]
forrouter_fileinroutes:
module_name=os.path.splitext(os.path.basename(router_file))[0]
# module spec with all informations required for modul importspec=importlib.util.spec_from_file_location(module_name, router_file)
# empty module object for importmodule=importlib.util.module_from_spec(spec)
# importspec.loader.exec_module(module)
# include router in appself.include_router(module.router)
Description
For larger projects, it seems inefficient to clutter the main script with include_router calls, especially when individual settings are not required. Even when individual settings are necessary, I believe this should be possible at the level at which the router is defined.
It would be beneficial to have a similar option built directly into FastAPI. Is there any comparable feature currently being developed or available?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
For larger projects, it seems inefficient to clutter the main script with include_router calls, especially when individual settings are not required. Even when individual settings are necessary, I believe this should be possible at the level at which the router is defined.
It would be beneficial to have a similar option built directly into FastAPI. Is there any comparable feature currently being developed or available?
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.111.1
Pydantic Version
2.8.2
Python Version
3.12.0
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions