I’d like to add a little to @Johannes Hovda answer:
1) Start/end
Be careful using start=0
(1970-01-01) as the time series API support timestamps all the way back to the year 1900. Following the examples in the documentation, you may import, for your convenience, the very first possible timestamp to be dead sure not to miss anything!
The oppositely is true for end
, which defaults to "now"
if not specified. Thus, if a time series first datapoint lies into the future, you need to specify end to retrieve it. API supports up to 2099-12-31 23:59:59.999
>>> from cognite.client.utils import MIN_TIMESTAMP_MS, MAX_TIMESTAMP_MS
>>> dps_backup = client.time_series.data.retrieve(
... id=123,
... start=MIN_TIMESTAMP_MS,
... end=MAX_TIMESTAMP_MS + 1) # end is exclusive
2) Efficient queries
You write that you have “thousands of time series” that you need to find the initial datapoint of and this could be very inefficient to query, if not done correctly.
The time series API allows for datapoints to be requested for up to 100 different time series in the same request. The Python SDK will combine your datapoint queries automatically if you ask for them all in one go:
>>> initial_dps = client.time_series.data.retrieve(
... start=MIN_TIMESTAMP_MS,
... end=MAX_TIMESTAMP_MS + 1, # end is exclusive
... external_id=a_few_thousand_ids,
... limit=1)
3) ...for other readers with very few time series
If you have a TimeSeries
object fetched from CDF, you can simply all the .first()
method on it:
>>> ts = client.time_series.retrieve(id=123)
>>> first_dp = ts.first()