File tree 7 files changed +418
-2
lines changed
Filter options
7 files changed +418
-2
lines changed
Original file line number Diff line number Diff line change 2
2
3
3
### Features
4
4
1 . [ #319 ] ( https://github.com/influxdata/influxdb-client-python/pull/319 ) : Add supports for array expressions in query parameters
5
+ 2 . [ #320 ] ( https://github.com/influxdata/influxdb-client-python/pull/320 ) : Add JSONEncoder to encode query results to JSON
5
6
6
7
### Bug Fixes
7
8
1 . [ #321 ] ( https://github.com/influxdata/influxdb-client-python/pull/321 ) : Fixes return type for dashboard when ` include=properties ` is used
Original file line number Diff line number Diff line change 11
11
## Queries
12
12
- [ query.py] ( query.py ) - How to query data into ` FluxTable ` s, ` Stream ` and ` CSV `
13
13
- [ query_from_file.py] ( query_from_file.py ) - How to use a Flux query defined in a separate file
14
+ - [ query_response_to_json.py] ( query_response_to_json.py ) - How to serialize Query response to JSON
14
15
15
16
16
17
## Management API
Original file line number Diff line number Diff line change
1
+ from influxdb_client import InfluxDBClient , Point
2
+ from influxdb_client .client .write_api import SYNCHRONOUS
3
+
4
+ with InfluxDBClient (url = "http://localhost:8086" , token = "my-token" , org = "my-org" ) as client :
5
+
6
+ """
7
+ Prepare data
8
+ """
9
+ _point1 = Point ("my_measurement" ).tag ("location" , "Prague" ).field ("temperature" , 25.3 )
10
+ _point2 = Point ("my_measurement" ).tag ("location" , "New York" ).field ("temperature" , 24.3 )
11
+
12
+ client .write_api (write_options = SYNCHRONOUS ).write (bucket = "my-bucket" , record = [_point1 , _point2 ])
13
+
14
+ """
15
+ Query: using Table structure
16
+ """
17
+ tables = client .query_api ().query ('from(bucket:"my-bucket") |> range(start: -10m)' )
18
+
19
+ """
20
+ Serialize to JSON
21
+ """
22
+ import json
23
+ from influxdb_client .client .flux_table import FluxStructureEncoder
24
+
25
+ output = json .dumps (tables , cls = FluxStructureEncoder , indent = 2 )
26
+ print (output )
Original file line number Diff line number Diff line change 3
3
4
4
The data model consists of tables, records, columns.
5
5
"""
6
+ from json import JSONEncoder
6
7
7
8
8
9
class FluxStructure :
@@ -11,8 +12,32 @@ class FluxStructure:
11
12
pass
12
13
13
14
15
+ class FluxStructureEncoder (JSONEncoder ):
16
+ """The FluxStructure encoder to encode query results to JSON."""
17
+
18
+ def default (self , obj ):
19
+ """Return serializable objects for JSONEncoder."""
20
+ import datetime
21
+ if isinstance (obj , FluxStructure ):
22
+ return obj .__dict__
23
+ elif isinstance (obj , (datetime .datetime , datetime .date )):
24
+ return obj .isoformat ()
25
+ return super ().default (obj )
26
+
27
+
14
28
class FluxTable (FluxStructure ):
15
- """A table is set of records with a common set of columns and a group key."""
29
+ """
30
+ A table is set of records with a common set of columns and a group key.
31
+
32
+ The table can be serialized into JSON by::
33
+
34
+ import json
35
+ from influxdb_client.client.flux_table import FluxStructureEncoder
36
+
37
+ output = json.dumps(tables, cls=FluxStructureEncoder, indent=2)
38
+ print(output)
39
+
40
+ """
16
41
17
42
def __init__ (self ) -> None :
18
43
"""Initialize defaults."""
You can’t perform that action at this time.
0 commit comments