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
Python
TypeScript
pip install synnaxThe script uses top-level await, so make an ES module project:
npm init -y
npm pkg set type=module
npm install @synnaxlabs/client tsxInstall 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.
Python
TypeScript
import synnax as sy
client = sy.Synnax(
host="localhost",
port=9090,
username="synnax",
password="seldon",
)import { DataType, Synnax, TimeSpan, TimeStamp } from "@synnaxlabs/client";
const client = new 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.
Python
TypeScript
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,
)const time = await client.channels.create(
{ name: "tank_time", dataType: DataType.TIMESTAMP, isIndex: true },
{ retrieveIfNameExists: true },
);
const pressure = await client.channels.create(
{ name: "tank_pressure", dataType: DataType.FLOAT32, index: time.key },
{ retrieveIfNameExists: true },
);Write five samples
Write one sample every 100 milliseconds, starting now:
Python
TypeScript
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],
},
)const start = TimeStamp.now();
const step = TimeSpan.milliseconds(100);
await client.write(start, {
tank_time: [0, 1, 2, 3, 4].map((i) => start.add(step.mult(i))),
tank_pressure: [20.0, 20.5, 21.0, 21.5, 22.0],
});Read the samples back
Python
TypeScript
samples = client.read(
sy.TimeRange(start, start + sy.TimeSpan.SECOND),
"tank_pressure",
)
print(samples.to_numpy())
client.close()const samples = await client.read(
{ start, end: start.add(TimeSpan.seconds(1)) },
"tank_pressure",
);
console.log(Array.from(samples));
await client.close();Run the script
Python
TypeScript
python quick_start.pyThe script prints the five samples that it wrote:
[20. 20.5 21. 21.5 22. ]npx tsx quick_start.tsThe 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.