Skip to main content

Your Image

PyPI version PyPI downloads Lint Code Base Lint Code Base Community Slack

influxdb3-python-cli

About

This repository contains a CLI extension to the influxdb 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.

Install

To install the CLI, enter the following command in your terminal:

python3 -m pip install influxdb3-python-cli

Scope and privileges

Python 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 a virtual environment. See how to create and use a venv or conda Python virtual environment.
  • To install the client to a user-specific directory (without administrative rights), pass the --user flag in the pip command.
  • To install the client in your system-wide path, use sudo with admin privileges.

Add a config

To configure the CLI, do one of the following:

  • Use the influx3 create config command to create or modify config--for example:

    influx3 create config \
    --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 a config.json file. This is saved within a directory called config located within your Documents folder.

If you're running the CLI against InfluxDB Cloud Serverless, replace your-database in the examples with your Cloud Serverless bucket name.

Run as a command

influx3 sql "select * from anomalies"
influx3 write testmes f=7 

Query and write interactively

In your terminal, enter the following command:

influx3

influx3 displays the (>) interactive prompt and waits for input.

Welcome to my IOx CLI.

(>)

To query, type sql at the prompt.

(>) sql

At the (sql >) prompt, enter your query statement:

(sql >) select * from home

The influx3 CLI 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, type write at the (>) prompt.

(>) write

At the (write >) prompt, enter line protocol data.

(>) write 
home,room=kitchen temp=70.5,hum=80

To exit a prompt, enter exit.

Write from a file

The 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 names
  • A column that contains a timestamp for each row

The 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,region

The following example shows how to write CSV data from the ./Examples/example.csv file to InfluxDB (as line protocol):

influx3 write_file --file ./Examples/example.csv --measurement table2 --time Date --tags host,region

Config Commands

The config command allows you to manage configurations for your application. It has the following subcommands: create, update, use, delete, and list.

Create

The create subcommand creates a new configuration. It requires the --name, --host, --token, --database, and --org parameters. The --active parameter is optional and can be used to set the new configuration as the active one.

Example usage:

influx3.py config create --name="my-config" --host="us-east-1-1.aws.cloud2.influxdata.com" --token="<your token>" --database="<database or bucket name>" --org="<your org ID>" --active

Update

The update subcommand updates an existing configuration. The --name parameter is required to specify which configuration to update. All other parameters (--host, --token, --database, --org, --active) are optional.

Example usage:

influx3.py config update --name="my-config" --host="new-host.com"

Use

The use subcommand sets a specific configuration as the active one. The --name parameter is required to specify which configuration to use.

Example usage:

influx3.py config use --name="my-config"

Delete

The delete subcommand deletes a configuration. The --name parameter is required to specify which configuration to delete.

Example usage:

influx3.py config delete --name="my-config"

List

The list subcommand lists all the configurations.

Example usage:

influx3.py config list

Please 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) Support

The 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 the OpenAI waitlist. Once you have an API key, you can set it as an environment variable called OPENAI_API_KEY.

To use this feature, you can use the chatgpt command:

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 data

Client library

The underlying client library is also available for use in your own code: https://github.com/InfluxCommunity/influxdb3-python

Contribution

When developing a new feature for the CLI or the client library, make sure to test your feature in both for breaking changes.

Release files for influxdb3-python-cli 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for influxdb3-python-cli 0.3.2
File Size Uploaded
influxdb3-python-cli-0.3.2.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for influxdb3-python-cli 0.3.2
File Interpreter ABI Platform
influxdb3_python_cli-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 28.5 kB

Release files / influxdb3-python-cli-0.3.2.tar.gz

Download URL influxdb3-python-cli-0.3.2.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f8ac2ea5d015c24976329af4c42c0d1cffad1a6b252df02afd4a0d6a893824d2
BLAKE2b-256 checksum
How to use checksums
a0bf0e5d24f72c8974885cc679cde0aa93078b7dbd6c15d11b5158f7672093d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / influxdb3_python_cli-0.3.2-py3-none-any.whl

Download URL influxdb3_python_cli-0.3.2-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
387ab67415576140df085e15ca59447faae34c4d0d18066d6353a414f03859a3
BLAKE2b-256 checksum
How to use checksums
98077d8273db0d2f168899e3742768583464a7bff6cff0580f71b84edb5bb4d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page