V1 Stream API
The stream
module contains classes that fetch timeseries data using
V1 Stream API.
Warning
The V1 API is supported, but it is not longer under active development. We recommend
using the resources
module instead, which provides access to data from the V2 Stream API.
However, you should be aware that the data returned by the V1 and V2 APIs are independent. Some types of data may only be available from one API or the other. If you have questions about which API to use, please contact Rune Support.
Usage
Initialization
The global initialization method, as described in the Quickstart (Initialization),
does NOT apply to requests made by the stream
module.
Start by creating a V1Client
, using a Config
.
The configuration class uses the file that was created via the command line tool (see
Configuration Setup).
from runeq import Config, stream
cfg = Config()
v1client = stream.V1Client(cfg)
Methods on the V1Client
are used to create accessors for each
type of data that can be queried using the V1 Stream API (e.g. accelerometry, events, local
field potentials, etc).
The example below initializes an Accel
class, which will allow us
to fetch accelerometry data:
accel = v1client.Accel(
patient_id='992967a09cad48378f7b628aff5bdf6c',
device_id='ABCDEF',
start_time=1562482800,
end_time=1563692400,
)
Accessors can be initialized with default query parameters, which will be used for all API requests.
JSON Endpoints
An accessor can be used to iterate over paginated data from the respective JSON endpoint:
for result in accel.iter_json_data():
print(result.keys())
To override the default query parameters, use keyword arguments:
for text in accel.iter_json_data(device_id='patient-ABC,device-456'):
pass # do something
CSV Endpoints
An accessor can also iterate over paginated data from the respective CSV endpoint.
Here, we use the accessor to build up a pandas DataFrame, containing the complete result set.
import io
import pandas as pd
df = pd.DataFrame()
for text in accel.iter_csv_text():
page_df = pd.read_csv(io.StringIO(text))
df.append(page_df)
We can also iterate over each point from the CSV response. Each line from the CSV is returned as a dict:
for point in accel.points():
print(point)
# the accessor itself is also an iterator
for point in accel:
print(point)
To override the default query parameters, use keyword arguments:
for point in accel.points(end_time=1563692400):
pass # do something
for text in accel.iter_csv_text(device_id='patient-ABC,device-456'):
pass # do something
# etc
Note that CSV-formatted data is not supported for all resources: refer to the API documentation for details.
V1Client
- class runeq.stream.V1Client(cfg: Config)
V1Client is a factory class. It holds configuration, which is used to initialize accessor classes for Stream V1 endpoints.
- Accel(**defaults) Accel
Initialize an Accel accessor.
- Parameters
**defaults – Default query parameters
- BandPower(**defaults) BandPower
Initialize a BandPower accessor.
- Parameters
**defaults – Default query parameters
- Event(**defaults) Event
Initialize an Event accessor.
- Parameters
**defaults – Default query parameters
- HeartRate(**defaults) HeartRate
Initialize a HeartRate accessor.
- Parameters
**defaults – Default query parameters
- ProbabilitySymptom(**defaults) ProbabilitySymptom
Initialize a ProbabilitySymptom accessor.
- Parameters
**defaults – Default query parameters
- Rotation(**defaults) Rotation
Initialize a Rotation accessor.
- Parameters
**defaults – Default query parameters
- Span(**defaults) Span
Initialize a Span accessor.
- Parameters
**defaults – Default query parameters
Accessors
Query data from the Rune Labs Stream API (V1).
Each resource that is exposed by the Stream API can be queried through an accessor class.
Accel
- class runeq.stream.v1.Accel(cfg: Config, **defaults)
Query accelerometry data streams.
- property expr_availability
Availability expression for this resource.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- get_csv_response(**params) Response
Make a GET request to the resource’s CSV endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Returns
requests.Response
- get_json_response(**params) Response
Make a GET request to the resource’s JSON endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis, for this request.
- Returns
requests.Response
- iter_csv_availability(**params) Iterator[dict]
Convenience method to query the CSV endpoint, using the availability expression. May not be supported for all resources.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_csv_text(**params) Iterator[str]
Iterate over CSV text results, from the resource’s CSV endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
APIError – when a request fails
- iter_json_availability(**params) Iterator[dict]
Convenience method to query the JSON endpoint, using the availability expression. This may not be supported for all endpoints.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_json_data(**params) Iterator[dict]
Iterate over results from the resource’s JSON endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
APIError – when a request fails
- points(**params) Iterator[dict]
Iterate over points from CSV response, yielding dictionaries.
This may involve multiple requests to the CSV endpoint, to follow pagination.
- Parameters
**params – query parameters for the request(s). These override self.defaults on a key-by-key basis.
- Yields
dict – Keys are the headers from the CSV response. Values are converted to numeric types where applicable. If numpy is available, np.float64 is used.
BandPower
- class runeq.stream.v1.BandPower(cfg: Config, **defaults)
Query band power data streams.
- property expr_availability
Availability expression for this resource.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- get_csv_response(**params) Response
Make a GET request to the resource’s CSV endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Returns
requests.Response
- get_json_response(**params) Response
Make a GET request to the resource’s JSON endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis, for this request.
- Returns
requests.Response
- iter_csv_availability(**params) Iterator[dict]
Convenience method to query the CSV endpoint, using the availability expression. May not be supported for all resources.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_csv_text(**params) Iterator[str]
Iterate over CSV text results, from the resource’s CSV endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
APIError – when a request fails
- iter_json_availability(**params) Iterator[dict]
Convenience method to query the JSON endpoint, using the availability expression. This may not be supported for all endpoints.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_json_data(**params) Iterator[dict]
Iterate over results from the resource’s JSON endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
APIError – when a request fails
- points(**params) Iterator[dict]
Iterate over points from CSV response, yielding dictionaries.
This may involve multiple requests to the CSV endpoint, to follow pagination.
- Parameters
**params – query parameters for the request(s). These override self.defaults on a key-by-key basis.
- Yields
dict – Keys are the headers from the CSV response. Values are converted to numeric types where applicable. If numpy is available, np.float64 is used.
Event
- class runeq.stream.v1.Event(cfg: Config, **defaults)
Query patient events.
- property expr_availability
Availability expression for this resource.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- get_json_response(**params) Response
Make a GET request to the resource’s JSON endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis, for this request.
- Returns
requests.Response
- iter_json_availability(**params) Iterator[dict]
Convenience method to query the JSON endpoint, using the availability expression. This may not be supported for all endpoints.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_json_data(**params) Iterator[dict]
Iterate over results from the resource’s JSON endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
APIError – when a request fails
HeartRate
- class runeq.stream.v1.HeartRate(cfg: Config, **defaults)
Query heart rate data streams.
- property expr_availability
Availability expression for this resource.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- get_csv_response(**params) Response
Make a GET request to the resource’s CSV endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Returns
requests.Response
- get_json_response(**params) Response
Make a GET request to the resource’s JSON endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis, for this request.
- Returns
requests.Response
- iter_csv_availability(**params) Iterator[dict]
Convenience method to query the CSV endpoint, using the availability expression. May not be supported for all resources.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_csv_text(**params) Iterator[str]
Iterate over CSV text results, from the resource’s CSV endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
APIError – when a request fails
- iter_json_availability(**params) Iterator[dict]
Convenience method to query the JSON endpoint, using the availability expression. This may not be supported for all endpoints.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_json_data(**params) Iterator[dict]
Iterate over results from the resource’s JSON endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
APIError – when a request fails
- points(**params) Iterator[dict]
Iterate over points from CSV response, yielding dictionaries.
This may involve multiple requests to the CSV endpoint, to follow pagination.
- Parameters
**params – query parameters for the request(s). These override self.defaults on a key-by-key basis.
- Yields
dict – Keys are the headers from the CSV response. Values are converted to numeric types where applicable. If numpy is available, np.float64 is used.
LFP
- class runeq.stream.v1.LFP(cfg: Config, **defaults)
Query local field potential (LFP) data streams.
- property expr_availability
Availability expression for this resource.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- get_csv_response(**params) Response
Make a GET request to the resource’s CSV endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Returns
requests.Response
- get_json_response(**params) Response
Make a GET request to the resource’s JSON endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis, for this request.
- Returns
requests.Response
- iter_csv_availability(**params) Iterator[dict]
Convenience method to query the CSV endpoint, using the availability expression. May not be supported for all resources.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_csv_text(**params) Iterator[str]
Iterate over CSV text results, from the resource’s CSV endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
APIError – when a request fails
- iter_json_availability(**params) Iterator[dict]
Convenience method to query the JSON endpoint, using the availability expression. This may not be supported for all endpoints.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_json_data(**params) Iterator[dict]
Iterate over results from the resource’s JSON endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
APIError – when a request fails
- points(**params) Iterator[dict]
Iterate over points from CSV response, yielding dictionaries.
This may involve multiple requests to the CSV endpoint, to follow pagination.
- Parameters
**params – query parameters for the request(s). These override self.defaults on a key-by-key basis.
- Yields
dict – Keys are the headers from the CSV response. Values are converted to numeric types where applicable. If numpy is available, np.float64 is used.
ProbabilitySymptom
- class runeq.stream.v1.ProbabilitySymptom(cfg: Config, **defaults)
Query the probability of a symptom.
- property expr_availability
Availability expression for this resource.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- get_csv_response(**params) Response
Make a GET request to the resource’s CSV endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Returns
requests.Response
- get_json_response(**params) Response
Make a GET request to the resource’s JSON endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis, for this request.
- Returns
requests.Response
- iter_csv_availability(**params) Iterator[dict]
Convenience method to query the CSV endpoint, using the availability expression. May not be supported for all resources.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_csv_text(**params) Iterator[str]
Iterate over CSV text results, from the resource’s CSV endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
APIError – when a request fails
- iter_json_availability(**params) Iterator[dict]
Convenience method to query the JSON endpoint, using the availability expression. This may not be supported for all endpoints.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_json_data(**params) Iterator[dict]
Iterate over results from the resource’s JSON endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
APIError – when a request fails
- points(**params) Iterator[dict]
Iterate over points from CSV response, yielding dictionaries.
This may involve multiple requests to the CSV endpoint, to follow pagination.
- Parameters
**params – query parameters for the request(s). These override self.defaults on a key-by-key basis.
- Yields
dict – Keys are the headers from the CSV response. Values are converted to numeric types where applicable. If numpy is available, np.float64 is used.
Rotation
- class runeq.stream.v1.Rotation(cfg: Config, **defaults)
Query rotation data streams.
- property expr_availability
Availability expression for this resource.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- get_csv_response(**params) Response
Make a GET request to the resource’s CSV endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Returns
requests.Response
- get_json_response(**params) Response
Make a GET request to the resource’s JSON endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis, for this request.
- Returns
requests.Response
- iter_csv_availability(**params) Iterator[dict]
Convenience method to query the CSV endpoint, using the availability expression. May not be supported for all resources.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_csv_text(**params) Iterator[str]
Iterate over CSV text results, from the resource’s CSV endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
APIError – when a request fails
- iter_json_availability(**params) Iterator[dict]
Convenience method to query the JSON endpoint, using the availability expression. This may not be supported for all endpoints.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_json_data(**params) Iterator[dict]
Iterate over results from the resource’s JSON endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
APIError – when a request fails
- points(**params) Iterator[dict]
Iterate over points from CSV response, yielding dictionaries.
This may involve multiple requests to the CSV endpoint, to follow pagination.
- Parameters
**params – query parameters for the request(s). These override self.defaults on a key-by-key basis.
- Yields
dict – Keys are the headers from the CSV response. Values are converted to numeric types where applicable. If numpy is available, np.float64 is used.
Span
- class runeq.stream.v1.Span(cfg: Config, **defaults)
Query spans.
- property expr_availability
Availability expression for this resource.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- get_json_response(**params) Response
Make a GET request to the resource’s JSON endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis, for this request.
- Returns
requests.Response
- iter_json_availability(**params) Iterator[dict]
Convenience method to query the JSON endpoint, using the availability expression. This may not be supported for all endpoints.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_json_data(**params) Iterator[dict]
Iterate over results from the resource’s JSON endpoint.
Follows pagination to get a complete set of results.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
APIError – when a request fails
State
- class runeq.stream.v1.State(cfg: Config, **defaults)
Query device state.
- property expr_availability
Availability expression for this resource.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- get_csv_response(**params) Response
Make a GET request to the resource’s CSV endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Returns
requests.Response
- get_json_response(**params) Response
Make a GET request to the resource’s JSON endpoint.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis, for this request.
- Returns
requests.Response
- iter_csv_availability(**params) Iterator[dict]
Convenience method to query the CSV endpoint, using the availability expression. May not be supported for all resources.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_csv_text(**params) Iterator[str]
Iterate over CSV text results, from the resource’s CSV endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
text body of each response.
- Raises
APIError – when a request fails
- iter_json_availability(**params) Iterator[dict]
Convenience method to query the JSON endpoint, using the availability expression. This may not be supported for all endpoints.
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
NotImplementedError – if the resource doesn’t support an availability query expression.
- iter_json_data(**params) Iterator[dict]
Iterate over results from the resource’s JSON endpoint.
Follows pagination to get a complete set of results, starting with the page specified in the page kwarg (or the first page, by default).
- Parameters
**params – Query parameters for the request. These override self.defaults, on a key-by-key basis.
- Yields
dict with the “result” from the JSON body of each response.
- Raises
APIError – when a request fails
- points(**params) Iterator[dict]
Iterate over points from CSV response, yielding dictionaries.
This may involve multiple requests to the CSV endpoint, to follow pagination.
- Parameters
**params – query parameters for the request(s). These override self.defaults on a key-by-key basis.
- Yields
dict – Keys are the headers from the CSV response. Values are converted to numeric types where applicable. If numpy is available, np.float64 is used.