API Reference

This part of the documentation covers all the interfaces of Aioinflux


🚧 This section of the documentation is under writing and may be wrong/incomplete 🚧

Client Interface

class aioinflux.client.InfluxDBClient(host='localhost', port=8086, mode='async', output='raw', db=None, *, ssl=False, unix_socket=None, username=None, password=None, database=None, loop=None)[source]

Pings InfluxDB. Returns a dictionary containing the headers of the response from influxd.

Return type:dict
query(q, *args, epoch='ns', chunked=False, chunk_size=None, db=None, parser=None, **kwargs)[source]

Sends a query to InfluxDB. Please refer to the InfluxDB documentation for all the possible queries: https://docs.influxdata.com/influxdb/latest/query_language/

  • q (AnyStr) – Raw query string
  • args – Positional arguments for query patterns
  • db (Optional[str]) – Database to be queried. Defaults to self.db.
  • epoch (str) – Precision level of response timestamps. Valid values: {'ns', 'u', 'µ', 'ms', 's', 'm', 'h'}.
  • chunked (bool) – If True, makes InfluxDB return results in streamed batches rather than as a single response. Returns an AsyncGenerator which yields responses in the same format as non-chunked queries.
  • chunk_size (Optional[int]) – Max number of points for each chunk. By default, InfluxDB chunks responses by series or by every 10,000 points, whichever occurs first.
  • kwargs – Keyword arguments for query patterns
  • parser (Optional[Callable]) – Optional parser function for ‘iterable’ mode
Return type:

Union[Asyncgenerator[+T_co, -T_contra], dict, InfluxDBResult, InfluxDBChunkedResult]


Returns an async generator if chunked is True, otherwise returns a dictionary containing the parsed JSON response.

classmethod set_query_pattern(queries=None, **kwargs)[source]

Defines custom methods to provide quick access to commonly used query patterns.

Query patterns are passed as mappings, with the key being name of the new method and the value the actual query pattern. Query patterns are plain strings, with optional the named placed holders. Named placed holders are processed as keyword arguments in str.format. Positional arguments are also supported.

Sample query pattern dictionary:

{"host_load": "SELECT mean(load) FROM cpu_stats "
              "WHERE host = '{host}' AND time > now() - {days}d",
 "peak_load": "SELECT max(load) FROM cpu_stats "
              "WHERE host = '{host}' GROUP BY time(1d),host"}
  • queries (Optional[Mapping[~KT, +VT_co]]) – Mapping (e.g. dictionary) containing query patterns. Can be used in conjunction with kwargs.
  • kwargs – Alternative way to pass query patterns.
Return type:


write(data, measurement=None, db=None, tag_columns=None, **extra_tags)[source]

Writes data to InfluxDB. Input can be:

  1. a string properly formatted in InfluxDB’s line protocol
  2. a dictionary-like object containing four keys: measurement, time, tags, fields
  3. a Pandas DataFrame with a DatetimeIndex
  4. an iterable of one of above

Input data in formats 2-4 are parsed to the line protocol before being written to InfluxDB. See the InfluxDB docs for more details.

  • data (Union[AnyStr, Mapping[~KT, +VT_co], Iterable[Union[AnyStr, Mapping[~KT, +VT_co]]]]) – Input data (see description above).
  • measurement (Optional[str]) – Measurement name. Mandatory when when writing DataFrames only. When writing dictionary-like data, this field is treated as the default value for points that do not contain a measurement field.
  • db (Optional[str]) – Database to be written to. Defaults to self.db.
  • tag_columns (Optional[Iterable[+T_co]]) – Columns to be treated as tags (used when writing DataFrames only)
  • extra_tags – Additional tags to be added to all points passed.
Return type:



Returns True if insert is successful. Raises ValueError exception otherwise.

exception aioinflux.client.InfluxDBWriteError(resp)[source]



Makes a dictionary of DataFrames from a response object

Return type:None
aioinflux.serialization.parse_df(df, measurement, tag_columns=None, **extra_tags)[source]

Converts a Pandas DataFrame into line protocol format