Async API Reference¶
WriteApiAsync¶
-
class
influxdb_client.client.write_api_async.
WriteApiAsync
(influxdb_client, point_settings: influxdb_client.client.write_api.PointSettings = <influxdb_client.client.write_api.PointSettings object>)[source]¶ Implementation for ‘/api/v2/write’ endpoint.
- Example:
from influxdb_client_async import InfluxDBClientAsync # Initialize async/await instance of Write API async with InfluxDBClientAsync(url="http://localhost:8086", token="my-token", org="my-org") as client: write_api = client.write_api()
Initialize defaults.
Parameters: - influxdb_client – with default settings (organization)
- point_settings – settings to store default tags.
-
write
(bucket: str, org: str = None, record: Union[str, Iterable[str], influxdb_client.client.write.point.Point, Iterable[Point], dict, Iterable[dict], bytes, Iterable[bytes], NamedTuple, Iterable[NamedTuple], dataclass, Iterable[dataclass]] = None, write_precision: influxdb_client.domain.write_precision.WritePrecision = 'ns', **kwargs) → bool[source]¶ Write time-series data into InfluxDB.
Parameters: - bucket (str) – specifies the destination bucket for writes (required)
- Organization org (str,) – specifies the destination organization for writes;
take the ID, Name or Organization.
If not specified the default value from
InfluxDBClientAsync.org
is used. - write_precision (WritePrecision) – specifies the precision for the unix timestamps within the body line-protocol. The precision specified on a Point has precedes and is use for write.
- record – Point, Line Protocol, Dictionary, NamedTuple, Data Classes, Pandas DataFrame
Key data_frame_measurement_name: name of measurement for writing Pandas DataFrame -
DataFrame
Key data_frame_tag_columns: list of DataFrame columns which are tags, rest columns will be fields -
DataFrame
Key data_frame_timestamp_column: name of DataFrame column which contains a timestamp. The column can be defined as a
str
value formatted as 2018-10-26, 2018-10-26 12:00, 2018-10-26 12:00:00-05:00 or other formats and types supported by pandas.to_datetime -DataFrame
Key data_frame_timestamp_timezone: name of the timezone which is used for timestamp column -
DataFrame
Key record_measurement_key: key of record with specified measurement -
dictionary
,NamedTuple
,dataclass
Key record_measurement_name: static measurement name -
dictionary
,NamedTuple
,dataclass
Key record_time_key: key of record with specified timestamp -
dictionary
,NamedTuple
,dataclass
Key record_tag_keys: list of record keys to use as a tag -
dictionary
,NamedTuple
,dataclass
Key record_field_keys: list of record keys to use as a field -
dictionary
,NamedTuple
,dataclass
Returns: True
for successfully accepted data, otherwise raise an exception- Example:
# Record as Line Protocol await write_api.write("my-bucket", "my-org", "h2o_feet,location=us-west level=125i 1") # Record as Dictionary dictionary = { "measurement": "h2o_feet", "tags": {"location": "us-west"}, "fields": {"level": 125}, "time": 1 } await write_api.write("my-bucket", "my-org", dictionary) # Record as Point from influxdb_client import Point point = Point("h2o_feet").tag("location", "us-west").field("level", 125).time(1) await write_api.write("my-bucket", "my-org", point)
- DataFrame:
If the
data_frame_timestamp_column
is not specified the index of Pandas DataFrame is used as atimestamp
for written data. The index can be PeriodIndex or its must be transformable todatetime
by pandas.to_datetime.If you would like to transform a column to
PeriodIndex
, you can use something like:import pandas as pd # DataFrame data_frame = ... # Set column as Index data_frame.set_index('column_name', inplace=True) # Transform index to PeriodIndex data_frame.index = pd.to_datetime(data_frame.index, unit='s')
DeleteApiAsync¶
-
class
influxdb_client.client.delete_api_async.
DeleteApiAsync
(influxdb_client)[source]¶ Async implementation for ‘/api/v2/delete’ endpoint.
Initialize defaults.
-
delete
(start: Union[str, datetime.datetime], stop: Union[str, datetime.datetime], predicate: str, bucket: str, org: Union[str, influxdb_client.domain.organization.Organization, None] = None) → bool[source]¶ Delete Time series data from InfluxDB.
Parameters: - datetime.datetime start (str,) – start time
- datetime.datetime stop (str,) – stop time
- predicate (str) – predicate
- bucket (str) – bucket id or name from which data will be deleted
- Organization org (str,) – specifies the organization to delete data from.
Take the
ID
,Name
orOrganization
. If not specified the default value fromInfluxDBClientAsync.org
is used.
Returns: True
for successfully deleted data, otherwise raise an exception
-