网页
综合
更新时间 2026-11-14 09:45:59
Settings - Uvicorn
自动蜘蛛
uvicorn.dev
正文约 2360 字
Use the following options to configure Uvicorn, when running from the command line.
There are three ways to configure Uvicorn:
Command Line: Use command line options when running Uvicorn directly.
Programmatic: Use keyword arguments when running programmatically with uvicorn.run().
When using reload=True or workers=NUM, you should put uvicorn.run into an if __name__ == '__main__' clause in the main module.
Environment Variables: Use environment variables with the prefix UVICORN_.
CLI options and the arguments for uvicorn.run() take precedence over environment variables.
Also note that UVICORN_* prefixed settings cannot be used from within an environment configuration file. Using an environment configuration file with the --env-file flag is intended for configuring the ASGI application that uvicorn runs, rather than configuring uvicorn itself.
If Uvicorn cannot load watchfiles at runtime, it will periodically look for changes in modification times to all *.py files (and only *.py files) inside of its monitored directories. See the --reload-dir option. Specifying other file extensions is not supported unless watchfiles is installed. See the --reload-include and --reload-exclude options for details.
For more nuanced control over which file modifications trigger reloads, install uvicorn[standard], which includes watchfiles as a dependency. Alternatively, install watchfiles where Uvicorn can see it.
Using Uvicorn with watchfiles will enable the following options (which are otherwise ignored):
When using Uvicorn through WSL, you might have to set the WATCHFILES_FORCE_POLLING environment variable, for file changes to trigger a reload. See watchfiles documentation for further details.
The --reload and --workers arguments are mutually exclusive. You cannot use both at the same time.
Uvicorn's native WSGI implementation is deprecated, you should switch to a2wsgi (pip install a2wsgi).
The --no-date-header flag doesn't have effect on the websockets implementation.
The SSL context can be configured with the following options:
To understand more about the SSL context options, please refer to the Python documentation.
For advanced TLS scenarios that the flags above don't cover (e.g., mutual TLS, certificate pinning, custom SSLContext.options), pass an ssl_context_factory to uvicorn.run() or Config. See Running with HTTPS for details.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。