Skip to content

Commit d5f8f29

Browse files
Merge pull request #22 from InfluxCommunity/21-expose-flight-client-options
added flight options
2 parents fb50c6d + cb3798b commit d5f8f29

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

Examples/flight_options_example.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import influxdb_client_3 as InfluxDBClient3
2+
import pandas as pd
3+
import numpy as np
4+
from influxdb_client_3 import flight_client_options
5+
6+
7+
8+
9+
with open("./cert.pem", 'rb') as f:
10+
cert = f.read()
11+
print(cert)
12+
13+
14+
client = InfluxDBClient3.InfluxDBClient3(token="",
15+
host="b0c7cce5-8dbc-428e-98c6-7f996fb96467.a.influxdb.io",
16+
org="6a841c0c08328fb1",
17+
database="flightdemo", flight_client_options=flight_client_options(tls_root_certs=cert))
18+
19+
20+
table = client.query(query="SELECT * FROM flight WHERE time > now() - 4h", language="influxql")
21+
22+
print(table.to_pandas())

influxdb_client_3/__init__.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
def write_options(**kwargs):
1515
return _WriteOptions(**kwargs)
1616

17+
def flight_client_options(**kwargs):
18+
return kwargs # You can replace this with a specific data structure if needed
19+
20+
21+
1722

1823

1924

2025
class InfluxDBClient3:
21-
def __init__(self, host=None, org=None, database=None, token=None, write_options=None, **kwargs):
26+
def __init__(self, host=None, org=None, database=None, token=None, write_options=None, flight_client_options=None ,**kwargs):
2227
"""
2328
This class provides an interface for interacting with an InfluxDB server, simplifying common operations such as writing, querying.
2429
* host (str, optional): The hostname or IP address of the InfluxDB server. Defaults to None.
@@ -33,7 +38,9 @@ def __init__(self, host=None, org=None, database=None, token=None, write_options
3338
self.write_options = write_options if write_options is not None else SYNCHRONOUS
3439
self._client = _InfluxDBClient(url=f"https://{host}", token=token, org=self._org, **kwargs )
3540
self._write_api = _WriteApi(self._client, write_options=self.write_options )
36-
self._flight_client = FlightClient(f"grpc+tls://{host}:443")
41+
42+
self._flight_client_options = flight_client_options if flight_client_options is not None else {}
43+
self._flight_client = FlightClient(f"grpc+tls://{host}:443", **self._flight_client_options)
3744
# create an authorization header
3845
self._options = FlightCallOptions(headers=[(b"authorization",f"Bearer {token}".encode('utf-8'))])
3946

@@ -109,4 +116,4 @@ def __enter__(self):
109116
def __exit__(self, exc_type, exc_val, exc_tb):
110117
self.close()
111118

112-
__all__ = ["InfluxDBClient3", "Point", "PointSettings", "SYNCHRONOUS", "ASYNCHRONOUS", "write_options", "WritePrecision"]
119+
__all__ = ["InfluxDBClient3", "Point", "PointSettings", "SYNCHRONOUS", "ASYNCHRONOUS", "write_options", "WritePrecision", "flight_client_options"]

0 commit comments

Comments
 (0)