Skip to main content

asyncio Server-Sent Events implementation

Project description

SSE
===

Simple asyncio/aiohttp wrapper for Server-Sent Events.

Usage
-----

Sending events:

```python
import asyncio
import sse


class Handler(sse.Handler):
@asyncio.coroutine
def handle_request(self):
yield from asyncio.sleep(2)
self.send('foo')
yield from asyncio.sleep(2)
self.send('bar', event='wakeup')

start_server = sse.serve(Handler, 'localhost', 8888)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
```

Validating incoming requests:

```python
class Handler(sse.Handler):
def validate_sse(self):
super().validate_sse()
# use self.request / self.payload
if not self.request.path.startswith('/live'):
raise sse.SseException()
```

Sending JSON data:

```python
class Handler(sse.Handler):
@asyncio.coroutine
def handle_request(self):
self.send({'foo': 'bar'})
```

Sending IDs / event names / retry information:

```python
class Handler(sse.Handler):
@asyncio.coroutine
def handle_request(self):
self.send('some data', id=12345, event='something', retry=10000)
```

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Files for asyncio-sse, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size asyncio_sse-0.1-py33-none-any.whl (5.2 kB) File type Wheel Python version py33 Upload date Hashes View
Filename, size asyncio-sse-0.1.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page