asphalt.influxdb.client

class asphalt.influxdb.client.DataPoint(measurement: str, tags: typing.Dict[str, typing.Any], fields: typing.Dict[str, typing.Union[int, float, decimal.Decimal, str]], timestamp: typing.Union[datetime.datetime, int] = None) → None

Bases: object

Represents a data point to be written to the database.

Variables:
  • measurement (str) – name of the measurement
  • tags – a dictionary of tag names to values
  • fields – a dictionary of field names to values
  • timestamp – time stamp for the measurement
class asphalt.influxdb.client.InfluxDBClient(base_urls: typing.Sequence[str] = 'http://localhost:8086', db: str = None, username: str = None, password: str = None, consistency: str = None, retention_policy: str = None, precision: str = None, chunked: int = None, epoch: str = None, session: typing.Union[aiohttp.client.ClientSession, str] = None, timeout: int = 60) → None

Bases: object

An asyncio based InfluxDB client.

To set advanced connection options like HTTP authentication, client certificates etc., see the documentation of the ClientSession and provide your own session argument to the constructor of this class.

Parameters:
  • base_urls (Sequence[str]) – an HTTP URL pointing to the InfluxDB server (or several URLs, in case of an InfluxEnterprise cluster)
  • db (Optional[str]) – default database to use
  • username (Optional[str]) – default user name to use for per-request authentication
  • password (Optional[str]) – default password to use for per-request authentication
  • consistency (Optional[str]) – default write consistency (for InfluxEnterprise) – one of any, one, quorum, all or None
  • precision (Optional[str]) – default timestamp precision for writes – one of n, u, ms, s, m, h or None
  • epoch (Optional[str]) – default timestamp precision for queries – one of n, u, ms, s, m, h or None
  • retention_policy (Optional[str]) – default retention policy name to use for writes
  • session (Union[ClientSession, str, None]) – an aiohttp session or a resource name of one (if omitted, one is created automatically and closed when the client is closed)
  • timeout (int) – timeout (in seconds) for all HTTP requests
coroutine ping(self)

Check connectivity to the server.

Return type:str
Returns:value of the X-Influxdb-Version response header
Raises:InfluxDBError – if the server returns an error or an unexpected HTTP status code
query(select, from_, **kwargs)

Create a query builder.

To execute the query, call its execute() method.

Parameters:
Return type:

SelectQuery

Returns:

a query builder object

coroutine raw_query(self, query, *, http_verb=None, **query_params)

Send a raw query to the server.

Parameters:
  • query (str) – the query string
  • http_verb (Optional[str]) – the HTTP verb (GET or POST) to use in the HTTP request (autodetected for most queries if omitted; SELECT ... INTO in particular cannot be autodetected)
  • query_params – HTTP query parameters
Return type:

Union[None, Series, List[Series], List[List[Series]]]

Returns:

depending on the query and the results:

  • None (if there are no series or errors in the results)
  • a single series
  • a list of series (if selecting from more than one measurement)
  • a list of lists of series (if the query string contained multiple queries)

Raises:

InfluxDBError – if the server returns an error or an unexpected HTTP status code

coroutine start(self, ctx)

Resolve Asphalt resource references.

Return type:None
coroutine write(self, measurement, tags, fields, timestamp=None, **write_params)

Write a single data point to the database.

This is a shortcut for instantiating a DataPoint and passing it in a tuple to write_many().

Note

If the timestamp is given as an integer, it must match with the precision option the client was initialized with.

Parameters:
  • measurement (str) – name of the measurement
  • tags (Dict[str, Any]) – a dictionary of tag names to values
  • fields (Dict[str, Union[float, Decimal, bool, str]]) – a dictionary of field names to values
  • timestamp (Union[datetime, int, None]) – time stamp for the measurement
  • write_params – overrides for default write parameters
Raises:

InfluxDBError – if the server returns an error or an unexpected HTTP status code

Return type:

None

coroutine write_many(self, datapoints, **write_params)

Write the given data points to the database.

Parameters:
  • datapoints (Iterable[DataPoint]) – data points to write
  • write_params – overrides for default write parameters
Raises:

InfluxDBError – if the server returns an error or an unexpected HTTP status code

Return type:

None

exception asphalt.influxdb.client.InfluxDBError

Bases: Exception

Base exception class for InfluxDB related errors.