Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
URL: http://github.com/fastapi/fastapi-cli/discussions/263
origen="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-0fcd9af82350aeda.css" />
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