← 返回命令列表

Linux command

fastapi 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run development server

fastapi dev [main.py]

Run with specific host and port

fastapi dev [main.py] --host [0.0.0.0] --port [8080]

Run production server

fastapi run [main.py]

Run with auto-reload disabled

fastapi dev [main.py] --no-reload

Specify the app location

fastapi dev [main.py:app]

说明

fastapi is the CLI for FastAPI, a modern Python web framework for building APIs. It wraps Uvicorn ASGI server for convenient development and deployment. fastapi dev starts a development server with auto-reload—code changes trigger automatic restart. Use for local development with --host 0.0.0.0 to allow external access. fastapi run starts a production-oriented server without auto-reload and binding to all interfaces. For actual production, consider Uvicorn or Gunicorn directly with more configuration options. The path argument points to a Python file containing a FastAPI instance. Use path:variable syntax to specify a non-default app variable name. FastAPI generates automatic API documentation at /docs (Swagger UI) and /redoc endpoints based on your route definitions and type hints.

参数

--host _address_
Bind address. Default: 127.0.0.1 (dev), 0.0.0.0 (run).
--port _port_
Server port. Default: 8000.
--reload
Enable auto-reload (dev default).
--no-reload
Disable auto-reload.
--workers _count_
Number of worker processes.
--root-path _path_
ASGI root path for proxied setups.
--app _name_
Application variable name. Default: app.
--reload-dir _path_
Directory to watch for file changes (dev mode).
--proxy-headers
Trust X-Forwarded headers.
--help
Display help information.

FAQ

What is the fastapi command used for?

fastapi is the CLI for FastAPI, a modern Python web framework for building APIs. It wraps Uvicorn ASGI server for convenient development and deployment. fastapi dev starts a development server with auto-reload—code changes trigger automatic restart. Use for local development with --host 0.0.0.0 to allow external access. fastapi run starts a production-oriented server without auto-reload and binding to all interfaces. For actual production, consider Uvicorn or Gunicorn directly with more configuration options. The path argument points to a Python file containing a FastAPI instance. Use path:variable syntax to specify a non-default app variable name. FastAPI generates automatic API documentation at /docs (Swagger UI) and /redoc endpoints based on your route definitions and type hints.

How do I run a basic fastapi example?

Run `fastapi dev [main.py]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --host _address_ do in fastapi?

Bind address. Default: 127.0.0.1 (dev), 0.0.0.0 (run).