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 open on your computer. You can also use a Core in Synnax Enterprise that your computer can reach, with a username and password for it.
- Python 3.13 or later, or Node.js 22.12 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.61 for Core 0.61. The client prints a warning when the versions differ, and the TypeScript client can stop with an error. The Connect from code dialog of Synnax Desktop gives the install command that matches. To open it, click the code button in the top bar of Synnax Desktop.
Install without internet access
If the computer for your script has no internet access, download the Python client and
its dependencies on a computer that does. Use a computer with the same operating system,
CPU architecture, and Python version. Replace 0.61 with the major and minor version of
your Core:
pip download "synnax==0.61.*" -d synnax-wheelsCopy the synnax-wheels folder to the computer with no internet access, then install
from it:
pip install --no-index --find-links synnax-wheels synnaxDo not download with --platform for a different operating system. pip then skips the
dependencies that only that operating system needs, and the install fails.
Connect to the Core
Python
TypeScript
With Synnax Desktop open, the Python client finds its Core by itself:
import synnax as sy
client = sy.Synnax()For a Core in Synnax Enterprise, give its address and your credentials:
client = sy.Synnax(
host="core.example.com",
port=9090,
username="operator",
password="secret",
)With Synnax Desktop open, the TypeScript client finds its Core by itself:
import { DataType, Synnax, TimeSpan, TimeStamp } from "@synnaxlabs/client";
const client = new Synnax();For a Core in Synnax Enterprise, give its address and your credentials:
const client = new Synnax({
host: "core.example.com",
port: 9090,
username: "operator",
password: "secret",
});For TLS, API keys, and other options, see Connect to a Core.
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.tsWith Bun, run bun quick_start.ts. With Deno, run
deno run --allow-net quick_start.ts.
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.