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 in the documentation/README.
I already searched in Google "How to do X" and didn't find any information.
I already read and followed all the tutorial in the docs/README and didn't find an answer.
Commit to Help
I commit to help with one of those options 👆
Example Code
N/A
Description
I would like to propose adding a plugin system to fastapi-cli using Python entry points. This would allow third-party packages to register commands that appear in the fastapi CLI automatically.
Currently, the answer to these is "use external tools". But there is a real gap: we developers want commands that integrate with their FastAPI app context - database sessions, settings, dependencies and not just random scripts that happen to live nearby.
A plugin system would:
Keep fastapi-cli core minimal
Let the community build and share extensions
Provide a blessed path for app-aware tooling
Proposed Design
Following is a high-level design on how this can be achieved. Plugin authors will register commands via entry points in pyproject.toml:
$ pip install fastapi-cli
$ pip install fastapi-shell fastapi-routes
$ fastapi --help
Commands:
dev Run development server
run Run production server
shell Interactive shell [plugin: fastapi-shell]
routes List routes [plugin: fastapi-routes]
Plugin Introspection
A built-in command to see what's loaded:
$ fastapi plugins
Installed Plugins:
fastapi-shell v0.2.1 shell Interactive Python shell with app context
fastapi-routes v1.0.0 routes List all registered routes
Reference Plugin Implementation
A minimal example showing the complete plugin structure:
fastapi-routes/pyproject.toml:
[project]
name = "fastapi-routes"version = "0.1.0"description = "List routes in your FastAPI app"dependencies = ["fastapi-cli>=0.0.8", "typer>=0.9.0"]
[project.entry-points."fastapi_cli.plugins"]
routes = "fastapi_routes.cli:routes_command"
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
I would like to propose adding a plugin system to
fastapi-cliusing Python entry points. This would allow third-party packages to register commands that appear in thefastapiCLI automatically.Target Repository: fastapi/fastapi-cli
Motivation
Several discussions have requested CLI extensibility:
Currently, the answer to these is "use external tools". But there is a real gap: we developers want commands that integrate with their FastAPI app context - database sessions, settings, dependencies and not just random scripts that happen to live nearby.
A plugin system would:
fastapi-clicore minimalProposed Design
Following is a high-level design on how this can be achieved. Plugin authors will register commands via entry points in
pyproject.toml:That is it. When users
pip install my-plugin, the commands appear infastapi --helpautomatically.Implementation
File:
fastapi_cli/plugins.pyFile:
fastapi_cli/cli.pyHow Plugins Access App Context
This is where the magic happens. Plugins are not just random scripts - they can load and interact with your FastAPI app:
This gives plugin authors access to:
app.state)User Experience
Plugin Introspection
A built-in command to see what's loaded:
Reference Plugin Implementation
A minimal example showing the complete plugin structure:
fastapi-routes/pyproject.toml:fastapi_routes/cli.py:What I'm Offering
If there's interest, I will submit a PR that:
fastapi pluginsintrospection commandI am also building a management commands package that would use this system, which could serve as a reference implementation for the community.
Open Questions
fastapi_cli.pluginsvsfastapi.clivs other)[tool.fastapi-cli.plugins]table inpyproject.tomlbe preferred over entry points? (for future uv/PDM native support)Operating System
macOS
Operating System Details
MacOs 14
Python Version
3.10
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions