influxdb3-python 0.12.0__tar.gz → 0.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/basic_ssl_example.py +0 -2
  2. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/batching_example.py +0 -1
  3. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/cloud_dedicated_query.py +0 -1
  4. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/cloud_dedicated_write.py +0 -1
  5. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/config.py +0 -1
  6. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/flight_options_example.py +0 -1
  7. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/handle_http_error.py +0 -1
  8. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/pandas_write.py +0 -1
  9. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/query_async.py +0 -1
  10. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/query_type.py +0 -1
  11. {influxdb3_python-0.12.0/influxdb3_python.egg-info → influxdb3_python-0.13.0}/PKG-INFO +5 -11
  12. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/README.md +4 -10
  13. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0/influxdb3_python.egg-info}/PKG-INFO +5 -11
  14. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/__init__.py +129 -4
  15. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/query/query_api.py +1 -1
  16. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/version.py +1 -1
  17. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/__init__.py +0 -10
  18. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/_sync/api_client.py +43 -25
  19. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/_sync/rest.py +0 -20
  20. {influxdb3_python-0.12.0/influxdb_client_3/write_client/client/write → influxdb3_python-0.13.0/influxdb_client_3/write_client/client}/__init__.py +0 -10
  21. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/_base.py +10 -6
  22. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/influxdb_client.py +9 -5
  23. {influxdb3_python-0.12.0/influxdb_client_3/write_client/client → influxdb3_python-0.13.0/influxdb_client_3/write_client/client/write}/__init__.py +0 -10
  24. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/write_api.py +16 -3
  25. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/configuration.py +10 -24
  26. influxdb3_python-0.13.0/influxdb_client_3/write_client/domain/__init__.py +10 -0
  27. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/domain/write_precision.py +0 -16
  28. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/rest.py +0 -14
  29. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/service/__init__.py +0 -12
  30. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/service/signin_service.py +0 -16
  31. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/service/signout_service.py +0 -16
  32. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/service/write_service.py +0 -16
  33. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_api_client.py +22 -0
  34. influxdb3_python-0.13.0/tests/test_influxdb_client_3.py +147 -0
  35. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_polars.py +11 -4
  36. influxdb3_python-0.12.0/influxdb_client_3/write_client/domain/__init__.py +0 -19
  37. influxdb3_python-0.12.0/tests/test_influxdb_client_3.py +0 -79
  38. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/Examples/__init__.py +0 -0
  39. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/LICENSE +0 -0
  40. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb3_python.egg-info/SOURCES.txt +0 -0
  41. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb3_python.egg-info/dependency_links.txt +0 -0
  42. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb3_python.egg-info/requires.txt +0 -0
  43. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb3_python.egg-info/top_level.txt +0 -0
  44. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/py.typed +0 -0
  45. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/query/__init__.py +0 -0
  46. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/read_file.py +0 -0
  47. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/_sync/__init__.py +0 -0
  48. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/exceptions.py +0 -0
  49. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/logging_handler.py +0 -0
  50. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/util/__init__.py +0 -0
  51. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/util/date_utils.py +0 -0
  52. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/util/date_utils_pandas.py +0 -0
  53. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/util/helpers.py +0 -0
  54. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/util/multiprocessing_helper.py +0 -0
  55. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/warnings.py +0 -0
  56. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/write/dataframe_serializer.py +0 -0
  57. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/write/point.py +0 -0
  58. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/write/polars_dataframe_serializer.py +0 -0
  59. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/client/write/retry.py +0 -0
  60. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/extras.py +0 -0
  61. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/influxdb_client_3/write_client/service/_base_service.py +0 -0
  62. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/setup.cfg +0 -0
  63. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/setup.py +0 -0
  64. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_dataframe_serializer.py +0 -0
  65. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_date_helper.py +0 -0
  66. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_deep_merge.py +0 -0
  67. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_influxdb_client_3_integration.py +0 -0
  68. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_merge_options.py +0 -0
  69. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_point.py +0 -0
  70. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_query.py +0 -0
  71. {influxdb3_python-0.12.0 → influxdb3_python-0.13.0}/tests/test_write_file.py +0 -0
@@ -70,7 +70,6 @@ def write_and_query_with_explicit_sys_cert(conf):
70
70
  print("\nwrite and query with typical linux system cert\n")
