Skip to content

Commit 55492c5

Browse files
committed
docs: updated CHANGELOG and README
1 parent afae27d commit 55492c5

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
### Features
44
1. [#136](https://github.com/influxdata/influxdb-client-python/pull/136): Allows users to skip of verifying SSL certificate
5-
1. [#143](https://github.com/influxdata/influxdb-client-python/pull/143): Skip of verifying SSL certificate could be configured via config file or environment properties
5+
1. [#143](https://github.com/influxdata/influxdb-client-python/pull/143): Skip of verifying SSL certificate could be configured via config file or environment properties
6+
1. [#141](https://github.com/influxdata/influxdb-client-python/pull/141): Added possibility to use datetime nanoseconds precision by `pandas.Timestamp`
67

78
## 1.9.0 [2020-07-17]
89

README.rst

+67-1
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,76 @@ The following forward compatible APIs are available:
899899

900900
For detail info see `InfluxDB 1.8 example <examples/influxdb_18_example.py>`_.
901901

902+
Nanosecond precision
903+
^^^^^^^^^^^^^^^^^^^^
904+
905+
The Python's `datetime <https://docs.python.org/3/library/datetime.html>`_ doesn't support precision with nanoseconds
906+
so the library during writes and queries ignores everything after microseconds.
907+
908+
If you would like to use ``datetime`` with nanosecond precision you should use
909+
`pandas.Timestamp <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Timestamp.html#pandas.Timestamp>`_
910+
that is replacement for python ``datetime.datetime`` object and also you should set a proper ``DateTimeHelper`` to the client.
911+
912+
* sources - `nanosecond_precision.py <https://github.com/influxdata/influxdb-client-python/blob/master/examples/nanosecond_precision.py>`_
913+
914+
.. code-block:: python
915+
916+
from influxdb_client import Point, InfluxDBClient
917+
from influxdb_client.client.util.date_utils_pandas import PandasDateTimeHelper
918+
from influxdb_client.client.write_api import SYNCHRONOUS
919+
920+
"""
921+
Set PandasDate helper which supports nanoseconds.
922+
"""
923+
import influxdb_client.client.util.date_utils as date_utils
924+
925+
date_utils.date_helper = PandasDateTimeHelper()
926+
927+
"""
928+
Prepare client.
929+
"""
930+
client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org")
931+
932+
write_api = client.write_api(write_options=SYNCHRONOUS)
933+
query_api = client.query_api()
934+
935+
"""
936+
Prepare data
937+
"""
938+
939+
point = Point("h2o_feet") \
940+
.field("water_level", 10) \
941+
.tag("location", "pacific") \
942+
.time('1996-02-25T21:20:00.001001231Z')
943+
944+
print(f'Time serialized with nanosecond precision: {point.to_line_protocol()}')
945+
print()
946+
947+
write_api.write(bucket="my-bucket", record=point)
948+
949+
"""
950+
Query: using Stream
951+
"""
952+
query = '''
953+
from(bucket:"my-bucket")
954+
|> range(start: 0, stop: now())
955+
|> filter(fn: (r) => r._measurement == "h2o_feet")
956+
'''
957+
records = query_api.query_stream(query)
958+
959+
for record in records:
960+
print(f'Temperature in {record["location"]} is {record["_value"]} at time: {record["_time"]}')
961+
962+
"""
963+
Close client
964+
"""
965+
client.__del__()
966+
967+
902968
Local tests
903969
-----------
904970

905-
.. code-block:: python
971+
.. code-block:: console
906972
907973
# start/restart InfluxDB2 on local machine using docker
908974
./scripts/influxdb-restart.sh

examples/nanosecond_precision.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from influxdb_client import Point, InfluxDBClient
2+
from influxdb_client.client.util.date_utils_pandas import PandasDateTimeHelper
3+
from influxdb_client.client.write_api import SYNCHRONOUS
4+
5+
"""
6+
Set PandasDate helper which supports nanoseconds.
7+
"""
8+
import influxdb_client.client.util.date_utils as date_utils
9+
10+
date_utils.date_helper = PandasDateTimeHelper()
11+
12+
"""
13+
Prepare client.
14+
"""
15+
client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org")
16+
17+
write_api = client.write_api(write_options=SYNCHRONOUS)
18+
query_api = client.query_api()
19+
20+
"""
21+
Prepare data
22+
"""
23+
24+
point = Point("h2o_feet") \
25+
.field("water_level", 10) \
26+
.tag("location", "pacific") \
27+
.time('1996-02-25T21:20:00.001001231Z')
28+
29+
print(f'Time serialized with nanosecond precision: {point.to_line_protocol()}')
30+
print()
31+
32+
write_api.write(bucket="my-bucket", record=point)
33+
34+
"""
35+
Query: using Stream
36+
"""
37+
query = '''
38+
from(bucket:"my-bucket")
39+
|> range(start: 0, stop: now())
40+
|> filter(fn: (r) => r._measurement == "h2o_feet")
41+
'''
42+
records = query_api.query_stream(query)
43+
44+
for record in records:
45+
print(f'Temperature in {record["location"]} is {record["_value"]} at time: {record["_time"]}')
46+
47+
"""
48+
Close client
49+
"""
50+
client.__del__()

0 commit comments

Comments
 (0)