Skip to main content

Create distributed ASGI applications that pull events from a central Redis queue.

Project description

# Distributed ASGI
Uses Redis to distribute ASGI messages between worker ASGI apps. Workers can be on different machines, they just must be able to connect to the central Redis server.


# Usage

```py
# server.py
from distributed_asgi import create_distributor

app = create_distributor(
host="mywebsite.com",
port=6379,
db=0,
password="abc123",
key_prefix="MYPREFIX"
)

```


```py
# worker.py
from distributed_asgi import Node


class ASGIApp:
def __init__(self, scope):
self.scope = scope

async def __call__(self, receive, send):
await send({
"type": "http.response.start",
"status": 200
})

await send({
"type": "http.response.body",
"body": b"Hello World!"
})


node = Node(
host="mywebsite.com",
port="6379",
password="abc123",
cls=ASGIApp,
key_prefix='MYPREFIX'
)

print(f"Starting worker")
node.run()
```

Once you have `worker.py` and `server.py`, use some interface server to run `server.py`.

```
$ uvicorn server:App
```

and run `worker.py` as a normal python script:

```
$ python worker.py
```

ASGI requests received by the Distributor will be enqueued and later dequeued by the Node class and passed to the provided asgi app worker. It should be possible to replace `ASGIApp` in `worker.py` with your favorite ASGI application framework. Maybe Quart for example?



# Future Plans
* Path-based HTTP router that puts requests into different queues based on path.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

distributed-asgi-0.0.5.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file distributed-asgi-0.0.5.tar.gz.

File metadata

  • Download URL: distributed-asgi-0.0.5.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.4

File hashes

Hashes for distributed-asgi-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6e836fbaa43e886e30c56d8b1c9474f90ff63139bcd0eca13cbabeaae2dfa7ce
MD5 529457553b1db656c2c1963e355d80ee
BLAKE2b-256 24ceb941fce02f0b6c398edfb5384e567a6f4eaa3152290686df2649bf932bbf

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page