Conveniently access data
Project description
What is speedracer?
speedracer provides convenience classes for
- Subscribing to the Mission Data Broker (MDB)
- Authenticating to Autobahn APIs
Quickstart
Subscribing to the MDB
To subscribe to a dataset on the MDB
- Provide the base URL of the MDB Account Server (MAS) when creating a Connection
- Provide the dataset to the subscribe method
conn = Connection('https://mdb-account-server.com')
sub = await conn.subscribe('mydataset')
async for msg in sub:
print(msg.data.decode())
Authenticating to Autobahn APIs
To authenticate to Autobahn's REST APIs
- Create a
JWTManager
with the API Gateway's URL - Call the
get_headers
method to get an Authorization HTTP header
manager = JWTManager('https://api-gateway.com/getjwt')
headers = manager.get_headers()
If already subscribed to MDB, you can reuse your Connection
's JWTManager
conn.jwt_manager.get_headers()
Advanced Usage
MDB
Callback
Instead of iterating over a Subscription
, you can provide a callback that takes a message as an argument.
def cb(msg):
print(msg.data.decode())
conn = Connection('https://mdb-account-server.com')
sub = await conn.subscribe('mydataset', callback=cb)
# Since subscribe does not block, call sub.wait to block
await sub.wait(messages=15)
await sub.wait(timeout=5)
Seek
To move the cursor of your Subscription
, use seek
.
# seek to message sequence 1
await sub.seek(start_sequence=1)
# seek to 5 minutes ago
await sub.seek(start_datetime=datetime.datetime.utcnow() - datetime.timedelta(minutes=5)
Offset
By default, subscribe
starts with the oldest message. To start at the current time, specify offset.
sub = await conn.subscribe('mydataset', offset=Offset.NOW)
Low Latency
By default, Subscription
s fetch messages in batches of 10. If the server has less than 10 messages to send, it will wait a bit for new messages before returning the messages it does have. If that waiting is a problem, you may want to set batch_size
to 1.
sub = await conn.subscribe('mydataset', batch_size=1)
Frequently Asked Questions
TLS Errors
TLS errors occur for 2 reasons
- Not specifying client certificates
- Not specifying a Certificate Authority
Client certificates
By default, speedracer looks for certificates in the user's home directory named cert.crt
and cert.key
. To specify a different path, pass cert=('./mycert.crt', './mycert.key')
.
conn = Connection('https://mdb-account-server.com', cert=('./mycert.crt', './mycert.key'))
manager = JWTManager('https://api-gateway.com/getjwt', cert=('./mycert.crt', './mycert.key'))
Certificate Authority
To specify a Certificate Authorty
conn = Connection('https://mdb-account-server.com', ca_bundle='ca.pem')
manager = JWTManager('https://api-gateway.com/getjwt', verify='./ca.pem')
JWTManager
also supports verify=False, but Connection
does not offer an insecure option.
Subscription not starting at specified offset
The MDB remembers your subscription's place. If your program restarts, the subscription will pick up where it left off. If that is not the behavior you want, then use the Subscription's seek method.
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
Built Distribution
File details
Details for the file speedracer-0.0.1.tar.gz
.
File metadata
- Download URL: speedracer-0.0.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0b21900dd9b55dd7713f87af366f9b7fa1463c078a0733acac31a8b320d3bca |
|
MD5 | 2cb03fa87614233f8b029b2ada10bd9c |
|
BLAKE2b-256 | f27a548a7198cb8bcd13465a238f9890576467692d17afbfad89b1604e18e8e6 |
File details
Details for the file speedracer-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: speedracer-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47bbdc099257db5a9b69aab07838d10bbdf33a82a4a70c872d7dc9fc3bc32929 |
|
MD5 | 62e75063d9106f347e11c327b82890a3 |
|
BLAKE2b-256 | f50bb3036566e4d4d6fd77746709391c0698da2d51e838f6b511fa2fddcb00bb |