An extensible Redis-over-WebSocket API on top of websockets and aioredis.
Installation
For basic functionality:
pip install redis_websocket_api
With geo extension (filtering messages by extent, projection transformation):
pip install redis_websocket_api[geo]
Server-Side Usage
For a quick test you can run
python -m redis_websocket_api
to start a simple redis websocket api on ws://localhost:8765.
This does roughly the equivalant of:
from aioredis import from_url
from redis_websocket_api import WebsocketServer, WebsocketHandler
class PublishEverythingHandler(WebsocketHandler):
def channel_is_allowed(self, channel_name):
return True
WebsocketServer(
redis=from_url("redis:///", encoding="utf-8", decode_responses=True),
read_timeout=30,
keep_alive_timeout=120,
handler_class=PublishEverythingHandler,
).listen(
host='localhost',
port=8000,
channel_patterns=["[a-z]*"],
)
Have a look at examples/demo.py for an example with the GeoCommandsMixin
added.
Client-Side Usage
WebsocketHandler
The default functionality provides the following interface to the web client (expecting the requests over a websocket connection):
GET keytranslates tohvals keyGET key hkeytranslates tohget key hkeySUB keysubscribes the websocket to a redis channel (using a single redis connection pool for all clients)DEL keyunsubscribes the client from the channelPINGcauses aPONGresponse (to avoid timeouts)
Subclass of WebsocketHandler with GeoCommandsMixin added
By adding the GeoCommandsMixin the web client can use
BBOX left bottom right topto only receive GeoJSON features within this box plus all messages which are not valid GeoJSONPROJECTION epsg:numbercauses all future GeoJSON features to be transformed to the given projection
See examples/demo.py for how to use an extended WebsocketHandler subclass.
Geo commands are currently limited to LineString, Polygon, and Point
geometries.
Note that the projection input and output coordinates will use the traditional GIS order,
that is longitude, latitude for geographic CRS and easting, northing for most projected CRS.
If you want the input and output axis order to strictly follow the definition of the CRS,
use StrictAxisOrderGeoCommandsMixin instead of GeoCommandsMixin.
Build your own protocol
Using the commands listed above for communicating from client to server is
completly optional and determinded by the Mixin classes added to the
WebsocketHandlerBase.
Metadata
Release files for redis-websocket-api 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| redis-websocket-api-0.4.4.tar.gz | 13.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| redis_websocket_api-0.4.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.9 kB
Release files / redis-websocket-api-0.4.4.tar.gz
| Download URL | redis-websocket-api-0.4.4.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
842e0e179ae690725192661996325238d817057e185f842c7f10707293db0aad
|
|
BLAKE2b-256 checksum How to use checksums |
24ed85ff19a8598bb8357d4c62501beef380452fd2f9dc045771a4b69953fd27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Release files / redis_websocket_api-0.4.4-py3-none-any.whl
| Download URL | redis_websocket_api-0.4.4-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
08771ea76a33e5b861661b3f94066fa12edba4768dc8790805e8401bc232f673
|
|
BLAKE2b-256 checksum How to use checksums |
60b19825c44b65d7a4cd2355cce77c9681f45305b7aa0c4e63afa1461d38cbb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|