@@ -49,6 +49,7 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or
4949 else :
5050 self .conf .host = self .url
5151 self .conf .enable_gzip = enable_gzip
52+ self .conf .gzip_threshold = kwargs .get ('gzip_threshold' , None )
5253 self .conf .verify_ssl = kwargs .get ('verify_ssl' , True )
5354 self .conf .ssl_ca_cert = kwargs .get ('ssl_ca_cert' , None )
5455 self .conf .cert_file = kwargs .get ('cert_file' , None )
@@ -206,53 +207,6 @@ def _from_env_properties(cls, debug=None, enable_gzip=False, **kwargs):
206207 connection_pool_maxsize = _to_int (connection_pool_maxsize ), auth_basic = _to_bool (auth_basic ),
207208 profilers = profilers , ** kwargs )
208209
209- @classmethod
210- def _from_env (cls , debug = None , enable_gzip = False , ** kwargs ):
211- """
212- Creates and configures an instance of the class using environment variable values. The method loads
213- configuration values for connecting to an InfluxDB server instance from preset environment variables.
214- Options include connection details such as host, token, organization, and optional parameters
215- like SSL settings, profiling, and default tags. Non-specified parameters fallback to defaults
216- or None, ensuring a straightforward integration with varied InfluxDB setups.
217-
218- :param debug: Determines whether debugging mode is enabled.
219- :type debug: Optional[bool]
220- :param enable_gzip: Indicates whether gzip compression is enabled for requests.
221- :type enable_gzip: bool
222- :param kwargs: Additional keyword arguments to configure the instance.
223- :type kwargs: dict
224- :return: Instance of the class configured using the provided environmental settings.
225- :rtype: cls
226- """
227- url = os .getenv ('INFLUX_HOST' , "http://localhost:8086" )
228- token = os .getenv ('INFLUX_TOKEN' , "my-token" )
229- org = os .getenv ('INFLUX_ORG' , "my-org" )
230- timeout = os .getenv ('INFLUX_TIMEOUT' , "10000" )
231- verify_ssl = os .getenv ('INFLUX_VERIFY_SSL' , "True" )
232- ssl_ca_cert = os .getenv ('INFLUX_SSL_CA_CERT' , None )
233- cert_file = os .getenv ('INFLUX_CERT_FILE' , None )
234- cert_key_file = os .getenv ('INFLUX_CERT_KEY_FILE' , None )
235- cert_key_password = os .getenv ('INFLUX_CERT_KEY_PASSWORD' , None )
236- connection_pool_maxsize = os .getenv ('INFLUX_CONNECTION_POOL_MAXSIZE' , None )
237- auth_basic = os .getenv ('INFLUX_AUTH_BASIC' , "False" )
238-
239- prof = os .getenv ("INFLUX_PROFILERS" , None )
240- profilers = None
241- if prof is not None :
242- profilers = [x .strip () for x in prof .split (',' )]
243-
244- default_tags = dict ()
245-
246- for key , value in os .environ .items ():
247- if key .startswith ("INFLUX_TAG_" ):
248- default_tags [key [11 :].lower ()] = value
249-
250- return cls (url , token , debug = debug , timeout = _to_int (timeout ), org = org , default_tags = default_tags ,
251- enable_gzip = enable_gzip , verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert ,
252- cert_file = cert_file , cert_key_file = cert_key_file , cert_key_password = cert_key_password ,
253- connection_pool_maxsize = _to_int (connection_pool_maxsize ), auth_basic = _to_bool (auth_basic ),
254- profilers = profilers , ** kwargs )
255-
256210
257211class _BaseWriteApi (object ):
258212 def __init__ (self , influxdb_client , point_settings = None ):
@@ -324,9 +278,9 @@ def __init__(self):
324278 self .username = None
325279 self .password = None
326280
327- def update_request_header_params (self , path : str , params : dict ):
328- super ().update_request_header_params (path , params )
329- if self . enable_gzip :
281+ def update_request_header_params (self , path : str , params : dict , should_gzip : bool = False ):
282+ super ().update_request_header_params (path , params , should_gzip )
283+ if should_gzip :
330284 # GZIP Request
331285 if path == '/api/v2/write' :
332286 params ["Content-Encoding" ] = "gzip"
@@ -340,9 +294,9 @@ def update_request_header_params(self, path: str, params: dict):
340294 pass
341295 pass
342296
343- def update_request_body (self , path : str , body ):
344- _body = super ().update_request_body (path , body )
345- if self . enable_gzip :
297+ def update_request_body (self , path : str , body , should_gzip : bool = False ):
298+ _body = super ().update_request_body (path , body , should_gzip )
299+ if should_gzip :
346300 # GZIP Request
347301 if path == '/api/v2/write' :
348302 import gzip
0 commit comments