0.60

ReferenceClient librariesQuick start

Quick start

Install the Python or TypeScript client, connect to a Synnax Core, and write and read your first samples.

In this tutorial, you write a script that stores five pressure samples in a Synnax Core and reads them back. It takes about five minutes. Each step adds code to one file: quick_start.py for Python or quick_start.ts for TypeScript. Do not name the Python file synnax.py, because that name hides the synnax package.

You need:

  • Synnax Desktop on your computer, or a Core in Synnax Enterprise that your computer can reach, and a username and password for it.
  • Python 3.12 or later, or Node.js 22 or later.

Install the client

Enterprise
pip install synnax

Install the client version that matches the major and minor version of your Core, such as client 0.58 for Core 0.58. The client prints a warning when the versions differ.

Connect to the Core

Replace the address and credentials with the values of your Core. For TLS and other options, see Connect to a Core.

With Synnax Desktop, the Python client finds the Core by itself: call sy.Synnax() with no arguments. For TypeScript, copy the code from the Connect from code dialog. See Connect to Synnax Desktop.

Enterprise
import synnax as sy

client = sy.Synnax(
    host="localhost",
    port=9090,
    username="synnax",
    password="seldon",
)

Create two channels

The samples go in a data channel, and their timestamps go in an index channel. For more about channels, see Create channels.

Enterprise
time = client.channels.create(
    name="tank_time",
    data_type=sy.DataType.TIMESTAMP,
    is_index=True,
    retrieve_if_name_exists=True,
)
pressure = client.channels.create(
    name="tank_pressure",
    data_type=sy.DataType.FLOAT32,
    index=time.key,
    retrieve_if_name_exists=True,
)

Write five samples

Write one sample every 100 milliseconds, starting now:

Enterprise
start = sy.TimeStamp.now()
client.write(
    start,
    {
        "tank_time": [
            start + sy.TimeSpan.MILLISECOND * 100 * i for i in range(5)
        ],
        "tank_pressure": [20.0, 20.5, 21.0, 21.5, 22.0],
    },
)

Read the samples back

Enterprise
samples = client.read(
    sy.TimeRange(start, start + sy.TimeSpan.SECOND),
    "tank_pressure",
)
print(samples.to_numpy())
client.close()

Run the script

Enterprise
python quick_start.py

The script prints the five samples that it wrote:

[20.  20.5 21.  21.5 22. ]

When the channels exist, the script uses them, so you can run it again.

Next steps

  • Series and frames -> work with the data that a read returns.
  • Write data -> write samples as they arrive with a writer.
  • Read data -> read many channels, the latest samples, or large time ranges.
  • Stream data -> get samples live, as the Core receives them.