Use the Python SDK for the Satori platform to create server-based applications that use the Satori to publish and subscribe.
pip install satori-sdk-python
Secure WebSocket communication (wss://) is supported natively
for Python 2.7.9+ and PyPy 2.6+ only.
backports.ssl can be used to enable secure websocket communication with Python 2.7.* below 2.7.9 (For example CentOS 7 has Python 2.7.5).
pip install backports.ssl
Beware that backports.ssl requires PyOpenSSL >= 0.15, so if you have e.g. PyOpenSSL 0.13.1 that would result in strange errors.
The SDK will take advantage of python-rapidjson for faster json processing if it's installed.
There are most two notable CPU intensive routines in websocket communication: UTF-8 validation and payload masking. Fortunately there exists the wsaccel package that provides optimized versions of said routines.
To enable the SDK to use wsaccel, use the following code:
import satori.rtm.connection
satori.rtm.connection.enable_wsaccel()
You can view the latest Python SDK documentation here.
There more build-time dependencies than runtime dependencies. In order to work on satori-sdk-python development, you need:
- State Machine Compiler (SMC) to convert state machines description into Python source code
- tox to run tests using all supported Python interpreters in separate sandboxes.
Tests require an active Satori to be available. The tests require credentials.json
to be populated with the Satori properties.
The credentials.json file must include the following key-value pairs:
{
"endpoint": "ws://<SATORI_HOST>/",
"appkey": "my_appkey",
"superuser_role_secret": "ROLE SECRET KEY"
}
endpointis your customer-specific DNS name for Satori access.appkeyis your application key.superuser_role_secretis a role secret key for a role namedsuperuserthat has access to the reserved channels. If this role does not exist, you must create it.
After setting up credentials.json, run SDK tests with the following commands:
export SMC_JAR=/path/to/Smc.jar
tox -e py27-test
Substitute py27 with one of py26, pypy, py34 or py35 to choose a
desired Python implementation.