We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call client.write_file() and pass a JSON or CSV file.
client.write_file()
from influxdb_client_3 import(InfluxDBClient3, write_client_options, WritePrecision, WriteOptions, InfluxDBError) # Define the result object result = { 'config': None, 'status': None, 'data': None, 'error': None } # Define callbacks for write responses def success_callback(self, data: str): result['config'] = self result['status'] = 'success' result['data'] = data def error_callback(self, data: str, exception: InfluxDBError): result['config'] = self result['status'] = 'error' result['data'] = data result['error'] = exception def retry_callback(self, data: str, exception: InfluxDBError): result['config'] = self result['status'] = 'retry_error' result['data'] = data result['error'] = exception write_options = WriteOptions(batch_size=500, flush_interval=10_000, jitter_interval=2_000, retry_interval=5_000, max_retries=5, max_retry_delay=30_000, exponential_base=2) wco = write_client_options(success_callback=success_callback, error_callback=error_callback, retry_callback=retry_callback, write_options=write_options) with InfluxDBClient3(host=f"{{< influxdb/host >}}", database=f"DATABASE_NAME", token=f"DATABASE_TOKEN", write_client_options=wco) as client: client.write_file(file='./data/home.csv', timestamp_column='time', tag_columns=["room"], write_precision='s') assert result['status'] == "success", f"Expected CSV {result['error']} to be success" client.write_file(file='./data/home.json', timestamp_column='time', tag_columns=["room"], write_precision='s') assert result['status'] == "success", f"Expected JSON {result['error']} to be success"
See below for more examples/details.
I expect the batch to be written and to not require polars for writing CSV or JSON.
It throws the following error:
`polars_frame` requires polars which couldn't be imported due: No module named 'polars'
See the following for dependency versions and example pytest failures:
✔ Container docs-v2-tests Created 0.0s Attaching to docs-v2-tests docs-v2-tests | PRETEST: substituting values in ./content/influxdb/cloud-dedicated/reference/client-libraries/v3/python.md docs-v2-tests | Package Version docs-v2-tests | -------------------- ----------- docs-v2-tests | annotated-types 0.7.0 docs-v2-tests | anyio 4.3.0 docs-v2-tests | certifi 2024.2.2 docs-v2-tests | coverage 7.5.1 docs-v2-tests | distro 1.9.0 docs-v2-tests | h11 0.14.0 docs-v2-tests | httpcore 1.0.5 docs-v2-tests | httpx 0.27.0 docs-v2-tests | idna 3.7 docs-v2-tests | influxdb3-python 0.0.0 docs-v2-tests | influxdb3-python-cli 0.0.0 docs-v2-tests | iniconfig 2.0.0 docs-v2-tests | numpy 1.26.4 docs-v2-tests | openai 1.30.2 docs-v2-tests | packaging 24.0 docs-v2-tests | pandas 2.2.2 docs-v2-tests | pip 23.0.1 docs-v2-tests | pluggy 1.5.0 docs-v2-tests | prompt-toolkit 3.0.43 docs-v2-tests | pyarrow 16.1.0 docs-v2-tests | pydantic 2.7.1 docs-v2-tests | pydantic_core 2.18.2 docs-v2-tests | Pygments 2.18.0 docs-v2-tests | pytest 8.2.1 docs-v2-tests | pytest_codeblocks 0.17.0 docs-v2-tests | pytest-cov 5.0.0 docs-v2-tests | pytest-dotenv 0.5.2 docs-v2-tests | python-dateutil 2.9.0.post0 docs-v2-tests | python-dotenv 1.0.1 docs-v2-tests | pytz 2024.1 docs-v2-tests | reactivex 4.0.4 docs-v2-tests | setuptools 66.1.1 docs-v2-tests | six 1.16.0 docs-v2-tests | sniffio 1.3.1 docs-v2-tests | tabulate 0.9.0 docs-v2-tests | tqdm 4.66.4 docs-v2-tests | typing_extensions 4.11.0 docs-v2-tests | tzdata 2024.1 docs-v2-tests | urllib3 2.2.1 docs-v2-tests | wcwidth 0.2.13 docs-v2-tests | Running content/influxdb/cloud-dedicated tests... docs-v2-tests | ============================= test session starts ============================== docs-v2-tests | platform linux -- Python 3.11.2, pytest-8.2.1, pluggy-1.5.0 docs-v2-tests | rootdir: /usr/src/app/test docs-v2-tests | configfile: pytest.ini docs-v2-tests | plugins: anyio-4.3.0, cov-5.0.0, dotenv-0.5.2, pytest_codeblocks-0.17.0 docs-v2-tests | collected 23 items docs-v2-tests | docs-v2-tests | content/influxdb/cloud-dedicated/reference/client-libraries/v3/python.md F [ 4%] docs-v2-tests | .....F...F.........ss. [100%] docs-v2-tests | docs-v2-tests | =================================== FAILURES =================================== docs-v2-tests | _______________________________ code block check _______________________________ docs-v2-tests | line 18, line 18: docs-v2-tests | ``` docs-v2-tests | import os docs-v2-tests | from influxdb_client_3 import(InfluxDBClient3, docs-v2-tests | WriteOptions, docs-v2-tests | write_client_options) docs-v2-tests | # Instantiate batch writing options for the client docs-v2-tests | write_options = WriteOptions() docs-v2-tests | wco = write_client_options(write_options=write_options) docs-v2-tests | # Instantiate an InfluxDB v3 client docs-v2-tests | with InfluxDBClient3(host=os.getenv("INFLUX_HOSTNAME"), docs-v2-tests | database=os.getenv("INFLUX_DATABASE"), docs-v2-tests | token=os.getenv("INFLUX_TOKEN"), docs-v2-tests | write_client_options=wco) as client: docs-v2-tests | # Write data in batches docs-v2-tests | client.write_file(file='./data/home.csv', timestamp_column='time', docs-v2-tests | tag_columns=["room"]) docs-v2-tests | # Execute a query and retrieve data formatted as a PyArrow Table docs-v2-tests | table = client.query( docs-v2-tests | '''SELECT * docs-v2-tests | FROM home docs-v2-tests | WHERE time >= now() - INTERVAL '90 days' docs-v2-tests | ORDER BY time''') docs-v2-tests | ``` docs-v2-tests | docs-v2-tests | `polars_frame` requires polars which couldn't be imported due: No module named 'polars' docs-v2-tests | _______________________________ code block check _______________________________ docs-v2-tests | line 279, line 279: docs-v2-tests | ``` docs-v2-tests | import os docs-v2-tests | from influxdb_client_3 import(InfluxDBClient3, docs-v2-tests | write_client_options, docs-v2-tests | WriteOptions, docs-v2-tests | InfluxDBError) docs-v2-tests | docs-v2-tests | status = None docs-v2-tests | docs-v2-tests | # Define callbacks for write responses docs-v2-tests | def success(self, data: str): docs-v2-tests | status = f"Success writing batch: data: {data}" docs-v2-tests | docs-v2-tests | def error(self, data: str, err: InfluxDBError): docs-v2-tests | status = f"Error writing batch: config: {self}, data: {data}, error: {err}" docs-v2-tests | docs-v2-tests | def retry(self, data: str, err: InfluxDBError): docs-v2-tests | status = f"Retry error writing batch: config: {self}, data: {data}, error: {err}" docs-v2-tests | docs-v2-tests | # Instantiate WriteOptions for batching docs-v2-tests | write_options = WriteOptions() docs-v2-tests | wco = write_client_options(success_callback=success, docs-v2-tests | error_callback=error, docs-v2-tests | retry_callback=retry, docs-v2-tests | write_options=write_options) docs-v2-tests | docs-v2-tests | # Use the with...as statement to ensure the file is properly closed and resources docs-v2-tests | # are released. docs-v2-tests | with InfluxDBClient3(host=os.getenv("INFLUX_HOSTNAME"), docs-v2-tests | database=os.getenv("INFLUX_DATABASE"), docs-v2-tests | token=os.getenv("INFLUX_TOKEN"), docs-v2-tests | write_client_options=wco) as client: docs-v2-tests | docs-v2-tests | client.write_file(file='./data/home.csv', docs-v2-tests | timestamp_column='time', tag_columns=["room"], write_precision='s') docs-v2-tests | docs-v2-tests | assert status.startsWith('Success'), f"Expected {status} to be success" docs-v2-tests | ``` docs-v2-tests | docs-v2-tests | `polars_frame` requires polars which couldn't be imported due: No module named 'polars' docs-v2-tests | _______________________________ code block check _______________________________ docs-v2-tests | line 536, line 536: docs-v2-tests | ``` docs-v2-tests | import os docs-v2-tests | from influxdb_client_3 import(InfluxDBClient3, write_client_options, docs-v2-tests | WritePrecision, WriteOptions, InfluxDBError) docs-v2-tests | docs-v2-tests | # Define the result object docs-v2-tests | result = { docs-v2-tests | 'config': None, docs-v2-tests | 'status': None, docs-v2-tests | 'data': None, docs-v2-tests | 'error': None docs-v2-tests | } docs-v2-tests | docs-v2-tests | # Define callbacks for write responses docs-v2-tests | def success_callback(self, data: str): docs-v2-tests | result['config'] = self docs-v2-tests | result['status'] = 'success' docs-v2-tests | result['data'] = data docs-v2-tests | docs-v2-tests | def error_callback(self, data: str, exception: InfluxDBError): docs-v2-tests | result['config'] = self docs-v2-tests | result['status'] = 'error' docs-v2-tests | result['data'] = data docs-v2-tests | result['error'] = exception docs-v2-tests | docs-v2-tests | def retry_callback(self, data: str, exception: InfluxDBError): docs-v2-tests | result['config'] = self docs-v2-tests | result['status'] = 'retry_error' docs-v2-tests | result['data'] = data docs-v2-tests | result['error'] = exception docs-v2-tests | docs-v2-tests | write_options = WriteOptions(batch_size=500, docs-v2-tests | flush_interval=10_000, docs-v2-tests | jitter_interval=2_000, docs-v2-tests | retry_interval=5_000, docs-v2-tests | max_retries=5, docs-v2-tests | max_retry_delay=30_000, docs-v2-tests | exponential_base=2) docs-v2-tests | docs-v2-tests | docs-v2-tests | wco = write_client_options(success_callback=success_callback, docs-v2-tests | error_callback=error_callback, docs-v2-tests | retry_callback=retry_callback, docs-v2-tests | write_options=write_options) docs-v2-tests | docs-v2-tests | with InfluxDBClient3(host=os.getenv("INFLUX_HOSTNAME"), docs-v2-tests | database=os.getenv("INFLUX_DATABASE"), docs-v2-tests | token=os.getenv("INFLUX_TOKEN"), docs-v2-tests | write_client_options=wco) as client: docs-v2-tests | docs-v2-tests | client.write_file(file='./data/home.csv', timestamp_column='time', docs-v2-tests | tag_columns=["room"], write_precision='s') docs-v2-tests | docs-v2-tests | assert result['status'] == "success", f"Expected CSV {result['error']} to be success" docs-v2-tests | docs-v2-tests | client.write_file(file='./data/home.json', timestamp_column='time', docs-v2-tests | tag_columns=["room"], write_precision='s') docs-v2-tests | docs-v2-tests | assert result['status'] == "success", f"Expected JSON {result['error']} to be success" docs-v2-tests | ``` docs-v2-tests | docs-v2-tests | `polars_frame` requires polars which couldn't be imported due: No module named 'polars' docs-v2-tests | =========================== short test summary info ============================ docs-v2-tests | FAILED content/influxdb/cloud-dedicated/reference/client-libraries/v3/python.md::line 18 docs-v2-tests | FAILED content/influxdb/cloud-dedicated/reference/client-libraries/v3/python.md::line 279 docs-v2-tests | FAILED content/influxdb/cloud-dedicated/reference/client-libraries/v3/python.md::line 536 docs-v2-tests | =================== 3 failed, 18 passed, 2 skipped in 3.69s ====================
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Specifications
Call
client.write_file()
and pass a JSON or CSV file.Code sample to reproduce problem
See below for more examples/details.
Expected behavior
I expect the batch to be written and to not require polars for writing CSV or JSON.
Actual behavior
It throws the following error:
Additional info
See the following for dependency versions and example pytest failures:
The text was updated successfully, but these errors were encountered: