influxdb3-python 0.1.9__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: influxdb3-python
3
- Version: 0.1.9
3
+ Version: 0.2.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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: influxdb3-python
3
- Version: 0.1.9
3
+ Version: 0.2.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
@@ -1,22 +1,42 @@
1
- import json
2
- import urllib.parse
1
+ import urllib.parse, json
3
2
  import pyarrow as pa
4
3
  from influxdb_client import InfluxDBClient as _InfluxDBClient, WriteOptions, Point
5
4
  from influxdb_client.client.write_api import WriteApi as _WriteApi, SYNCHRONOUS, ASYNCHRONOUS, PointSettings
6
5
  from influxdb_client.domain.write_precision import WritePrecision
7
6
  from influxdb_client.client.exceptions import InfluxDBError
8
7
  from pyarrow.flight import FlightClient, Ticket, FlightCallOptions
9
- from influxdb_client_3.read_file import upload_file
8
+ from influxdb_client_3.read_file import UploadFile
10
9
 
11
10
 
12
11
  def write_client_options(**kwargs):
12
+ """
13
+ Function for providing additional arguments for the WriteApi client.
14
+
15
+ :param kwargs: Additional arguments for the WriteApi client.
16
+ :return: dict with the arguments.
17
+ """
13
18
  return kwargs
14
19
 
15
20
  def default_client_options(**kwargs):
16
21
  return kwargs
17
22
 
18
23
  def flight_client_options(**kwargs):
19
- return kwargs # You can replace this with a specific data structure if needed
24
+ """
25
+ Function for providing additional arguments for the FlightClient.
26
+
27
+ :param kwargs: Additional arguments for the FlightClient.
28
+ :return: dict with the arguments.
29
+ """
30
+ return kwargs
31
+
32
+ def file_parser_options(**kwargs):
33
+ """
34
+ Function for providing additional arguments for the file parser.
35
+
36
+ :param kwargs: Additional arguments for the file parser.
37
+ :return: dict with the arguments.
38
+ """
39
+ return kwargs
20
40
 
21
41
 
22
42
  class InfluxDBClient3:
@@ -40,13 +60,13 @@ class InfluxDBClient3:
40
60
  :type database: str
41
61
  :param token: The authentication token for accessing the InfluxDB server.
42
62
  :type token: str
43
- :param write_client_options: Options for the WriteAPI.
44
- :type write_client_options: dict
45
- :param flight_client_options: Options for the FlightClient.
46
- :type flight_client_options: dict
63
+ :param write_client_options: Function for providing additional arguments for the WriteApi client.
64
+ :type write_client_options: callable
65
+ :param flight_client_options: Function for providing additional arguments for the FlightClient.
66
+ :type flight_client_options: callable
47
67
  :param kwargs: Additional arguments for the InfluxDB Client.
48
68
  """
49
- self._org = org
69
+ self._org = org if org is not None else "default"
50
70
  self._database = database
51
71
  self._token = token
52
72
  self._write_client_options = write_client_options if write_client_options is not None else default_client_options(write_options=SYNCHRONOUS)
@@ -72,7 +92,9 @@ class InfluxDBClient3:
72
92
  Write data to InfluxDB.
73
93
 
74
94
  :param record: The data point(s) to write.
75
- :type record: Point or list of Point objects
95
+ :type record: object or list of objects
96
+ :param database: The database to write to. If not provided, uses the database provided during initialization.
97
+ :type database: str
76
98
  :param kwargs: Additional arguments to pass to the write API.
77
99
  """
78
100
  if database is None:
@@ -84,7 +106,7 @@ class InfluxDBClient3:
84
106
  raise e
85
107
 
86
108
 
87
- def write_file(self, file, measurement_name=None, tag_columns=None, timestamp_column='time', database=None, **kwargs):
109
+ def write_file(self, file, measurement_name=None, tag_columns=None, timestamp_column='time', database=None, file_parser_options=None ,**kwargs):
88
110
  """
89
111
  Write data from a file to InfluxDB.
90
112
 
@@ -96,13 +118,17 @@ class InfluxDBClient3:
96
118
  :type tag_columns: list
97
119
  :param timestamp_column: Timestamp column name. Defaults to 'time'.
98
120
  :type timestamp_column: str
121
+ :param database: The database to write to. If not provided, uses the database provided during initialization.
122
+ :type database: str
123
+ :param file_parser_options: Function for providing additional arguments for the file parser.
124
+ :type file_parser_options: callable
99
125
  :param kwargs: Additional arguments to pass to the write API.
100
126
  """
101
127
  if database is None:
102
128
  database = self._database
103
129
 
104
130
  try:
105
- table = upload_file(file).load_file()
131
+ table = UploadFile(file, file_parser_options).load_file()
106
132
  df = table.to_pandas() if isinstance(table, pa.Table) else table
107
133
  self._process_dataframe(df, measurement_name, tag_columns or [], timestamp_column, database=database, **kwargs)
108
134
  except Exception as e:
@@ -138,10 +164,13 @@ class InfluxDBClient3:
138
164
 
139
165
  :param query: The query string.
140
166
  :type query: str
141
- :param language: The query language (default is "sql").
167
+ :param language: The query language; "sql" or "influxql" (default is "sql").
142
168
  :type language: str
143
169
  :param mode: The mode of fetching data (all, pandas, chunk, reader, schema).
144
170
  :type mode: str