71
71
  with InfluxDBClient3(token=conf.token,
72
72
  host=conf.host,
73
- org=conf.org,
74
73
  database=conf.database,
75
74
  ssl_ca_cert="/etc/ssl/certs/ca-certificates.crt",
76
75
  verify_ssl=True) as _client:
@@ -90,7 +89,6 @@ def query_with_verify_ssl_off(conf, cert):
90
89
  # Switch verify_ssl to True to throw SSL_ERROR_SSL
91
90
  with InfluxDBClient3(token=conf.token,
92
91
  host=conf.host,
93
- org=conf.org,
94
92
  database=conf.database,
95
93
  ssl_ca_cert=cert,
96
94
  verify_ssl=False) as _client:
@@ -70,7 +70,6 @@ def main() -> None:
70
70
  # of 10k ms and gzip compression
71
71
  with InfluxDBClient3.InfluxDBClient3(token=conf.token,
72
72
  host=conf.host,
73
- org=conf.org,
74
73
  database=conf.database,
75
74
  enable_gzip=True,
76
75
  write_client_options=wco) as _client:
@@ -6,7 +6,6 @@ config = Config()
6
6
  client = InfluxDBClient3.InfluxDBClient3(
7
7
  token=config.token,
8
8
  host=config.host,
9
- org=config.org,
10
9
  database=config.database)
11
10
 
