Skip to content

Commit 58f653a

Browse files
committed
docs: clarify how to use ASYNCHRONOUS write (#90)
1 parent a1f9826 commit 58f653a

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

README.rst

+13-6
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,17 @@ Data are writes in an asynchronous HTTP request.
397397

398398
.. code-block:: python
399399
400-
from influxdb_client import InfluxDBClient
400+
from influxdb_client import InfluxDBClient, Point
401401
from influxdb_client.client.write_api import ASYNCHRONOUS
402402
403403
client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org")
404-
write_client = client.write_api(write_options=ASYNCHRONOUS)
404+
write_api = client.write_api(write_options=ASYNCHRONOUS)
405+
406+
_point1 = Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)
407+
_point2 = Point("my_measurement").tag("location", "New York").field("temperature", 24.3)
405408
406-
...
409+
async_result = write_api.write(bucket="my-bucket", record=[_point1, _point2])
410+
async_result.get()
407411
408412
client.__del__()
409413
@@ -414,13 +418,16 @@ Data are writes in a synchronous HTTP request.
414418

415419
.. code-block:: python
416420
417-
from influxdb_client import InfluxDBClient
421+
from influxdb_client import InfluxDBClient, Point
418422
from influxdb_client .client.write_api import SYNCHRONOUS
419423
420424
client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org")
421-
write_client = client.write_api(write_options=SYNCHRONOUS)
425+
write_api = client.write_api(write_options=SYNCHRONOUS)
426+
427+
_point1 = Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)
428+
_point2 = Point("my_measurement").tag("location", "New York").field("temperature", 24.3)
422429
423-
...
430+
write_api.write(bucket="my-bucket", record=[_point1, _point2])
424431
425432
client.__del__()
426433

tests/test_WriteApi.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ def test_write_dictionaries(self):
349349

350350
_point_list = [_point1, _point2]
351351

352-
self.write_client.write(bucket.name, self.org, _point_list)
353-
time.sleep(1)
352+
async_result = self.write_client.write(bucket.name, self.org, _point_list)
353+
async_result.get()
354354

355355
query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'
356356

@@ -388,8 +388,8 @@ def test_use_default_tags_with_dictionaries(self):
388388

389389
_point_list = [_point1, _point2]
390390

391-
self.write_client.write(bucket.name, self.org, _point_list)
392-
time.sleep(1)
391+
async_result = self.write_client.write(bucket.name, self.org, _point_list)
392+
async_result.get()
393393

394394
query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'
395395

@@ -424,10 +424,9 @@ def test_use_default_tags_with_data_frame(self):
424424
index=[now + timedelta(hours=1), now + timedelta(hours=2)],
425425
columns=["location", "water_level"])
426426

427-
self.write_client.write(bucket.name, record=data_frame, data_frame_measurement_name='h2o_feet',
427+
async_result = self.write_client.write(bucket.name, record=data_frame, data_frame_measurement_name='h2o_feet',
428428
data_frame_tag_columns=['location'])
429-
430-
time.sleep(1)
429+
async_result.get()
431430

432431
query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'
433432

@@ -460,8 +459,8 @@ def test_write_bytes(self):
460459

461460
_bytes_list = [_bytes1, _bytes2]
462461

463-
self.write_client.write(bucket.name, self.org, _bytes_list, write_precision=WritePrecision.S)
464-
time.sleep(1)
462+
async_result = self.write_client.write(bucket.name, self.org, _bytes_list, write_precision=WritePrecision.S)
463+
async_result.get()
465464

466465
query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'
467466

0 commit comments

Comments
 (0)