Use the Satori RTM SDK for Python to create server-based applications that use RTM to publish and subscribe.
pip install satori-rtm-sdk
Secure WebSocket communication (wss://) is supported natively
for Python 2.7.9+ and PyPy 2.6+ only.
If the SDK installation step detects Python older than 2.7.9 without secure TLS socket implementation (For example CentOS 7 has Python 2.7.5), it installs the secure replacement backports.ssl. Beware that it requires OpenSSL library, Python development headers and a C compiler to be available.
This should work on CentOS 7:
yum install -y epel-release
yum install -y python-pip gcc python-devel openssl-devel
pip install satori-rtm-sdk
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-rtm-sdk 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": "wss://<SATORI_HOST>/",
"appkey": "<APP_KEY>",
"auth_role_name": "<ROLE_NAME>",
"auth_role_secret_key": "<ROLE_SECRET_KEY>",
"auth_restricted_channel": "<CHANNEL_NAME>"
}
endpointis your customer-specific DNS name for RTM access.appkeyis your application key.auth_role_nameis a role name that permits publishing / subscribing toauth_restricted_channel. Must be notdefault.auth_role_secret_keyis a secret key forauth_role_name.auth_restricted_channelis a channel with subscribe and publish access forauth_role_namerole only.
You must use DevPortal to create role and set channel permissions.
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 pypy, py34 or py35 to choose a
desired Python implementation.