Fastapi CLI
在使用FastAPI前,我个人使用Flask居多,比较喜欢Flask的CLI,使用起来比较方便,这个项目就是解决FastAPI没有CLI的问题
使用它自动加载项目中已有的Typer实例
使用前
假设我们的CLI代码在下面的路径app/cli/init.py
import typer
app = typer.Typer()
@app.command()
def version():
return "1.0.0"
为了方便执行,我们需要在项目根目录新增一个入口文件如cli.py并添加下面的内容
from app.cli import app
if __name__ == __main__:
app()
最后执行
python cli.py --help
使用后
使用fastcli由于app.cli:app在默认路径下,因此会自动加载,我们只需要运行下面的命令即可
fastcli --help
安装使用
安装
pip install fastapi-fastcli
# 安装TAB自动补全
fastcli --install-completion
查看路由列表
fastcli routes
启动FastAPI应用
fastcli run
在运行时所在的目录 查找下列路径
- app.commands:app
- app.cli:app
- cli:app
- main:cli
- manage:cli
- app:cli
你也通过环境变量 FASTAPI_APP指定 比如
export FASTAPI_APP=app:app
功能
- 查看路由
- 启动FastAPI应用(uvicron)
Metadata
Release files for fastapi-fastcli 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_fastcli-0.1.8.tar.gz | 3.1 kB | Without provenance | Details for fastapi_fastcli-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_fastcli-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for fastapi_fastcli-0.1.8-py3-none-any.whl |
Total release size: 7.2 kB
Release files / fastapi_fastcli-0.1.8.tar.gz
| Download URL | fastapi_fastcli-0.1.8.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
384d6ba5919870ab8a9b996e61b0cf5ff447fb0314ee78f48c5c731cb62a99ac
|
|
BLAKE2b-256 checksum How to use checksums |
66090053bba76cc508eb9ecfcb29ed231b85a86d9b81e3add888cdc7d2be5f25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-41-generic
|
Release files / fastapi_fastcli-0.1.8-py3-none-any.whl
| Download URL | fastapi_fastcli-0.1.8-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35665ba45c4839371134d29c5e1bf968149bae563e1e7fa7add65686be1e4568
|
|
BLAKE2b-256 checksum How to use checksums |
31d874a6a9569b8ee2580bf6c0b50be4994eed74fef630e5b0cc00a39fb16a4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-41-generic
|
Security for fastapi-fastcli 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.