0.60

ReferenceClient librariesTime types

Time types

Create and use timestamps, time spans, time ranges, and rates with nanosecond precision in the Python and TypeScript clients.

Synnax stores each timestamp as a 64-bit integer: the number of nanoseconds since the Unix epoch, 1970-01-01 00:00:00 UTC. The clients give you four types that keep this precision:

Type Holds Python TypeScript
TimeStamp A point in time. sy.TimeStamp.now() TimeStamp.now()
TimeSpan A duration. sy.TimeSpan.SECOND * 5 TimeSpan.seconds(5)
TimeRange The time from start to end. sy.TimeRange(start, end) new TimeRange(start, end)
Rate A frequency, in hertz. sy.Rate.HZ * 100 Rate.hz(100)

Methods such as read and write take a time type, or any value that its constructor takes, such as a datetime in Python or a Date in TypeScript.

TimeStamp

Create a timestamp

Enterprise
from datetime import datetime, timezone

import pandas as pd
import synnax as sy

now = sy.TimeStamp.now()

# From a datetime. A datetime with no time zone is in local time.
start = sy.TimeStamp(datetime(2026, 10, 3, 12, 0, tzinfo=timezone.utc))

# From a pandas Timestamp.
start = sy.TimeStamp(pd.Timestamp("2026-10-03 12:00:00", tz="UTC"))

# From nanoseconds since the Unix epoch.
start = sy.TimeStamp(1_791_028_800_000_000_000)

The Python client does not parse strings: sy.TimeStamp("2026-10-03") raises a ValueError. Parse the string with datetime.fromisoformat or pandas first.

Add, subtract, and compare

Enterprise
later = start + sy.TimeSpan.MINUTE
print(later - start)  # 1m
print(later > start)  # True
print(later.after_eq(start))  # True

Subtracting two timestamps returns the time between them as a TimeSpan. Add or subtract a TimeSpan, not a bare number: start + 5 raises a TypeError.

Convert a timestamp

Enterprise
print(start.datetime(tz=timezone.utc))  # 2026-10-03 12:00:00+00:00
print(start.datetime())  # The same time, in the local time zone.
print(int(start))  # 1791028800000000000

TimeSpan

Enterprise
from datetime import timedelta

timeout = sy.TimeSpan.MILLISECOND * 250
print(timeout)  # 250ms
print(timeout.seconds)  # 0.25
print(sy.TimeSpan.from_seconds(1.5))  # 1s 500ms
print(sy.TimeSpan(timedelta(minutes=2)))  # 2m
print(timeout / 2)  # 125ms
print(sy.TimeSpan.MINUTE / sy.TimeSpan.SECOND)  # 60.0

The constants are NANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, and DAY. The properties seconds, milliseconds, and the other units return floats, and timedelta returns a Python timedelta.

TimeRange

A time range includes its start and excludes its end. A sample at the end of a time range belongs to the next time range, so time ranges that touch never hold the same sample:

Time range ATime range B12:0013:0014:00includedexcluded
Enterprise
end = start + sy.TimeSpan.HOUR
tr = sy.TimeRange(start, end)
print(tr.span)  # 1h
print(tr.contains(start))  # True
print(tr.contains(end))  # False

# Other ways to make the same range.
tr = start.range(end)
tr = start.span_range(sy.TimeSpan.HOUR)

contains also takes a TimeRange, and returns true when the whole time range is inside, ends included.

Rate

A rate is a frequency in hertz.

Enterprise
rate = sy.Rate.HZ * 100
print(rate)  # 100.0 Hz
print(rate.period)  # 10ms

sy.Rate(100) is the same rate. The constants are HZ, KHZ, and MHZ. Hardware task configurations take a Rate or a number of hertz for sample_rate and stream_rate.

Precision

The time types keep every nanosecond. The native types of each language keep less, so a conversion can lose precision:

Enterprise

A datetime keeps microseconds. TimeStamp.datetime rounds to the nearest microsecond:

ts = sy.TimeStamp(1_609_459_200_123_456_789)
print(ts.datetime(tz=timezone.utc))  # 2021-01-01 00:00:00.123457+00:00