diff --git a/Examples/flight_options_example.py b/Examples/flight_options_example.py new file mode 100644 index 0000000..0a558ec --- /dev/null +++ b/Examples/flight_options_example.py @@ -0,0 +1,22 @@ +import influxdb_client_3 as InfluxDBClient3 +import pandas as pd +import numpy as np +from influxdb_client_3 import flight_client_options + + + + +with open("./cert.pem", 'rb') as f: + cert = f.read() +print(cert) + + +client = InfluxDBClient3.InfluxDBClient3(token="", + host="b0c7cce5-8dbc-428e-98c6-7f996fb96467.a.influxdb.io", + org="6a841c0c08328fb1", + database="flightdemo", flight_client_options=flight_client_options(tls_root_certs=cert)) + + +table = client.query(query="SELECT * FROM flight WHERE time > now() - 4h", language="influxql") + +print(table.to_pandas()) \ No newline at end of file diff --git a/influxdb_client_3/__init__.py b/influxdb_client_3/__init__.py index 8c8cb3d..7ca1ffc 100644 --- a/influxdb_client_3/__init__.py +++ b/influxdb_client_3/__init__.py @@ -14,11 +14,16 @@ def write_options(**kwargs): return _WriteOptions(**kwargs) +def flight_client_options(**kwargs): + return kwargs # You can replace this with a specific data structure if needed + + + class InfluxDBClient3: - def __init__(self, host=None, org=None, database=None, token=None, write_options=None, **kwargs): + def __init__(self, host=None, org=None, database=None, token=None, write_options=None, flight_client_options=None ,**kwargs): """ This class provides an interface for interacting with an InfluxDB server, simplifying common operations such as writing, querying. * 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 self.write_options = write_options if write_options is not None else SYNCHRONOUS self._client = _InfluxDBClient(url=f"https://{host}", token=token, org=self._org, **kwargs ) self._write_api = _WriteApi(self._client, write_options=self.write_options ) - self._flight_client = FlightClient(f"grpc+tls://{host}:443") + + self._flight_client_options = flight_client_options if flight_client_options is not None else {} + self._flight_client = FlightClient(f"grpc+tls://{host}:443", **self._flight_client_options) # create an authorization header self._options = FlightCallOptions(headers=[(b"authorization",f"Bearer {token}".encode('utf-8'))]) @@ -109,4 +116,4 @@ def __enter__(self): def __exit__(self, exc_type, exc_val, exc_tb): self.close() -__all__ = ["InfluxDBClient3", "Point", "PointSettings", "SYNCHRONOUS", "ASYNCHRONOUS", "write_options", "WritePrecision"] +__all__ = ["InfluxDBClient3", "Point", "PointSettings", "SYNCHRONOUS", "ASYNCHRONOUS", "write_options", "WritePrecision", "flight_client_options"]