Crossbar HTTP
Module that provides methods for accessing Crossbar.io HTTP Bridge Services using python-requests and requests-futures for async support
Fork of the original package by Eric Chapman at The HQ, only supporting Python 3+ versions using python-requests and requests-futures module. Which means you can pass params like proxies, auth, certificate verify etc. to the Client. Check python-requests for extra args you can use.
Revision History
v0.1.4:
Added requests-futures module to support async mode calls can now return Futures instead of Response obj
v0.1.3:
Switched to python-requests module to support more params passing to the client
v0.1.2:
Added “ClientCallRuntimeError” exception for general errors
v0.1.1:
Added class defined Exceptions for specific events
Added key/secret handling
v0.1:
Initial version
Installation
pip install crossbarhttprequests
Usage
Call
To call a Crossbar HTTP bridge, do the following
client = Client("https://127.0.0.1/call", verify=False) # https url with extra param verify going to requests.request
result = client.call("com.example.add", 2, 3, offset=10)
#Asnyc mode
client = Client("http://127.0.0.1/", do_async=True) # Run in async mode
future = client.call("com.example.add", 2, 3, offset=10)
#Do other work here
result = future.result() #Get result when ready
This will call the following method
def onJoin(self, details):
def add_something(x, y, offset=0):
print "Add was called"
return x+y+offset
self.register(add_something, "com.example.add")
Publish
To publish to a Crossbar HTTP bridge, do the following
client = Client("http://127.0.0.1/", headers={'X-Custom-Headers': 'X-Value'}) # Extra params goes to requests.request
result = client.publish("com.example.event", event="new event")
#In async mode
client = Client("http://127.0.0.1/publish", do_async=True, max_workers=8, session=None, response_hook=None) # Extra params for requests-futures
result = client.publish("com.example.event", event="new event", response_hook=_method_to_handle_response).result()
The receiving subscription would look like
def onJoin(self, details):
def subscribe_something(event=None, **kwargs):
print "Publish was called with event %s" % event
self.subscribe(subscribe_something, "com.example.event")
Key/Secret
For bridge services that have a key and secret defined, simply include the key and secret in the instantiation of the client.
client = Client("http://127.0.0.1/publish", key="key", secret="secret")
Exceptions
The library will throw the following exceptions. Note that all exceptions subclass from “ClientBaseException” so you can just catch that if you don’t want the granularity.
ClientBadUrl - The specified URL is not a HTTP bridge service
ClientBadHost - The specified host name is rejecting the connection
ClientMissingParams - The call was missing parameters
ClientSignatureError - The signature did not match
ClientNoCalleeRegistered - Callee was not registered on the router for the specified procedure
ClientCallRuntimeError - Procedure triggered an exception
Contributing
To contribute, fork the repo and submit a pull request.
Testing
The test can be run by using Docker Compose. Connect to a docker host and type
%> docker-compose build %> docker-compose up
The Docker Compose file creates a generic router with an example service connected to it and runs the tests.
The service “crossbarhttp_test_1” will return a 0 value if the tests were successful and non zero otherwise. To get the pass/fail results from a command line, do the following
#!/usr/bin/env bash
docker-compose build
docker-compose up
exit $(docker-compose ps -q | xargs docker inspect -f '{{ .Name }} exited with status {{ .State.ExitCode }}' | grep test_1 | cut -f5 -d ' ')
This is a little hacky (and hopefully Docker will fix it) but it will do the trick for now.
License
MIT
Metadata
Release files for crossbarhttprequests 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| crossbarhttprequests-0.1.6.tar.gz | 6.3 kB | Without provenance | Details |
Release files / crossbarhttprequests-0.1.6.tar.gz
| Download URL | crossbarhttprequests-0.1.6.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8194b95a066675c5351d4bfef541e5cfdc3b0b11867e5bf8575f5daf983e837
|
|
BLAKE2b-256 checksum How to use checksums |
c60a8c5510263139a6c1c345e0436ec42f2cb7e017638ecd7ee3aa8016ed7cc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.5
|
Security for crossbarhttprequests 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.