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.

[Feature Request] Uvicorn integration

See original GitHub issue

🚀 Feature Request

Firstly thank you for open sourcing this - documentation is excellent too!.

Motivation

Often ASGI/WSGI python webserver frameworks are launched with their own wrapper module such as gunicorn, uvicorn and hypercorn.

Example as per the uvicorn quickstart guide. (note the run command: uvicorn example:app)

The uvicorn command then runs this main module.

If one wishes to use hydra for configuration management in the uvicorn examples they would need to rewrite some code from the above module perhaps:

import hydra
from uvicorn.supervisors import Multiprocess
from uvicorn.config import Config
from uvicorn.main import Server


async def app(scope, receive, send):
    assert scope['type'] == 'http'
    await send({
        'type': 'http.response.start',
        'status': 200,
        'headers': [
            [b'content-type', b'text/plain'],
        ]
    })
    await send({
        'type': 'http.response.body',
        'body': b'Hello, world!',
    })


@hydra.main()
def run(cfg):
    print(cfg.pretty())

    config = Config(app)
    server = Server(config=config)
    sock = config.bind_socket()
    supervisor = Multiprocess(config)
    supervisor.run(server.run, sockets=[sock])


if __name__ == "__main__":
    run()

Pitch

Describe the solution you’d like

A very open ended question but what are peoples thoughts on developing a way to make these libraries work together

Goals:

  • users don’t have to duplicate code.
  • make it easier to pass the hydra configuration into the uvicorn application

Are you willing to open a pull request?

  • Yes

cc. @tomchristie

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
alimcmaster1commented, Nov 10, 2019

@omry - Thanks for your detailed responses - appreciate it.

Yes agree #219 - looks interesting - will keep an eye out and try this when available.

Thanks very much for the example - that’s a neat way of integrating uvicorn and hydra!

0reactions
omrycommented, Jan 20, 2020

Closing, this should be possible via the compose API or following the example I pointed to.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uvicorn
Uvicorn is an ASGI web server implementation for Python. Until recently Python has lacked a minimal low-level server/application interface for async frameworks.
Read more >
Building REST APIs using FastAPI, SQLAlchemy & Uvicorn
Integrate FastAPI with SQLAlchemy; Using both normal and async ways of handling requests. Using Swagger in FastAPI. If you would like to refer ......
Read more >
Uvicorn - New Relic Documentation
Uvicorn. Read about the requirements and tips for integrating our Python agent with an app that uses the ASGI server Uvicorn.
Read more >
How to start a Uvicorn + FastAPI in background when testing ...
app = App() self.proc = Process(target=uvicorn.run, args=(app.api,), ... pytest import requests import uvicorn from fastapi import FastAPI ...
Read more >
Python feature server - Feast
This enables users to write and read features from the online store using any programming language that can make HTTP requests. CLI.
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