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.

Considering ASGI.

See original GitHub issue

Okay, I’m going to punt this one out there.

Andrew Godwin’s latest work on the ASGI spec, means that there really is now an asyncio-based interface for Python webservers.

I’m planning to shortly be releasing a new release of uvicorn, at which point there will be two production-ready ASGI servers. (We already have daphne available.)

I’ll also be releasing a new version of apistar which will present either WSGI or ASGI interfaces, so there will be at least two ASGI web application frameworks. (We already have Django Channels)

I already use whitenoise for serving static files with apistar, but it’s not ideal under ASGI, because we necessarily need to run whitenoise behind as WSGI-to-ASGI adapter, which means that:

  • We’re not actually running asyncio code for disk operations.
  • We’re not able to stream response data, instead everything gets buffered at the adapter layer.
  • There’s no support for send_file. (This isn’t currently addressed in the ASGI spec, so that’s more complicated to address.)

This may well be premature, given the early nature of ASGI, but I’m wondering if you’d consider whitenoise-as-an-ASGI-middleware. If we use sync file operations on load, then I think ASGI support could be addressed with…

  • A WhiteNoise subclass, ASGIWhiteNoise that overrides __call__, and serve.
  • Changing get_response and file iteration in the asyncio case, to use something like aiofiles.
  • Considering how a sendfiles extension to ASGI might look.

I’ll likely be tackling some of this as part of my work on apistar, but figured I’d also raise this here just to get an idea of if you’d be interested in seeing ASGI supported directly in whitenoise?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:18
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
evansdcommented, Apr 4, 2018

Hi Tom, thanks for raising this. Yes, I’d definitely be interested in supporting native ASGI in WhiteNoise. My hope is that it won’t actually involve a lot of extra code. Fundamentally, WhiteNoise takes a request path, HTTP method, and headers and returns a status code, response headers, and an open file handle. There’s a bit of adaptor code to get this to work with the WSGI and Django middleware specs. So hopefully the ASGI adaptor code will be equally small, but I haven’t looked into this in detail yet.

I don’t know exactly when I’ll get time to look at this (the WhiteNoise 4.0 release is already massively behind due to work and family commitments) but very happy to review patches or discuss options.

2reactions
evansdcommented, Feb 28, 2020

Yes, absolutely. It’s “just” a case of finding the time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hello, ASGI - Encode
This article offers an introduction to the emerging ASGI standard, and what benefits it provides to Python web frameworks.
Read more >
Introduction to ASGI: Emergence of an Async Python Web ...
From a 1000-foot perspective, ASGI can be thought of as the glue that allows Python asynchronous servers and applications to communicate with ...
Read more >
Considering ASGI support - Sanic Community Discussion
I'm considering taking a proper crack at ASGI support, rather than just the proof-of-concept shim of #1265.
Read more >
Philip Jones - An ASGI Server from scratch - YouTube
"An ASGI Server from scratchEuroPython 2020 - Talk - 2020-07-23 - BrianOnlineBy Philip JonesI intend for this to be a fairly advanced talk ......
Read more >
ASGI: A Solid Infrastructure Fund For Today's Market
ASGI invests in a globally diversified portfolio of toll road ... Overall, the ASGI fund might be worth considering for investment.
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