An adapter for aiohttp, enabling a server to service WAMP calls and subscriptions over WebSockets.
Project description
serverwamp
Components that add Web Application Messaging Protocol features to WebSocket servers. With server_wamp, an aiohttp server can act as both a WAMP broker and dealer.
Example WAMP Microservice
from aiohttp import web
from server_wamp.adapters.aiohttp import WAMPApplication
from server_wamp.rpc import RPCRouteTableDef, RPCError
rpc_routes = RPCRouteTableDef()
@rpc_routes.route('myapp:getDoc')
async def get_document(document_id):
record = await mydb.retrieve(document_id)
return {'status': 'SUCCESS', 'document': record}
@rpc_routes.route('myapp:delDoc')
async def delete_document(document_id):
succeeded = await mydb.delete(document_id)
if succeeded:
return {'status': 'SUCCESS'}
else:
raise RPCError('wamp.error.delete_failed', {'status': 'FAILURE'})
if __name__ == '__main__':
wamp = WAMPApplication()
wamp.add_rpc_routes(rpc_routes)
app = web.Application()
app.add_routes((web.get('/', wamp.handle),))
web.run_app(app)
Compared to Traditional WAMP
Traditionally, WAMP clients connect to a WAMP router either to provide functionality or to use functionality provided by other clients. This library enables a server to respond to calls and subscriptions like a WAMP router would, but serve them in a custom way instead of routing them to other clients.
You might do this to provide Python-based web services over a WebSocket using a typical client and server model, while taking advantage of the structure the WAMP protocol provides.
In summary, this is not a WAMP router, but you could use it to build one if you wanted.
This library is good if…
- you like developing in micro-frameworks like Flask and aiohttp, but want to branch into serving over WebSockets.
- you want a structure for communicating over WebSockets, but want more request/response features than the socket.io protocol provides.
- you want to build a WAMP router.
It's not as useful if…
- you want to build a WAMP client
- Consider Autobahn|Python instead.
- you want a WAMP router out of the box.
- Consider Crossbar.io instead.
Known Deficiencies
- Project is in the prototyping stages, so documentation isn't available on low-level features yet.
- The out-of-the-box RPC handler does not provide the URI, session ID or call ID to the function that the call is routed to. This may be addressed in a later version with arg inspection/injection or async context vars.
Development
Unit tests can be run with:
pip install -e .
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for serverwamp-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa0670c07b8f40de9e0fe2deba387498f1acb180aaf8a1aa3dbeeb2955ecabcc |
|
MD5 | ad8026c1145b08c920b108cc8c82ec4e |
|
BLAKE2b-256 | 2d18d95aee15da28ca6c4c12e5ad5401ddc882ecf9580dd01d7845f131c260f7 |