Configure uvicorn with a python source file
See original GitHub issueChecklist
- There are no similar issues or pull requests for this yet.
- I discussed this idea on the community chat and feedback is positive.
Feature request
I want to be able to configure uvicorn
using a python source file similar to how gunicorn does it. uvicorn
currently does not support this behaviour. An example gunicorn_conf.py
file can be found here
Possible usage
Running the command below should start the uvicorn
server with the given configurations in the uvicorn_config.py
.
uvicorn example:app -c "uvicorn_config.py"
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Settings - Uvicorn
Use the following options to configure Uvicorn, when running from the ... --reload-dir <path> - Specify which directories to watch for python file...
Read more >How to use the uvicorn.Config function in uvicorn - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... Server): def install_signal_handlers(self): pass config...
Read more >Python Examples of uvicorn.run - ProgramCreek.com
The following are 15 code examples of uvicorn.run(). ... def run(self): # Note(simon): we have to use lower level uvicorn Config and Server...
Read more >Run a Server Manually - Uvicorn - FastAPI
FastAPI framework, high performance, easy to learn, fast to code, ready for production.
Read more >How to run Uvicorn FastAPI server as a module from another ...
Basically, your code that creates the new process must be under if __name__ ... main : the file main.py (the Python "module").
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would be happy to take on a PR if the community is interested enough in this.
I agree with @raqib-hayder. I think support for a configuration file would be helpful, and would bring Uvicorn in line with Gunicorn, Hypercorn (https://github.com/encode/uvicorn/discussions/1105), and other related projects in this respect.
I find myself doing increasing amounts of programmatic configuration for Uvicorn. This configuration sometimes has to be version-aware (i.e., the
reload_excludes
option can only be passed touvicorn>=0.15
). It would be helpful for separation of concerns to move the configuration into a dedicated file.A config file would also make it easier to maintain configurability when layers of abstraction are built on top of Uvicorn. For example, users might want to start with a pre-configured server like this, using it as the basis for their project. The base project provides default configuration, but the downstream project might need to change some settings. How should these downstream projects update the Uvicorn configuration if the actual
uvicorn
/uvicorn.run()
command is in the base project? Environment variables can be used, but then the base project needs to read an environment variable for every Uvicorn config setting, and there are a lot of config settings. With configuration file support, downstream users could simply specify a single environment variable likeUVICORN_CONF
with the path to their configuration file, rather than passing in individual environment variables for every setting they want to configure.I’m not sure there needs to be an additional way to configure Uvicorn’s CLI, since you can write your own Python program to call
uvicorn.run
… https://github.com/encode/uvicorn/blob/1d9511f0b9dc73867bbbb38f72dbbdcac5478651/uvicorn/main.py#L428