171
+ :param database: The database to query from. If not provided, uses the database provided during initialization.
172
+ :type database: str
173
+ :param kwargs: Additional arguments for the query.
145
174
  :return: The queried data.
146
175
  """
147
176
  if database is None:
@@ -188,5 +217,6 @@ __all__ = [
188
217
  "WritePrecision",
189
218
  "WriteOptions",
190
219
  "write_client_options",
191
- "flight_client_options"
220
+ "flight_client_options",
221
+ "file_parser_options"
192
222
  ]
@@ -0,0 +1,99 @@
1
+ import os
2
+ import pyarrow.csv as csv
3
+ import pyarrow.feather as feather
4
+ import pyarrow.parquet as parquet
5
+ import pandas as pd
6
+
7
+ # Check if the OS is not Windows
8
+ if os.name != 'nt':
9
+ import pyarrow.orc as orc
10
+
11
+
12
+ class UploadFile:
13
+ """
14
+ Class for uploading and reading different types of files.
15
+ """
16
+ def __init__(self, file, file_parser_options=None):
17
+ """
18
+ Initialize an UploadFile instance.
19
+
20
+ :param file: The file to upload.
21
+ :type file: str
22
+ :param kwargs: Additional arguments for file loading functions.
23
+ """
24
+ self._file = file
25
+ self._kwargs = file_parser_options if file_parser_options is not None else {}
26
+
27
+ def load_file(self):
28
+ """
29
+ Load a file based on its extension.
30
+
31
+ :return: The loaded file.
32
+ :raises ValueError: If the file type is not supported.
33
+ """
34
+ if self._file.endswith(".feather"):
35
+ return self.load_feather(self._file)
36
+ elif self._file.endswith(".parquet"):
37
+ return self.load_parquet(self._file)
38
+ elif self._file.endswith(".csv"):
39
+ return self.load_csv(self._file)
40
+ elif self._file.endswith(".json"):
41
+ return self.load_json(self._file)
42
+ elif self._file.endswith(".orc"):
43
+ return self.load_orc(self._file)
44
+ else:
45
+ raise ValueError("Unsupported file type")
46
+
47
+ def load_feather(self, file ):
48
+ """
49
+ Load a Feather file.
50
+
51
+ :param file: The Feather file to load.
52
+ :type file: str
53
+ :return: The loaded Feather file.
54
+ """
55
+ return feather.read_table(file, **self._kwargs)
56
+
57
+ def load_parquet(self, file):
58
+ """
59
+ Load a Parquet file.
60
+
61
+ :param file: The Parquet file to load.
62
+ :type file: str
63
+ :return: The loaded Parquet file.
64
+ """
65
+ return parquet.read_table(file, **self._kwargs)
66
+
67
+ def load_csv(self, file):
68
+ """
69
+ Load a CSV file.
70
+
71
+ :param file: The CSV file to load.
72
+ :type file: str
73
+ :return: The loaded CSV file.
74
+ """
75
+ return csv.read_csv(file, **self._kwargs)
76
+
77
+ def load_orc(self, file):
78
+ """
79
+ Load an ORC file.
80
+
81
+ :param file: The ORC file to load.
82
+ :type file: str
83
+ :return: The loaded ORC file.
84
+ :raises ValueError: If the OS is Windows.
85
+ """
86
+ if os.name == 'nt':
87
+ raise ValueError("Unsupported file type for this OS")
88
+ else:
89
+ return orc.read_table(file, **self._kwargs)
90
+
91
+ def load_json(self, file):
92
+ """
93
+ Load a JSON file.
94
+
95
+ :param file: The JSON file to load.
96
+ :type file: str
97
+ :return: The loaded JSON file.
98
+ """
99
+ return pd.read_json(file, **self._kwargs)
@@ -1,51 +0,0 @@
1
- from pyarrow import json as pa_json
2
- import pyarrow.csv as csv
3
- import pyarrow.feather as feather
4
- import pyarrow.parquet as parquet
5
- import os
6
-
7
- # Check if the OS is not Windows
8
- if os.name != 'nt':
9
- import pyarrow.orc as orc
10
-
11
- import pandas as pd
12
-
13
- class upload_file:
14
- def __init__(self, file, **kwargs):
15
- self._file = file
16
- self._kwargs = kwargs
17
-
18
- def load_file(self):
19
- if self._file.endswith(".feather"):
20
- return self.load_feather(self._file, **self._kwargs)
21
- elif self._file.endswith(".parquet"):
22
- return self.load_parquet(self._file)
23
- elif self._file.endswith(".csv"):
24
- return self.load_csv(self._file)
25
- elif self._file.endswith(".json"):
26
- return self.load_json(self._file)
27
- elif self._file.endswith(".orc"):
28
-
29
- return self.load_orc(self._file)
30
- else:
31
- raise ValueError("Unsupported file type")
32
-
33
- def load_feather(self, file):
34
- return feather.read_table(file, **self._kwargs)
35
-
36
- def load_parquet(self, file):
37
- return parquet.read_table(file, **self._kwargs)
38
-
39
- def load_csv(self, file):
40
- return csv.read_csv(file, **self._kwargs)
41
-
42
- def load_orc(self, file):
43
- if os.name == 'nt':
44
- raise ValueError("Unsupported file type for this OS")
45
- else:
46
- return orc.read_table(file, **self._kwargs)
47
-
48
- #TODO: Use pyarrow.json.read_json() instead of pandas.read_json()
49
- def load_json(self, file):
50
- return pd.read_json(file, **self._kwargs)
51
-