There's no direct way to read observations from a datastream over HTTP.
Writing one is first-class:
datastream.insert_observation_dict({...})
Reading them back is not — you go through the API helper and name the resource types yourself, and get a raw requests.Response:
node.get_api_helper().get_resource(
APIResourceTypes.DATASTREAM, datastream.get_id(),
APIResourceTypes.OBSERVATION, params={"limit": 5},
)
The alternative, api_helpers.list_observations_from_datastream(), makes you re-supply the server URL and credentials the Node already holds, and accepts no query parameters.
Proposal
Add Datastream.get_observations(), mirroring insert_observation_dict:
observations = datastream.get_observations(limit=5)
observations = datastream.get_observations(result_time="latest")
It would use the parent node's configured credentials, take the common CS API query params (limit, resultTime, phenomenonTime) as keyword arguments, and run results through the datastream's cached record schema via decode_observation so the binary wire formats work the same as JSON.
StreamableResource already declares poll() and fetch(time_period) as no-op stubs (resources/base.py), so fetch() could be implemented on top of this.
Open questions
- Return plain dicts, or parsed
ObservationResource models?
- Follow the
links-based pagination, or return just the first page?
There's no direct way to read observations from a datastream over HTTP.
Writing one is first-class:
Reading them back is not — you go through the API helper and name the resource types yourself, and get a raw
requests.Response:The alternative,
api_helpers.list_observations_from_datastream(), makes you re-supply the server URL and credentials theNodealready holds, and accepts no query parameters.Proposal
Add
Datastream.get_observations(), mirroringinsert_observation_dict:It would use the parent node's configured credentials, take the common CS API query params (
limit,resultTime,phenomenonTime) as keyword arguments, and run results through the datastream's cached record schema viadecode_observationso the binary wire formats work the same as JSON.StreamableResourcealready declarespoll()andfetch(time_period)as no-op stubs (resources/base.py), sofetch()could be implemented on top of this.Open questions
ObservationResourcemodels?links-based pagination, or return just the first page?