generic_exporters package

Subpackages

Submodules

generic_exporters.dataset module

class generic_exporters.dataset.Dataset(data: _DT)

Bases: ASyncGenericBase, Dict[datetime, _DT]

A container for time series data, supporting various operations.

This class extends the standard Python dictionary to create a specialized container for time series data. It is keyed by datetime objects and can hold TimeSeries, WideTimeSeries, or TimeDataRow instances as values. The Dataset class provides methods for plotting, exporting to CSV, and other operations useful in handling time series data.

Parameters:
  • Dict[datetime – Inherits from the standard dictionary with datetime keys and values of type TimeSeries, WideTimeSeries, or TimeDataRow.

  • _DT] – Inherits from the standard dictionary with datetime keys and values of type TimeSeries, WideTimeSeries, or TimeDataRow.

export

Exports the dataset to a specified datastore.

This method is intended to provide a way to export the time series data contained within the Dataset to an external datastore.

Parameters:

datastore – The target datastore to which the Dataset should be exported.

plot

Generates a plot for the dataset.

This method is intended to provide a quick visualization of the time series data contained within the Dataset.

Returns:

an object containing the plotted data.

Return type:

Figure

to_csv

Exports the dataset to a CSV file.

This method is intended to provide a way to export the time series data contained within the Dataset to a CSV file.

generic_exporters.metric module

class generic_exporters.metric.Constant(value: _T)

Bases: Metric

A Constant is a Metric object that produces the same result at any given timestamp. These are used to perform math operations between a Metric object and a constant value to create a new Metric object that represents the result of the operation.

property key: None

A human-readable label for the metric being exported that will also be used as a unique key to identify this Metric in the datastore

produce
class generic_exporters.metric.Metric

Bases: _MathableBase

_validate_other(other) Metric

Validates the other operand to ensure it is compatible for arithmetic operations.

This method must be implemented by subclasses to define how operands are validated.

Parameters:

other – The operand to validate.

Returns:

The validated operand, potentially converted or wrapped to ensure compatibility.

Return type:

_T

abstract property key: str

A human-readable label for the metric being exported that will also be used as a unique key to identify this Metric in the datastore

produce

Computes and returns the measurement at timestamp for this particular Metric

sync = False

A Metric represents a numeric measurement taken periodically over time. It contains the logic for taking that measurement at a specific timestamp and generating a unique key for the result.

You can perform math operations on two Metric objects, the result will be a new Metric that can produce the result of the math operation between the two input `Metric`s at any given timestamp.

You can also slice a Metric object to return a Timeseries future-like object that can materialize data for a specific time range and perform operations with the outputs.

class generic_exporters.metric._AdditionMetric(metric0: Metric, metric1: Metric)

Bases: _MathResultMetricBase

An AdditionMetric is a Metric that queries two input Metrics at any given timestamp, adds their outputs, and returns the sum.

They are created by the library when you add two Metric objects. You should not need to interact with this class directly.

_symbol = '+'
class generic_exporters.metric._FloorDivisionMetric(metric0: Metric, metric1: Metric)

Bases: _MathResultMetricBase

A FloorDivisionMetric is a Metric that queries two input Metrics at any given timestamp, divides their outputs, and returns the floored quotient.

They are created by the library when you divide two Metric objects. You should not need to interact with this class directly.

_symbol = '//'
class generic_exporters.metric._MathResultMetricBase(metric0: Metric, metric1: Metric)

Bases: Metric

These are created by the library when you perform math operations on Metric objects. You should not need to interact with this class directly

abstract property _symbol: str

The symbol of the math operation being performed

property key: str

A human-readable label for the metric being exported that will also be used as a unique key to identify this Metric in the datastore

produce
class generic_exporters.metric._MultiplicationMetric(metric0: Metric, metric1: Metric)

Bases: _MathResultMetricBase

A MultiplicationMetric is a Metric that queries two input Metrics at any given timestamp, multiplies their outputs, and returns the product.

They are created by the library when you multiply two Metric objects. You should not need to interact with this class directly.

_symbol = '*'
class generic_exporters.metric._PowerMetric(metric0: Metric, metric1: Metric)

Bases: _MathResultMetricBase

A PowerMetric is a Metric that queries two input Metrics at any given timestamp, raises the output of the first to the power of the output of the second, and returns the exponentiation.

They are created by the library when you exponentiate two Metric objects. You should not need to interact with this class directly.

_symbol = '**'
class generic_exporters.metric._SubtractionMetric(metric0: Metric, metric1: Metric)

Bases: _MathResultMetricBase

A SubtractionMethod is a Metric that queries two input Metrics at any given timestamp, subtracts their outputs, and returns the difference.

They are created by the library when you subtract two Metric objects. You should not need to interact with this class directly.

_symbol = '-'
class generic_exporters.metric._TrueDivisionMetric(metric0: Metric, metric1: Metric)

Bases: _MathResultMetricBase

A TrueDivisionMetric is a Metric that queries two input Metrics at any given timestamp, divides their outputs, and returns the true quotient.

They are created by the library when you divide two Metric objects. You should not need to interact with this class directly.

_symbol = '/'

