Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dlax/pyramid-asgi
https://github.com/dlax/pyramid-asgi
asgi pyramid
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dlax/pyramid-asgi
- Owner: dlax
- Created: 2018-07-11T07:44:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-11T10:10:59.000Z (over 6 years ago)
- Last Synced: 2024-10-18T10:31:13.091Z (3 months ago)
- Topics: asgi, pyramid
- Language: Python
- Size: 11.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
Awesome Lists containing this project
README
Pyramid ASGI
============.. image:: https://travis-ci.org/dlax/pyramid-asgi.svg?branch=master
:target: https://travis-ci.org/dlax/pyramid-asgiGetting Started
---------------`pyramid_asgi` provides a wrapper to transform Pyramid WSGI applications into
ASGI applications. It also provides configurator methods to register ASGI
consumers.Here is a simple example that defines a wrapped Pyramid application using
`pyramid_asgi.PyramidWsgiToAsgi` and registers a "websocket" consumer under
the ``/ws`` route path... code-block:: python
from asgiref.wsgi import WsgiToAsgiInstance
from pyramid.config import Configurator
from pyramid_asgi import PyramidWsgiToAsgiclass WebsocketConsumer(WsgiToAsgiInstance):
"""ASGI consumer for websocket protocol."""async def __call__(self, receive, send):
while True:
message = await receive()
if message["type"] == "websocket.connect":
await send({"type": "websocket.accept"})
if message["type"] == "websocket.receive":
text = message.get("text")
if text:
await send({"type": "websocket.send",
"text": text})def main(global_config, **settings):
config = Configurator(settings=settings)
config.scan()
config.include('pyramid_asgi')
config.add_consumer(WebsocketConsumer, 'websocket', '/ws')
app = config.make_wsgi_app()
return PyramidWsgiToAsgi(app)This example can then be run through an ASGI server, like `uvicorn
`_.