Skip to content

feat: Add CLI#208

Merged
karel-rehor merged 4 commits intoInfluxCommunity:mainfrom
TheTrueAI:add-cli
May 6, 2026
Merged

feat: Add CLI#208
karel-rehor merged 4 commits intoInfluxCommunity:mainfrom
TheTrueAI:add-cli

Conversation

@TheTrueAI
Copy link
Copy Markdown
Contributor

@TheTrueAI TheTrueAI commented Apr 20, 2026

Proposed Changes

Developers and AI tooling need a simple, scriptable query command for fast feedback during development. Existing community Python CLI seems unmaintained and not aligned with current behavior. So this PR introduces the following:

  • Adds a new influx3 query CLI path for read/query workflows.
  • Supports SQL and InfluxQL queries with JSON, JSONL, CSV, and pretty output formats.
  • Adds module entrypoint support so the CLI can also be run through python -m influxdb_client_3.
  • Fixes Windows-specific PEM newline handling for Flight query TLS root certificates.

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional
  • Sign CLA (if not already signed)

@TheTrueAI TheTrueAI changed the title Add CLI feat: Add CLI Apr 20, 2026
Copy link
Copy Markdown
Member

@bednar bednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheTrueAI thanks for the PR. There is already an existing CLI tool: https://docs.influxdata.com/influxdb3/core/reference/cli/influxdb3/. What’s the reason for creating a new one in the Python v3 client?

@TheTrueAI
Copy link
Copy Markdown
Contributor Author

Good point — the official influxdb3 query CLI does cover the same query functionality. My motivation was zero-install in Python environments: pip install influxdb3-python gives you the CLI inside the venv with no separate binary needed. This is useful for Python-centric CI and AI agent workflows where adding system binaries is friction.

Happy to scope this down or close if you feel the overlap isn't justified.

@bednar
Copy link
Copy Markdown
Member

bednar commented Apr 22, 2026

Good point — the official influxdb3 query CLI does cover the same query functionality. My motivation was zero-install in Python environments: pip install influxdb3-python gives you the CLI inside the venv with no separate binary needed. This is useful for Python-centric CI and AI agent workflows where adding system binaries is friction.

Happy to scope this down or close if you feel the overlap isn't justified.

Thanks for explanation, every PR is welcome so we will be happy to review your code. Thanks again for your contribution.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a first-party, scriptable influx3 query CLI for executing SQL/InfluxQL queries against InfluxDB 3, and adds a small Windows-focused TLS root cert compatibility fix for Flight query PEM loading.

Changes:

  • Add influx3 console script + python -m influxdb_client_3 module entrypoint for query workflows.
  • Implement query execution + output formatting (JSON/JSONL/CSV/pretty), config/env precedence, and basic error handling.
  • Normalize PEM certificate line endings when reading Flight query root certs.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
influxdb_client_3/cli.py New CLI implementation for influx3 query including formatting, env precedence, and output handling.
influxdb_client_3/__main__.py Enables python -m influxdb_client_3 CLI execution.
setup.py Adds console_scripts entry point for influx3.
tests/test_cli.py Adds unit tests for CLI parsing and core query execution paths.
influxdb_client_3/query/query_api.py Normalizes PEM line endings when reading root certificates.
README.md Documents CLI usage, formats, and configuration precedence.
CHANGELOG.md Adds feature + bug-fix entries for the CLI and PEM normalization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread influxdb_client_3/cli.py Outdated
Comment thread influxdb_client_3/cli.py
Comment thread influxdb_client_3/query/query_api.py
Comment thread tests/test_cli.py Outdated
Comment thread influxdb_client_3/cli.py
Comment thread influxdb_client_3/cli.py
@TheTrueAI TheTrueAI force-pushed the add-cli branch 2 times, most recently from 4a4b595 to fde7f67 Compare April 23, 2026 11:46
@TheTrueAI TheTrueAI requested a review from bednar April 23, 2026 18:21
@bednar bednar requested review from Copilot and karel-rehor and removed request for bednar April 27, 2026 08:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CHANGELOG.md Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 92.91339% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.05%. Comparing base (a1e03da) to head (c90beeb).

Files with missing lines Patch % Lines
influxdb_client_3/cli.py 95.08% 6 Missing ⚠️
influxdb_client_3/__main__.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #208      +/-   ##
==========================================
+ Coverage   75.17%   76.05%   +0.87%     
==========================================
  Files          35       37       +2     
  Lines        2417     2543     +126     
==========================================
+ Hits         1817     1934     +117     
- Misses        600      609       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TheTrueAI
Copy link
Copy Markdown
Contributor Author

What's the goal of the code coverage? Should I increase it?

@alespour
Copy link
Copy Markdown
Contributor

alespour commented May 4, 2026

Patch coverage check passed.
I think just rebase it please.

Comment thread README.md
Copy link
Copy Markdown
Contributor

@karel-rehor karel-rehor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @TheTrueAI,

Thank you for this contribution. It looks very complete.

While testing it out I ran into a minor problem when querying data with nanosecond time precision. PyArrow needs pandas installed in order for this to work.