generic_exporters.plan module

final class generic_exporters.plan.QueryPlan(dataset: TimeSeries | WideTimeSeries, start_timestamp: datetime | Awaitable[datetime], end_timestamp: datetime, interval: timedelta, *, sync: bool = True)

Bases: _QueryPlan[Metric, Decimal]

Represents a plan for querying time series data within a specified range.

This class encapsulates the logic for generating and executing a plan to query time series data. It supports asynchronous iteration over the generated data points and provides methods for plotting and converting the data to a pandas DataFrame.

dataset

The dataset to be queried.

Type:

Union[TimeSeries, WideTimeSeries]

start_timestamp

The start of the query range.

Type:

LooseDatetime

end_timestamp

The end of the query range.

Type:

datetime

interval

The interval between data points in the query.

Type:

timedelta

sync

A flag indicating whether operations should be performed synchronously or asynchronously.

Type:

bool

Parameters:
  • dataset (Union[TimeSeries, WideTimeSeries]) – The dataset to be queried.

  • start_timestamp (LooseDatetime) – The start of the query range.

  • end_timestamp (datetime) – The end of the query range.

  • interval (timedelta) – The interval between data points in the query.

  • sync (bool, optional) – Specifies if operations should be executed synchronously. Defaults to True.

final class generic_exporters.plan.TimeDataRow(timestamp: datetime, fields: Iterable[Metric | TimeSeries], sync: bool = True)

Bases: _TimeDataRow[Metric]

A future-like class that can be awaited to materialize results

timestamp
class generic_exporters.plan._QueryPlan(dataset: TimeSeries | WideTimeSeries, start_timestamp: datetime | Awaitable[datetime], end_timestamp: datetime, interval: timedelta, *, sync: bool = True)

Bases: _TimeDataBase, ASyncIterable[TimeDataRow[_M]], _AwaitableMixin[Dict[_M, _T]]

__start_timestamp__: HiddenMethodDescriptor[Self, datetime]
async _aiter_timestamps(run_forever: bool = False) AsyncGenerator[datetime, None]

Generates the timestamps to be queried based on the specified range and interval.

async _materialize() Dataset

Materializes the query plan, executing the necessary asynchronous operations and returning the results.

dataframe

Converts the queried data to a pandas DataFrame.

Returns:

A pandas DataFrame representing the queried time series data.

Return type:

DataFrame

plot

Generates a plot for the queried data.

Returns:

A plot representing the queried time series data.

Return type:

Figure

start_timestamp

Computes the start timestamp for the query, handling asynchronous resolution if necessary.

class generic_exporters.plan._TimeDataRow(timestamp: datetime, fields: Iterable[Metric | TimeSeries], sync: bool = True)

Bases: _TimeDataBase, _AwaitableMixin[Dict[_M, Decimal]], Mapping[str, Coroutine[Any, Any, Decimal]]

A future-like class that can be awaited to materialize results. You can subclass this for type checking with your own Metric subtypes.

async _materialize() Dict[_M, Decimal | Exception]

Abstract method that subclasses must implement to define the awaitable operation.

This method should contain the asynchronous logic that is to be executed when an instance of the subclass is awaited. It must be implemented by subclasses.

Returns:

The result of the asynchronous operation.

Return type:

_T

property key: datetime
property tasks: TaskMapping[_M, Decimal]
timestamp
generic_exporters.plan._get_waiter(timestamp: datetime) Task[None]
generic_exporters.plan._ts_is_ready(timestamp: datetime, interval: timedelta) bool
generic_exporters.plan._validate_time_params(start_timestamp: datetime, end_timestamp: datetime | None, interval: timedelta)

Validates the time parameters for the query plan.

async generic_exporters.plan._wait(wait_until: datetime) None
generic_exporters.plan._wait_callback(t: Task) None

generic_exporters.timeseries module

final class generic_exporters.timeseries.TimeSeries(metric: Metric, *, sync: bool = True)

Bases: _TimeSeriesBase

An object representing the infinite series of values for a particular Metric across the time axis. NOTE: Imagine a line chart with a single line that has yet to be drawn.

You can slice a TimeSeries object to create a Dataset which can be used for exporting, plotting, and other fun things #NOTE: not yet implemented

tcollection of asyncio.Tasks that each will return one datapoint for a specific timestamp for a Metric object.

__validate_other(other: Metric | TimeSeries) None
property key: str
final class generic_exporters.timeseries.WideTimeSeries(*timeserieses: _T, sync: bool = True)

Bases: _WideTimeSeries[Metric | TimeSeries]

A collection of TimeSeries objects NOTE: Imagine a line chart with multiple lines that have yet to be drawn

class generic_exporters.timeseries._TimeSeriesBase(fields: Iterable[Metric | TimeSeries], *, sync: bool = True)

Bases: _TimeDataBase

class generic_exporters.timeseries._WideTimeSeries(*timeserieses: _T, sync: bool = True)

Bases: _TimeSeriesBase, Generic[_T]

You can subclass this to specify input types for custom applications

property key: str
generic_exporters.timeseries._convert_metrics(items: Iterable[Metric | TimeSeries]) List[TimeSeries]

Module contents