Package: influxdb3-python-cli
influxdb3-python-cliAboutThis repository contains a CLI extension to theinfluxdb 3.0 python client library. While this code is built on officially supported APIs, the library and CLI here are not officially support by InfluxData.InstallTo install the CLI, enter the following command in your terminal:python3-mpipinstallinfluxdb3-python-cliScope and privilegesPython provides the following methods for installing packages within a specific scope:To isolate the CLI (and its dependencies) to your project directory, install the CLI in avirtual environment.See how to create and use avenvorcondaPython virtual environment.To install the client to a user-specific directory (without administrative rights), pass the--userflag in thepipcommand.To install the client in your system-wide path, usesudowith admin privileges.Add a configTo configure the CLI, dooneof the following:Use theinflux3 create configcommand to create or modify config--for example:influx3createconfig\--name="my-config"\--database="<database or bucket name>"\--host="us-east-1-1.aws.cloud2.influxdata.com"\--token="<your token>"\--org="<your org ID>"The output is the configuration in aconfig.jsonfile. This is saved within a directory calledconfiglocated within yourDocumentsfolder.If you're running the CLI against InfluxDB Cloud Serverless, replaceyour-databasein the examples with your Cloud Serverlessbucket name.Run as a commandinflux3 sql "select * from anomalies"influx3 write testmes f=7Query and write interactivelyIn your terminal, enter the following command:influx3influx3displays the(>)interactive prompt and waits for input.Welcome to my IOx CLI.

(>)To query, typesqlat the prompt.(>) sqlAt the(sql >)prompt, enter your query statement:(sql >) select * from homeTheinflux3CLI displays query results in Markdown table format--for example:|     |   co |   hum | room        |   temp | time                          |
|----:|-----:|------:|:------------|-------:|:------------------------------|
|   0 |    0 |  35.9 | Kitchen     |   21   | 2023-03-09 08:00:00           |
|   1 |    0 |  35.9 | Kitchen     |   21   | 2023-03-09 08:00:50           |To write, typewriteat the(>)prompt.(>) writeAt the(write >)prompt, enter line protocol data.(>) write 
home,room=kitchen temp=70.5,hum=80To exit a prompt, enterexit.Write from a fileThe InfluxDB CLI and client library can write data from CSV, JSON, ORC, Parquet and Feather files.
The CSV file must contain the following:A header row with column namesA column that contains a timestamp for each rowThe following CLI options specify how data is parsed:--file- The path to the file.--time- The name of the column containing the timestamp.--measurement- The name of the measurement to store the data under. (Optional, will look for a measurement column in data otherwise).--tags- (optional) Specify an array of column names to use as tags. (Currently only supports user-specified strings) for example:--tags=host,regionThe following example shows how to write CSV data from the./Examples/example.csvfileto InfluxDB (as line protocol):influx3write_file--file./Examples/example.csv--measurementtable2--timeDate--tagshost,regionConfig CommandsTheconfigcommand allows you to manage configurations for your application. It has the following subcommands:create,update,use,delete, andlist.CreateThecreatesubcommand creates a new configuration. It requires the--name,--host,--token,--database, and--orgparameters. The--activeparameter is optional and can be used to set the new configuration as the active one.Example usage:influx3.pyconfigcreate--name="my-config"--host="us-east-1-1.aws.cloud2.influxdata.com"--token="<your token>"--database="<database or bucket name>"--org="<your org ID>"--activeUpdateTheupdatesubcommand updates an existing configuration. The--nameparameter is required to specify which configuration to update. All other parameters (--host,--token,--database,--org,--active) are optional.Example usage:influx3.pyconfigupdate--name="my-config"--host="new-host.com"UseTheusesubcommand sets a specific configuration as the active one. The--nameparameter is required to specify which configuration to use.Example usage:influx3.pyconfiguse--name="my-config"DeleteThedeletesubcommand deletes a configuration. The--nameparameter is required to specify which configuration to delete.Example usage:influx3.pyconfigdelete--name="my-config"ListThelistsubcommand lists all the configurations.Example usage:influx3.pyconfiglistPlease replace"my-config","us-east-1-1.aws.cloud2.influxdata.com","<your token>","<database or bucket name>", and"<your org ID>"with your actual values.(Beta) OpenAI (ChatGPT) SupportThe CLI also contians a beta feature that allows you to query your data using OpenAI's ChatGPT. To use this feature, you must have an OpenAI API key. You can get one by signing up for theOpenAI waitlist. Once you have an API key, you can set it as an environment variable calledOPENAI_API_KEY.To use this feature, you can use thechatgptcommand:export OPENAI_API_KEY=sk-o2Sbq3aVBp

influx3 chatgpt get average vibration grouped by machineID from machine_data
Run InfluxQL query: SELECT MEAN(vibration) AS avg_vibration FROM machine_data GROUP BY machineID
|    | iox::measurement   | time                | machineID   |   avg_vibration |
|---:|:-------------------|:--------------------|:------------|----------------:|
|  0 | machine_data       | 1970-01-01 00:00:00 | machine1    |         85.2356 |
|  1 | machine_data       | 1970-01-01 00:00:00 | machine2    |        190.273  |
|  2 | machine_data       | 1970-01-01 00:00:00 | machine3    |         85.4789 |
Press TAB to fetch next chunk of dataClient libraryThe underlying client library is also available for use in your own code:https://github.com/InfluxCommunity/influxdb3-pythonContributionWhen developing a new feature for the CLI or the client library, make sure to test your feature in both for breaking changes.