Skip to main content


pubsub-python is a Python example illustrating the use of the Syntropy Data Layer project, which facilitates subscription to existing data streams or publishing new ones. This example employs the NATS messaging system and offers a simpler starting point for integrating Python applications with the Syntropy Data Layer platform.


To install the Python SDK for Data Layer, you can use pip, the Python package manager. Here's an example of how to install it:

pip install syntropynet-pubsub

Getting Started

Before you begin using the Python SDK, make sure you have the necessary credentials and access tokens from the Syntropy Developer Portal platform. These credentials will allow you to connect to the Data Layer and subscribe to or publish data streams.


For detailed usage examples, please refer to the examples in the repository. These examples cover various scenarios and demonstrate how to utilize the SDK's features effectively.

The preferred authentication method is using an access token from the developer portal.

import asyncio
import nats
import tempfile
import os

from helper import create_app_jwt


async def main():
jwt = create_app_jwt(access_token)

# Write the JWT to a temporary file with correct format
with tempfile.NamedTemporaryFile(mode='w+t', delete=False) as temp:
temp_path =

nc = await nats.connect("nats://", user_credentials=temp_path)

async def message_handler(msg):
subject = msg.subject
data =
print("Received a message on '{subject}: {data}".format(
subject=subject, data=data))
# await nc.publish("syntropy.test.subject",

await nc.subscribe("syntropy.bitcoin.tx", cb=message_handler)

# run infinitely
while True:
await asyncio.sleep(1)

# Terminate connection to NATS.
await nc.drain()

# Delete the temporary file

if __name__ == '__main__':


If you encounter any difficulties or have questions regarding the Python SDK for Data Layer, please reach out to our support team at Discord #developer-discussion. We are here to assist you and ensure a smooth experience with our SDK.

We hope this documentation provides you with a comprehensive understanding of the Python SDK for the Data Layer. Happy coding with real-time data streams and enjoy the power of the Data Layer in your Python applications!