$ influx3 query "SELECT * FROM testnanosec"
Traceback (most recent call last):
  File "/home/karl/bonitoo/prjs/github.com/TheTrueAI/influxdb3-python/venv/bin/influx3", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/karl/bonitoo/prjs/github.com/TheTrueAI/influxdb3-python/venv/lib/python3.12/site-packages/influxdb_client_3/cli.py", line 184, in main
    return args.func(args, sys.stdout, sys.stderr)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/karl/bonitoo/prjs/github.com/TheTrueAI/influxdb3-python/venv/lib/python3.12/site-packages/influxdb_client_3/cli.py", line 169, in _run_query
    payload = _ensure_trailing_nl(_format_table(table, args.output_format))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/karl/bonitoo/prjs/github.com/TheTrueAI/influxdb3-python/venv/lib/python3.12/site-packages/influxdb_client_3/cli.py", line 85, in _format_table
    rows = table.to_pylist()
           ^^^^^^^^^^^^^^^^^
  File "pyarrow/table.pxi", line 2337, in pyarrow.lib._Tabular.to_pylist
  File "pyarrow/table.pxi", line 2300, in pyarrow.lib._Tabular.to_pydict
  File "pyarrow/table.pxi", line 1384, in pyarrow.lib.ChunkedArray.to_pylist
  File "pyarrow/array.pxi", line 1847, in pyarrow.lib.Array.to_pylist
  File "pyarrow/scalar.pxi", line 829, in pyarrow.lib.TimestampScalar.as_py
  File "pyarrow/scalar.pxi", line 719, in pyarrow.lib._datetime_from_int
ValueError: Nanosecond resolution temporal type 1777981256454646723 is not safely convertible to microseconds to convert to datetime.datetime. Install pandas to return as Timestamp with nanosecond support or access the .value attribute.

Pandas is not distributed with the Influxdb3-python client and needs to be installed separately. I've already made a mention of this in a documentation update merged today. It might be worth repeating as a reminder in the CLI section of README.md to help first time users avoid unpleasant surprises.

I have a small question regarding the environment variable overrides for the CLI client, which might be shorter to be more memorable.

Comment thread influxdb_client_3/cli.py
TheTrueAI added 3 commits May 5, 2026 19:36
Add a new query CLI to support quick read/debug workflows from terminal and AI agents.
- add influx3 query with json, jsonl, csv, and pretty output
- add module execution path via python -m influxdb_client_3
- wire console entry point in setup
- add CLI tests
ns timestamps are now truncated to µs.
This enables querying DBs with ns precision.
If ns precision is needed as output,
the direct Python client is the better option.

Co-authored-by: Copilot <copilot@github.com>
@TheTrueAI
Copy link
Copy Markdown
Contributor Author

TheTrueAI commented May 5, 2026

Hi @TheTrueAI,

Thank you for this contribution. It looks very complete.

While testing it out I ran into a minor problem when querying data with nanosecond time precision. PyArrow needs pandas installed in order for this to work.

$ influx3 query "SELECT * FROM testnanosec"
Traceback (most recent call last):
  File "/home/karl/bonitoo/prjs/github.com/TheTrueAI/influxdb3-python/venv/bin/influx3", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/karl/bonitoo/prjs/github.com/TheTrueAI/influxdb3-python/venv/lib/python3.12/site-packages/influxdb_client_3/cli.py", line 184, in main
    return args.func(args, sys.stdout, sys.stderr)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/karl/bonitoo/prjs/github.com/TheTrueAI/influxdb3-python/venv/lib/python3.12/site-packages/influxdb_client_3/cli.py", line 169, in _run_query
    payload = _ensure_trailing_nl(_format_table(table, args.output_format))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/karl/bonitoo/prjs/github.com/TheTrueAI/influxdb3-python/venv/lib/python3.12/site-packages/influxdb_client_3/cli.py", line 85, in _format_table
    rows = table.to_pylist()
           ^^^^^^^^^^^^^^^^^
  File "pyarrow/table.pxi", line 2337, in pyarrow.lib._Tabular.to_pylist
  File "pyarrow/table.pxi", line 2300, in pyarrow.lib._Tabular.to_pydict
  File "pyarrow/table.pxi", line 1384, in pyarrow.lib.ChunkedArray.to_pylist
  File "pyarrow/array.pxi", line 1847, in pyarrow.lib.Array.to_pylist
  File "pyarrow/scalar.pxi", line 829, in pyarrow.lib.TimestampScalar.as_py
  File "pyarrow/scalar.pxi", line 719, in pyarrow.lib._datetime_from_int
ValueError: Nanosecond resolution temporal type 1777981256454646723 is not safely convertible to microseconds to convert to datetime.datetime. Install pandas to return as Timestamp with nanosecond support or access the .value attribute.

Pandas is not distributed with the Influxdb3-python client and needs to be installed separately. I've already made a mention of this in a documentation update merged today. It might be worth repeating as a reminder in the CLI section of README.md to help first time users avoid unpleasant surprises.

I have a small question regarding the environment variable overrides for the CLI client, which might be shorter to be more memorable.

Good find! Now I added a commit, that should fix that problem. Please try again

@TheTrueAI TheTrueAI requested a review from karel-rehor May 5, 2026 18:30
Copy link
Copy Markdown
Contributor

@karel-rehor karel-rehor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheTrueAI

Thank you for this contribution.

Looks good to me. 🚴 🏁

@karel-rehor karel-rehor merged commit f8a0805 into InfluxCommunity:main May 6, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants