Compatibility
This library is compatible with stream-sea versions 4.0 <= v < 5.0
API Reference
publish(*, remote_host, remote_port, secure, client_id, client_secret, stream, payload)
Publish a message to a stream.
remote_host: str- The DNS name of the remote serverremote_port: str- The port of the remote serversecure: bool- If true, TLS is usedclient_id: str- The client IDclient_secret: str- The client secret used to authenticate the clientstream: str- The name of the stream to publish topayload: Any- The message payload to send
describe_stream(*, remote_host, remote_port, secure, client_id, client_secret, stream)
Read a schema definition for a stream
remote_host: str- The DNS name of the remote serverremote_port: str- The port of the remote serversecure: bool- If true, TLS is usedclient_id: str- The client IDclient_secret: str- The client secret used to authenticate the clientstream: str- The name of the stream
define_stream(*, remote_host, remote_port, secure, client_id, client_secret, stream, schema)
Write a schema definition for a stream
remote_host: str- The DNS name of the remote serverremote_port: str- The port of the remote serversecure: bool- If true, TLS is usedclient_id: str- The client IDclient_secret: str- The client secret used to authenticate the clientstream: str- The name of the streamschema: SchemaDefinition- Schema definition
If a schema definition with the same name and version number already exists, the existing definition will not be overwritten.
get_schema_versions_vector(*, remote_host, remote_port, secure, client_id, client_secret, streams)
Read the version numbers for multiple streams
remote_host: str- The DNS name of the remote serverremote_port: str- The port of the remote serversecure: bool- If true, TLS is usedclient_id: str- The client IDclient_secret: str- The client secret used to authenticate the clientstreams: [str]- The names of the streams
This function will return an array ret_val with the same length as streams. For every i, if the stream with name streams[i] exists, then the value of ret_val[i] will be that stream's version number. If the stream with name streams[i] does not exist, then the value of ret_val[i] will be None.
SchemaDefinition
The SchemaDefinition class defines a schema for a stream.
The SchemaDefinition class has the following fields:
name: str- The name of the schema. Currently the name of the schema must be equal to the name of the stream.version: str- The version number of the schema.fields- The set of fields in the schema. Fields are treated as an unordered set, so the order of this array does not matter.
The following field types are supported:
FieldType.STRING- Any stringFieldType.FLOAT- Any JSON-serializable floating point valueFieldType.INTEGER- Any JSON-serializable integerFieldType.DATE- A UTC date string in the format "YYYY-MM-DDTHH:mm:ssZ"FieldType.STRING_ARRAY- An array ofFieldType.STRINGFieldType.FLOAT_ARRAY- An array ofFieldType.FLOATFieldType.INTEGER_ARRAY- An array ofFieldType.INTEGERFieldType.DATE_ARRAY- An array ofFieldType.DATEFieldType.ENUM- A string restricted to a finite set of valuesFieldType.OBJECT- A JSON objectFieldType.OBJECT_ARRAY- An array ofFieldType.OBJECT
Stream-sea-client Developer Documentation
Tooling
- Developer tooling can be installed with
pip install -r dev-requirements.txt - The project uses
pycodestyleas a linter. To lint the project, runpycodestyle ./
Stream-sea wire protocol
Websocket layer
- The stream-sea wire protocol is built on top of the Websocket protocol
- The protocol is initiated by the client establishing a Websocket connection to the server
- As long as the Websocket connection is open, it is the server's responsibility to send Websocket ping messages at least every 30 seconds to avoid idle connections being closed
- Once a connection is established, the client and server communicate by exchanging Websocket data messages, which will be referred to as just messages for the rest of this spec.
- Every message is a JSON object serialized to a string
Message structure
- Each message has an
idfield of JSON typenumberand aactionfield of JSON typestring. Here is an example message:
{
"id": 2,
"action": "subscription",
"streamName": "boiler_data",
"payload": {
"temperature": 92,
"pressure": 3002
}
}
- The client must send the first message with
idequal to1, and must increaseidby 1 for each subsequent message - Each message
xsent by the server is a response to an earlier messageysent by the client.xmust have the same values ofidandactionasy - For some messages
ysent by the client, the server can reply with multiple messagesx1, x2, .... These must all have the same values ofidandactionasy
Authentication Request Message
- The client-sent message with
id = 1must be an Authentication Request message - Client-sent messages with
id > 1must not be Authentication Request messages - An Authentication Request message has an
actionfield with value"authenticate" - An Authentication Request message must have a
payloadfield of JSON typeobject - Stream-sea supports two authentication methods: Basic and JWT
- In order to authenticate with the Basic method, the
payloadof the Authentication Request message must have the following fields:- A
typefield with value"basic" - A
clientIdfield of JSON typestring - A
clientSecretfield of JSON typestring
- A
- In order to authenticate with the Basic method, the
payloadof the Authentication Request message must have the following fields:- A
typefield with value"jwt" - A
clientIdfield of JSON typestring - A
jwtfield of JSON typestringcontaining the stream-sea JWT
- A
- The server must respond to an Authentication Request message with exactly one Authentication Response message
Authentication Response Message
- An Authentication Response message has an
actionfield with value"authenticate" - An Authentication Response message must have a
successfield of JSON typebooleanwhich will indicate whether authentication was successful - If authentication was unsuccessful, the client must close the connection and must not send any more messages
Subscription Request Message
- The client may subscribe by sending a Subscription Request message
- A Subscription Request message has an
actionfield with value"subscribe" - A Subscription Request message has a
payloadfield of JSON typestring. The value of this field must be the name of the stream to subscribe to. - A Subscription Request message may have a
groupIdfield of JSON typestring. If set, the value of this field must be a UUID in RFC 4122 format (also known as the 8-4-4-4-12 format). - A Subscription Request message may have multiple responses. The first response must be a Subscription Response message. Each subsequent response must be a Message Delivery message.
Subscription Response Message
- A Subscription Response message has an
actionfield with value"subscribe" - A Subscription Response message has a
streamNamefield of JSON typestring. The value of this field is the name of the stream that was subscribed to.
Message Delivery
- A Message Delivery message has an
actionfield with value"subscribe" - A Message Delivery message has a
payloadfield of JSON typeobject. This value of this field is the user-defined message object.
Example of stream-sea wire protocol exchange
The client authenticates and subscribes to the stream boiler_data
The server delivers two messages from the boiler_data stream.
# client -> server
{
"id":1,
"action": "authenticate",
"payload": {
"type": "basic"
"clientId": "abc",
"clientSecret": "def123"
}
}
# client <- server
{
"id": 1,
"action": "authenticate",
"success": true,
"payload": {
"jailId": "some_jail"
}
}
# client -> server
{
"id": 2,
"action": "subscribe",
"payload": "boiler_data"
}
# client <- server
{
"id": 2,
"action": "subscription",
"success": true,
"streamName": "boiler_data",
"payload":2
}
# client <- server
{
"id": 2,
"action": "subscription",
"streamName": "boiler_data",
"payload": {
"temperature": 91,
"pressure": 3001
}
}
# client <- server
{
"id": 2,
"action": "subscription",
"streamName": "boiler_data",
"payload": {
"temperature": 92,
"pressure": 3002
}
}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file stream-sea-client-0.7.0.tar.gz.
File metadata
- Download URL: stream-sea-client-0.7.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34e023fb7ff6a2838ab2af2c55be4eeb6df07c9b4834a5988c1e18db8ac9dd29
|
|
| MD5 |
b36a9ea9fad3f0d87db99c1598232347
|
|
| BLAKE2b-256 |
240c478c57c6cdcd71479f0b6101f49a83ad724e5f3ac9431270173321b3976b
|