12
11
  table = client.query(
@@ -9,7 +9,6 @@ config = Config()
9
9
  client = InfluxDBClient3.InfluxDBClient3(
10
10
  token=config.token,
11
11
  host=config.host,
12
- org=config.org,
13
12
  database=config.database,
14
13
  write_options=WriteOptions(
15
14
  batch_size=500,
@@ -6,7 +6,6 @@ class Config:
6
6
  def __init__(self):
7
7
  self.host = os.getenv('INFLUXDB_HOST') or 'https://us-east-1-1.aws.cloud2.influxdata.com/'
8
8
  self.token = os.getenv('INFLUXDB_TOKEN') or 'my-token'
9
- self.org = os.getenv('INFLUXDB_ORG') or 'my-org'
10
9
  self.database = os.getenv('INFLUXDB_DATABASE') or 'my-db'
11
10
 
12
11
  def __str__(self):
@@ -10,7 +10,6 @@ print(cert)
10
10
  client = InfluxDBClient3.InfluxDBClient3(
11
11
  token="",
12
12
  host="b0c7cce5-8dbc-428e-98c6-7f996fb96467.a.influxdb.io",
13
- org="6a841c0c08328fb1",
14
13
  database="flightdemo",
15
14
  flight_client_options=flight_client_options(
16
15
  tls_root_certs=cert))
@@ -18,7 +18,6 @@ def main() -> None:
18
18
  client = InfluxDBClient3.InfluxDBClient3(
19
19
  host=config.host,
20
20
  token=config.token,
21
- org=config.org,
22
21
  database=config.database
23
22
  )
24
23
 
@@ -5,7 +5,6 @@ import numpy as np
5
5
  client = InfluxDBClient3.InfluxDBClient3(
6
6
  token="",
7
7
  host="eu-central-1-1.aws.cloud2.influxdata.com",
8
- org="",
9
8
  database="")
10
9
 
11
10
 
@@ -72,7 +72,6 @@ async def main():
72
72
  host=config.host,
73
73
  token=config.token,
74
74
  database=config.database,
75
- org=config.org
76
75
  )
77
76
  measurement = 'example_uav'
78
77
  write_data(client, measurement)
@@ -3,7 +3,6 @@ import influxdb_client_3 as InfluxDBClient3
3
3
  client = InfluxDBClient3.InfluxDBClient3(
4
4
  token="",
5
5
  host="eu-central-1-1.aws.cloud2.influxdata.com",
6
- org="6a841c0c08328fb1",
7
6
  database="factory")
8
7
 
9
8
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: influxdb3-python
3
- Version: 0.12.0
3
+ Version: 0.13.0
4
4
  Summary: Community Python client for InfluxDB 3.0
5
5
  Home-page: https://github.com/InfluxCommunity/influxdb3-python
6
6
  Author: InfluxData
@@ -104,13 +104,11 @@ from influxdb_client_3 import InfluxDBClient3, Point
104
104
 
105
105
  ## Initialization
106
106
  If you are using InfluxDB Cloud, then you should note that:
107
- 1. You will need to supply your org id, this is not necessary for InfluxDB Dedicated.
108
- 2. Use bucket name for the `database` argument.
107
+ 1. Use bucket name for the `database` argument.
109
108
 
110
109
  ```python
111
110
  client = InfluxDBClient3(token="your-token",
112
111
  host="your-host",
113
- org="your-org",
114
112
  database="your-database")
115
113
  ```
116
114
 
@@ -171,7 +169,6 @@ wco = write_client_options(success_callback=callback.success,
171
169
  with InfluxDBClient3.InfluxDBClient3(
172
170
  token="INSERT_TOKEN",
173
171
  host="eu-central-1-1.aws.cloud2.influxdata.com",
174
- org="6a841c0c08328fb1",
175
172
  database="python", write_client_options=wco) as client:
176
173
 
177
174
 
@@ -218,27 +215,24 @@ Install `certifi`
218
215
  pip install certifi
219
216
  ```
220
217
  Next include certifi within the flight client options:
218
+
221
219
  ```python
220
+ import certifi
221
+
222
222
  import influxdb_client_3 as InfluxDBClient3
223
- import pandas as pd
224
- import numpy as np
225
223
  from influxdb_client_3 import flight_client_options
226
- import certifi
227
224
 
228
225
  fh = open(certifi.where(), "r")
229
226
  cert = fh.read()
230
227
  fh.close()
231
228
 
232
-
233
229
  client = InfluxDBClient3.InfluxDBClient3(
234
230
  token="",
235
231
  host="b0c7cce5-8dbc-428e-98c6-7f996fb96467.a.influxdb.io",
236
- org="6a841c0c08328fb1",
237
232
  database="flightdemo",
238
233
  flight_client_options=flight_client_options(
239
234
  tls_root_certs=cert))
240
235
 
241
-
242
236
  table = client.query(
243
237
  query="SELECT * FROM flight WHERE time > now() - 4h",
244
238
  language="influxql")
@@ -57,13 +57,11 @@ from influxdb_client_3 import InfluxDBClient3, Point
57
57
 
58
58
  ## Initialization
59
59
  If you are using InfluxDB Cloud, then you should note that:
60
- 1. You will need to supply your org id, this is not necessary for InfluxDB Dedicated.
61
- 2. Use bucket name for the `database` argument.
60
+ 1. Use bucket name for the `database` argument.
62
61
 
63
62
  ```python
64
63
  client = InfluxDBClient3(token="your-token",
65
64
  host="your-host",
66
- org="your-org",
67
65
  database="your-database")
68
66
  ```
69
67
 
@@ -124,7 +122,6 @@ wco = write_client_options(success_callback=callback.success,
124
122
  with InfluxDBClient3.InfluxDBClient3(
125
123
  token="INSERT_TOKEN",
126
124
  host="eu-central-1-1.aws.cloud2.influxdata.com",
127
- org="6a841c0c08328fb1",
128
125
  database="python", write_client_options=wco) as client:
129
126
 
130
127
 
@@ -171,27 +168,24 @@ Install `certifi`
171
168
  pip install certifi
172
169
  ```
173
170
  Next include certifi within the flight client options:
171
+
174
172
  ```python
173
+ import certifi
174
+
175
175
  import influxdb_client_3 as InfluxDBClient3
176
- import pandas as pd
177
- import numpy as np
178
176
  from influxdb_client_3 import flight_client_options
179
- import certifi
180
177
 
181
178
  fh = open(certifi.where(), "r")
182
179
  cert = fh.read()
183
180
  fh.close()
184
181
 
185
-
186
182
  client = InfluxDBClient3.InfluxDBClient3(
187
183
  token="",
188
184
  host="b0c7cce5-8dbc-428e-98c6-7f996fb96467.a.influxdb.io",
189
- org="6a841c0c08328fb1",
190
185
  database="flightdemo",
191
186
  flight_client_options=flight_client_options(
192
187
  tls_root_certs=cert))
193
188
 
194
-
195
189
  table = client.query(
196
190
  query="SELECT * FROM flight WHERE time > now() - 4h",
197
191
  language="influxql")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: influxdb3-python
3
- Version: 0.12.0
3
+ Version: 0.13.0
4
4
  Summary: Community Python client for InfluxDB 3.0
5
5
  Home-page: https://github.com/InfluxCommunity/influxdb3-python
6
6
  Author: InfluxData
@@ -104,13 +104,11 @@ from influxdb_client_3 import InfluxDBClient3, Point
104
104
 
105
105
  ## Initialization
106
106
  If you are using InfluxDB Cloud, then you should note that:
107
- 1. You will need to supply your org id, this is not necessary for InfluxDB Dedicated.
108
- 2. Use bucket name for the `database` argument.
107
+ 1. Use bucket name for the `database` argument.
109
108
 
110
109
  ```python
111
110
  client = InfluxDBClient3(token="your-token",
112
111
  host="your-host",
113
- org="your-org",
114
112
  database="your-database")
115
113
  ```
116
114
 
@@ -171,7 +169,6 @@ wco = write_client_options(success_callback=callback.success,
171
169
  with InfluxDBClient3.InfluxDBClient3(
172
170
  token="INSERT_TOKEN",
173
171
  host="eu-central-1-1.aws.cloud2.influxdata.com",
174
- org="6a841c0c08328fb1",
175
172
  database="python", write_client_options=wco) as client:
176
173
 
177
174
 
@@ -218,27 +215,24 @@ Install `certifi`
218
215
  pip install certifi
219
216
  ```
220
217
  Next include certifi within the flight client options:
218
+
221
219
  ```python
220
+ import certifi
221
+
222
222
  import influxdb_client_3 as InfluxDBClient3
223
- import pandas as pd
224
- import numpy as np
225
223
  from influxdb_client_3 import flight_client_options
226
- import certifi
227
224
 
228
225
  fh = open(certifi.where(), "r")
229
226
  cert = fh.read()
230
227
  fh.close()
231
228
 
232
-
233
229
  client = InfluxDBClient3.InfluxDBClient3(
234
230
  token="",
235
231
  host="b0c7cce5-8dbc-428e-98c6-7f996fb96467.a.influxdb.io",
236
- org="6a841c0c08328fb1",
237
232
  database="flightdemo",
238
233
  flight_client_options=flight_client_options(
239
234
  tls_root_certs=cert))
240
235
 
241
-
242
236
  table = client.query(
243
237
  query="SELECT * FROM flight WHERE time > now() - 4h",
244
238
  language="influxql")
@@ -1,17 +1,28 @@
1
+ import importlib.util
2
+ import os
1
3
  import urllib.parse
4
+ from typing import Any
5
+
2
6
  import pyarrow as pa
3
- import importlib.util
4
7
 
5
8
  from influxdb_client_3.query.query_api import QueryApi as _QueryApi, QueryApiOptionsBuilder
6
9
  from influxdb_client_3.read_file import UploadFile
7
10
  from influxdb_client_3.write_client import InfluxDBClient as _InfluxDBClient, WriteOptions, Point
8
11
  from influxdb_client_3.write_client.client.exceptions import InfluxDBError
9
12
  from influxdb_client_3.write_client.client.write_api import WriteApi as _WriteApi, SYNCHRONOUS, ASYNCHRONOUS, \
10
- PointSettings
13
+ PointSettings, DefaultWriteOptions, WriteType
11
14
  from influxdb_client_3.write_client.domain.write_precision import WritePrecision
12
15
 
13
16
  polars = importlib.util.find_spec("polars") is not None
14
17
 
18
+ INFLUX_HOST = "INFLUX_HOST"
19
+ INFLUX_TOKEN = "INFLUX_TOKEN"
20
+ INFLUX_DATABASE = "INFLUX_DATABASE"
21
+ INFLUX_ORG = "INFLUX_ORG"
22
+ INFLUX_PRECISION = "INFLUX_PRECISION"
23
+ INFLUX_AUTH_SCHEME = "INFLUX_AUTH_SCHEME"
24
+ INFLUX_GZIP_THRESHOLD = "INFLUX_GZIP_THRESHOLD"
25
+
15
26
 
16
27
  def write_client_options(**kwargs):
17
28
  """
@@ -83,6 +94,51 @@ def _merge_options(defaults, exclude_keys=None, custom=None):
83
94
  return _deep_merge(defaults, {key: value for key, value in custom.items() if key not in exclude_keys})
84
95
 
85
96
 
97
+ def _parse_precision(precision):
98
+ """
99
+ Parses the precision value and ensures it is valid.
100
+
101
+ This function checks that the given `precision` is one of the allowed
102
+ values defined in `WritePrecision`. If the precision is invalid, it
103
+ raises a `ValueError`. The function returns the valid precision value
104
+ if it passes validation.
105
+
106
+ :param precision: The precision value to be validated.
107
+ Must be one of WritePrecision.NS, WritePrecision.MS,
108
+ WritePrecision.S, or WritePrecision.US.
109
+ :return: The valid precision value.
110
+ :rtype: WritePrecision
111
+ :raises ValueError: If the provided precision is not valid.
112
+ """
113
+ if precision not in [WritePrecision.NS, WritePrecision.MS, WritePrecision.S, WritePrecision.US]:
114
+ raise ValueError(f"Invalid precision value: {precision}")
115
+ return precision
116
+
117
+
118
+ def _parse_gzip_threshold(threshold):
119
+ """
120
+ Parses and validates the provided threshold value.
121
+
122
+ This function ensures that the given threshold is a valid integer value,
123
+ and it raises an appropriate error if the threshold is not valid. It also
124
+ enforces that the threshold value is non-negative.
125
+
126
+ :param threshold: The input threshold value to be parsed and validated.
127
+ :type threshold: Any
128
+ :return: The validated threshold value as an integer.
129
+ :rtype: int
130
+ :raises ValueError: If the provided threshold is not an integer or if it is
131
+ negative.
132
+ """
133
+ try:
134
+ threshold = int(threshold)
135
+ except (TypeError, ValueError):
136
+ raise ValueError(f"Invalid threshold value: {threshold}. Must be integer.")
137
+ if threshold < 0:
138
+ raise ValueError(f"Invalid threshold value: {threshold}. Must be non-negative.")
139
+ return threshold
140
+
141
+
86
142
  class InfluxDBClient3:
87
143
  def __init__(
88
144
  self,
@@ -136,8 +192,23 @@ class InfluxDBClient3:
136
192
  self._org = org if org is not None else "default"
137
193
  self._database = database
138
194
  self._token = token
139
- self._write_client_options = write_client_options if write_client_options is not None \
140
- else default_client_options(write_options=SYNCHRONOUS)
195
+
196
+ write_type = DefaultWriteOptions.write_type.value
197
+ write_precision = DefaultWriteOptions.write_precision.value
198
+ if isinstance(write_client_options, dict) and write_client_options.get('write_options') is not None:
199
+ write_opts = write_client_options['write_options']
200
+ write_type = getattr(write_opts, 'write_type', write_type)
201
+ write_precision = getattr(write_opts, 'write_precision', write_precision)
202
+
203
+ write_options = WriteOptions(
204
+ write_type=write_type,
205
+ write_precision=write_precision,
206
+ )
207
+
208
+ self._write_client_options = {
209
+ "write_options": write_options,
210
+ **(write_client_options or {})
211
+ }
141
212
 
142
213
  # Parse the host input
143
214
  parsed_url = urllib.parse.urlparse(host)
@@ -178,6 +249,60 @@ class InfluxDBClient3:
178
249
  flight_client_options=flight_client_options,
179
250
  proxy=kwargs.get("proxy", None), options=q_opts_builder.build())
180
251
 
252
+ @classmethod
253
+ def from_env(cls, **kwargs: Any) -> 'InfluxDBClient3':
254
+ """
255
+ Creates an instance of the ``InfluxDBClient3`` class using environment
256
+ variables for configuration. This method simplifies client creation by
257
+ automatically reading required information from the system environment.
258
+
259
+ It verifies the presence of required environment variables such as host,
260
+ token, and database. If any of these variables are missing or empty,
261
+ a ``ValueError`` will be raised. Optional parameters such as precision and
262
+ authentication scheme will also be extracted from the environment when
263
+ present, allowing further customization of the client.
264
+
265
+ :param kwargs: Additional parameters that are passed to the client constructor.
266
+ :type kwargs: Any
267
+ :raises ValueError: If any required environment variables are missing or empty.
268
+ :return: An initialized client object of type ``InfluxDBClient3``.
269
+ :rtype: InfluxDBClient3
270
+ """
271
+ required_vars = {
272
+ INFLUX_HOST: os.getenv(INFLUX_HOST),
273
+ INFLUX_TOKEN: os.getenv(INFLUX_TOKEN),
274
+ INFLUX_DATABASE: os.getenv(INFLUX_DATABASE)
275
+ }
276
+ missing_vars = [var for var, value in required_vars.items() if value is None or value == ""]
277
+ if missing_vars:
278
+ raise ValueError(f"Missing required environment variables: {', '.join(missing_vars)}")
279
+
280
+ write_options = WriteOptions(write_type=WriteType.synchronous)
281
+
282
+ gzip_threshold = os.getenv(INFLUX_GZIP_THRESHOLD)
283
+ if gzip_threshold is not None:
284
+ kwargs['gzip_threshold'] = _parse_gzip_threshold(gzip_threshold)
285
+ kwargs['enable_gzip'] = True
286
+
287
+ precision = os.getenv(INFLUX_PRECISION)
288
+ if precision is not None:
289
+ write_options.write_precision = _parse_precision(precision)
290
+
291
+ write_client_option = {'write_options': write_options}
292
+
293
+ if os.getenv(INFLUX_AUTH_SCHEME) is not None:
294
+ kwargs['auth_scheme'] = os.getenv(INFLUX_AUTH_SCHEME)
295
+
296
+ org = os.getenv(INFLUX_ORG, "default")
297
+ return InfluxDBClient3(
298
+ host=required_vars[INFLUX_HOST],
299
+ token=required_vars[INFLUX_TOKEN],
300
+ database=required_vars[INFLUX_DATABASE],
301
+ write_client_options=write_client_option,
302
+ org=org,
303
+ **kwargs
304
+ )
305
+
181
306
  def write(self, record=None, database=None, **kwargs):
182
307
  """
183
308
  Write data to InfluxDB.
@@ -104,7 +104,7 @@ class QueryApi(object):
104
104
 
105
105
 
106
106
  # Initialize instance of QueryApi
107
- with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org") as client:
107
+ with InfluxDBClient(url="http://localhost:8086", token="my-token") as client:
108
108
  query_api = client.query_api()
109
109
  """
110
110
 
@@ -1,4 +1,4 @@
1
1
  """Version of the Client that is used in User-Agent header."""
2
2
 
3
- VERSION = '0.12.0'
3
+ VERSION = '0.13.0'
4
4
  USER_AGENT = f'influxdb3-python/{VERSION}'
@@ -2,16 +2,6 @@
2
2
 
3
3
  # flake8: noqa
4
4
 
5
- """
6
- InfluxDB OSS API Service.
7
-
8
- The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501
9
-
10
- OpenAPI spec version: 2.0.0
11
- Generated by: https://openapi-generator.tech
12
- """
13
-
14
-
15
5
  from __future__ import absolute_import
16
6
 
17
7
  from influxdb_client_3.write_client.client.write_api import WriteApi, WriteOptions
@@ -1,12 +1,4 @@
1
1
  # coding: utf-8
2
- """
3
- InfluxDB OSS API Service.
4
-
5
- The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501
6
-
7
- OpenAPI spec version: 2.0.0
8
- Generated by: https://openapi-generator.tech
9
- """
10
2
 
11
3
  from __future__ import absolute_import
12
4
 
@@ -28,17 +20,7 @@ from influxdb_client_3.write_client.rest import _requires_create_user_session, _
28
20
 
29
21
 
30
22
  class ApiClient(object):
31
- """Generic API client for OpenAPI client library Build.
32
-
33
- OpenAPI generic API client. This client handles the client-
34
- server communication, and is invariant across implementations. Specifics of
35
- the methods and models for each application are generated from the OpenAPI
36
- templates.
37
-
38
- NOTE: This class is auto generated by OpenAPI Generator.
39
- Ref: https://openapi-generator.tech
40
- Do not edit the class manually.
41
-
23
+ """
42
24
  :param configuration: .Configuration object for this client
43
25
  :param header_name: a header to pass when making calls to the API.
44
26
  :param header_value: a header value to pass when making calls to
@@ -110,6 +92,40 @@ class ApiClient(object):
110
92
  """Set HTTP header for this API client."""
111
93
  self.default_headers[header_name] = header_value
112
94
 
95
+ @staticmethod
96
+ def should_gzip(payload: str, enable_gzip: bool = False, gzip_threshold: int = None) -> bool:
97
+ """
98
+ Determines whether gzip compression should be applied to the given payload based
99
+ on the specified conditions. This method evaluates the `enable_gzip` flag and
100
+ considers the size of the payload in relation to the optional `gzip_threshold`.
101
+ If `enable_gzip` is set to True and no threshold is provided, gzip compression
102
+ is advised without any size condition. If a threshold is specified, compression
103
+ is applied only when the size of the payload meets or exceeds the threshold.
104
+ By default, no compression is performed if `enable_gzip` is False.
105
+
106
+ :param payload: The payload data as a string for which gzip determination is to
107
+ be made.
108
+ :type payload: str
109
+ :param enable_gzip: A flag indicating whether gzip compression is enabled. By
110
+ default, this flag is False.
111
+ :type enable_gzip: bool, optional
112
+ :param gzip_threshold: Optional threshold specifying the minimum size (in bytes)
113
+ of the payload to trigger gzip compression. Only considered if
114
+ `enable_gzip` is True.
115
+ :type gzip_threshold: int, optional
116
+ :return: A boolean value indicating True if gzip compression should be applied
117
+ based on the payload size, the enable_gzip flag, and the gzip_threshold.
118
+ :rtype: bool
119
+ """
120
+ if enable_gzip is not False:
121
+ if gzip_threshold is not None:
122
+ payload_size = len(payload.encode('utf-8'))
123
+ return payload_size >= gzip_threshold
124
+ if enable_gzip is True:
125
+ return True
126
+
127
+ return False
128
+
113
129
  def __call_api(
114
130
  self, resource_path, method, path_params=None,
115
131
  query_params=None, header_params=None, body=None, post_params=None,
@@ -120,9 +136,16 @@ class ApiClient(object):
120
136
  config = self.configuration
121
137
  self._signin(resource_path=resource_path)
122
138
 
139
+ # body
140
+ should_gzip = False
141
+ if body:
142
+ should_gzip = self.should_gzip(body, config.enable_gzip, config.gzip_threshold)
143
+ body = self.sanitize_for_serialization(body)
144
+ body = config.update_request_body(resource_path, body, should_gzip)
145
+
123
146
  # header parameters
124
147
  header_params = header_params or {}
125
- config.update_request_header_params(resource_path, header_params)
148
+ config.update_request_header_params(resource_path, header_params, should_gzip)
126
149
  header_params.update(self.default_headers)
127
150
  if self.cookie:
128
151
  header_params['Cookie'] = self.cookie
@@ -159,11 +182,6 @@ class ApiClient(object):
159
182
  # auth setting
160
183
  self.update_params_for_auth(header_params, query_params, auth_settings)
161
184
 
162
- # body
163
- if body:
164
- body = self.sanitize_for_serialization(body)
165
- body = config.update_request_body(resource_path, body)
166
-
167
185
  # request url
168
186
  url = self.configuration.host + resource_path
169
187
 
@@ -1,15 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
- """
4
- InfluxDB OSS API Service.
5
-
6
- The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501
7
-
8
- OpenAPI spec version: 2.0.0
9
- Generated by: https://openapi-generator.tech
10
- """
11
-
12
-
13
3
  from __future__ import absolute_import
14
4
 
15
5
  import io
@@ -28,11 +18,6 @@ except ImportError:
28
18
 
29
19
 
30
20
  class RESTResponse(io.IOBase):
31
- """NOTE: This class is auto generated by OpenAPI Generator.
32
-
33
- Ref: https://openapi-generator.tech
34
- Do not edit the class manually.
35
- """
36
21
 
37
22
  def __init__(self, resp):
38
23
  """Initialize with HTTP response."""
@@ -51,11 +36,6 @@ class RESTResponse(io.IOBase):
51
36
 
52
37
 
53
38
  class RESTClientObject(object):
54
- """NOTE: This class is auto generated by OpenAPI Generator.
55
-
56
- Ref: https://openapi-generator.tech
57
- Do not edit the class manually.
58
- """
59
39
 
60
40
  def __init__(self, configuration, pools_size=4, maxsize=None, retries=False):
61
41
  """Initialize REST client."""
@@ -1,15 +1,5 @@
1
1
  # flake8: noqa
2
2
 
3
- """
4
- InfluxDB OSS API Service.
5
-
6
- The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501
7
-
8
- OpenAPI spec version: 2.0.0
9
- Generated by: https://openapi-generator.tech
10
- """
11
-
12
-
13
3
  from __future__ import absolute_import
14
4
 
15
5
  # import apis into api package