Opened 3 months ago

Last modified 6 weeks ago

#31626 new New feature

Add asgi support to runserver

Reported by: Joshua Massover Owned by: nobody
Component: HTTP handling Version: 3.0
Severity: Normal Keywords: runserver, asgi
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Joshua Massover)

Previous conversation about this ticket can be found on the django forum

It would be great to add an asgi flag such that runserver will "just work" with ASGI. eg.

./manage.py runserver --asgi

The 4 options I've thought of are the following:

  1. Update runserver in django in a way that keeps the daphne import optional.
  2. Add daphne as a dependency to django and update runserver.
  3. Maintain a separate django app that holds the command that integrates daphne with runserver. Reference the app in asgi section of the django documentation.
  4. Add the commands to the daphne repository, perhaps allowing us to add daphne as an installed app so the command is discovered, and reference this in the asgi section of the django documentation.

I have an initial pr for (1). This code depends on #31594.

Change History (5)

comment:1 Changed 3 months ago by Joshua Massover

Description: modified (diff)

comment:2 Changed 3 months ago by Carlton Gibson

Resolution: needsinfo
Status: newclosed

I'm going to momentarily close this as needsinfo — let's continue the discussion on the forum thread: we can re-open if it's agreed to bundle this.

Yes, if runserver just worked would be good, but the draft PR is quite big, and doesn’t allow for other ASGI servers at all.

What’s the alternative? Install channels and add to INSTALLED_APPS. This is Option 3. This would allow an uvicorn-runserver option and so on. It’s not as neat but it might be a lot cleaner. :grimacing:

Last edited 3 months ago by Carlton Gibson (previous) (diff)

comment:3 Changed 2 months ago by Carlton Gibson

Component: UncategorizedHTTP handling
Keywords: runserver asgi added
Triage Stage: UnreviewedAccepted

OK, let's accept this as a new feature.

The suggestion in the forum thread is to detect if Daphne or uvicorn or ... is installed and then use that.

In the draft PR looks like importing Daphne in a try block, which I´m not sure about at all.
Is there a way we can detect the asgi server without hard-coding imports?

I'd imagined a server based off of Python's http.server, as we have for WSGI, either in Django or asigref as appropriate.

In the meantime, 3.1 could probably do with some docs, saying to install channels (to use it's runserver) or uvicorn (which has a --reload option).

comment:4 Changed 2 months ago by Carlton Gibson

Resolution: needsinfo
Status: closednew

comment:5 Changed 6 weeks ago by Seth Michael Larson

Hey! So I recently had a user hit this issue when using the recently added async support to the Elasticsearch client library.

See here: https://github.com/elastic/elasticsearch-py/issues/1303

Note: See TracTickets for help on using tickets.
Back to Top