FastAPI CLI
Project description
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
你也通过环境变量 TYPER_APP指定
功能
- 查看路由
- 启动FastAPI应用(uvicron)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi_fastcli-0.1.2.tar.gz
(3.1 kB
view details)
Built Distribution
File details
Details for the file fastapi_fastcli-0.1.2.tar.gz
.
File metadata
- Download URL: fastapi_fastcli-0.1.2.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-83-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a40e84ed65650e5903d127179733f2768afda90399cac8760b651d70607531c3 |
|
MD5 | 9c92be6de459f8711d8f5884bda6f0c7 |
|
BLAKE2b-256 | 4da4215ba5fca380213aae53ee2768d76e232ef20ea26ff75dfaa30d741908d1 |
File details
Details for the file fastapi_fastcli-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: fastapi_fastcli-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-83-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 492c71419d85237457156ed905fa410abe51c3fca3484780e4598dcf3074ab93 |
|
MD5 | be101471857ef0d9911ec17e18bf7e24 |
|
BLAKE2b-256 | 03fcc288da8b361fce78158b1f9f9b8e8608a523609c6e9bfb14feced7d065ff |