Skip to main content

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

fastcli run

启动FastAPI应用

fastcli run

fastcli routes

在运行时所在的目录 查找下列路径

- app.commands:app
- app.cli:app
- cli:app
- main:cli
- manage:cli
- app:cli

你也通过环境变量 TYPER_APP指定

功能

  • 查看路由
  • 启动FastAPI应用(uvicron)

Project details


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.3.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

fastapi_fastcli-0.1.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_fastcli-0.1.3.tar.gz.

File metadata

  • Download URL: fastapi_fastcli-0.1.3.tar.gz
  • Upload date:
  • Size: 3.2 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

Hashes for fastapi_fastcli-0.1.3.tar.gz
Algorithm Hash digest
SHA256 79035590e67d4d195bd0721bf2fca402f9b70759da8512814f795214d804a737
MD5 19a54e2cc7ac665214d6ac6afb446915
BLAKE2b-256 cd1d79ff6b22919338690a5d5caa3331835ed3f18e8aac2e392c530ad2fc2a6e

See more details on using hashes here.

File details

Details for the file fastapi_fastcli-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: fastapi_fastcli-0.1.3-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

Hashes for fastapi_fastcli-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ceb03c953eb201ecd16463015b5c39bcb3c2f08dba743384504cd7dd5af1830e
MD5 0bc4a42fa57bcbb9109105b6a8bd590e
BLAKE2b-256 f33d358b151d6562a016a14c582c79a6e9c284bf36d791d4a1c6bf9b4c6d6fa8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page