question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configure uvicorn with a python source file

See original GitHub issue

Checklist

  • 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:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
br3ndonlandcommented, Oct 24, 2021

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 to uvicorn>=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 like UVICORN_CONF with the path to their configuration file, rather than passing in individual environment variables for every setting they want to configure.

3reactions
akxcommented, Sep 13, 2021

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.runhttps://github.com/encode/uvicorn/blob/1d9511f0b9dc73867bbbb38f72dbbdcac5478651/uvicorn/main.py#L428

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found