diff --git a/README.rst b/README.rst index 1c9c3e75..5f801b07 100644 --- a/README.rst +++ b/README.rst @@ -397,13 +397,17 @@ Data are writes in an asynchronous HTTP request. .. code-block:: python - from influxdb_client import InfluxDBClient + from influxdb_client import InfluxDBClient, Point from influxdb_client.client.write_api import ASYNCHRONOUS client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org") - write_client = client.write_api(write_options=ASYNCHRONOUS) + write_api = client.write_api(write_options=ASYNCHRONOUS) + + _point1 = Point("my_measurement").tag("location", "Prague").field("temperature", 25.3) + _point2 = Point("my_measurement").tag("location", "New York").field("temperature", 24.3) - ... + async_result = write_api.write(bucket="my-bucket", record=[_point1, _point2]) + async_result.get() client.__del__() @@ -414,13 +418,16 @@ Data are writes in a synchronous HTTP request. .. code-block:: python - from influxdb_client import InfluxDBClient + from influxdb_client import InfluxDBClient, Point from influxdb_client .client.write_api import SYNCHRONOUS client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org") - write_client = client.write_api(write_options=SYNCHRONOUS) + write_api = client.write_api(write_options=SYNCHRONOUS) + + _point1 = Point("my_measurement").tag("location", "Prague").field("temperature", 25.3) + _point2 = Point("my_measurement").tag("location", "New York").field("temperature", 24.3) - ... + write_api.write(bucket="my-bucket", record=[_point1, _point2]) client.__del__() diff --git a/tests/test_WriteApi.py b/tests/test_WriteApi.py index 42d0798d..74aa92f9 100644 --- a/tests/test_WriteApi.py +++ b/tests/test_WriteApi.py @@ -349,8 +349,8 @@ def test_write_dictionaries(self): _point_list = [_point1, _point2] - self.write_client.write(bucket.name, self.org, _point_list) - time.sleep(1) + async_result = self.write_client.write(bucket.name, self.org, _point_list) + async_result.get() query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)' @@ -388,8 +388,8 @@ def test_use_default_tags_with_dictionaries(self): _point_list = [_point1, _point2] - self.write_client.write(bucket.name, self.org, _point_list) - time.sleep(1) + async_result = self.write_client.write(bucket.name, self.org, _point_list) + async_result.get() query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)' @@ -424,10 +424,9 @@ def test_use_default_tags_with_data_frame(self): index=[now + timedelta(hours=1), now + timedelta(hours=2)], columns=["location", "water_level"]) - self.write_client.write(bucket.name, record=data_frame, data_frame_measurement_name='h2o_feet', + async_result = self.write_client.write(bucket.name, record=data_frame, data_frame_measurement_name='h2o_feet', data_frame_tag_columns=['location']) - - time.sleep(1) + async_result.get() query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)' @@ -460,8 +459,8 @@ def test_write_bytes(self): _bytes_list = [_bytes1, _bytes2] - self.write_client.write(bucket.name, self.org, _bytes_list, write_precision=WritePrecision.S) - time.sleep(1) + async_result = self.write_client.write(bucket.name, self.org, _bytes_list, write_precision=WritePrecision.S) + async_result.get() query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'