Skip to content

fix: support ipv6 hosts #132

New issue

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 0.13.0 [unreleased]

### Bug Fixes

1. [#132](https://github.com/InfluxCommunity/influxdb3-python/pull/132): Fixes support for IPv6 addresses in the `host` parameter of the client. The client now correctly handles IPv6 addresses by enclosing them in square brackets.

## 0.12.0 [2025-03-26]

Expand Down
8 changes: 8 additions & 0 deletions influxdb_client_3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
PointSettings
from influxdb_client_3.write_client.domain.write_precision import WritePrecision

from ipaddress import IPv6Address, AddressValueError

polars = importlib.util.find_spec("polars") is not None


Expand Down Expand Up @@ -147,6 +149,12 @@ def __init__(
hostname = parsed_url.hostname if parsed_url.hostname else host
port = parsed_url.port if parsed_url.port else 443

try:
IPv6Address(hostname)
hostname = f"[{hostname}]"
except AddressValueError:
pass

# Construct the clients using the parsed values
if write_port_overwrite is not None:
port = write_port_overwrite
Expand Down
23 changes: 23 additions & 0 deletions tests/test_influxdb_client_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,29 @@ async def test_query_async(self):
assert {'data': 'sql_query', 'reference': query, 'value': -1.0} in result_list
assert {'data': 'query_type', 'reference': 'sql', 'value': -1.0} in result_list

@asyncio_run
async def test_query_async_ipv6(self):
with ConstantFlightServer() as server:
client = InfluxDBClient3(
host=f"http://[::1]:{server.port}",
org="my_org",
database="my_db",
token="my_token",
)

query = "SELECT * FROM my_data"

table = await client.query_async(query=query, language="sql")

result_list = table.to_pylist()

cd = ConstantData()
for item in cd.to_list():
assert item in result_list

assert {'data': 'database', 'reference': 'my_db', 'value': -1.0} in result_list
assert {'data': 'sql_query', 'reference': query, 'value': -1.0} in result_list
assert {'data': 'query_type', 'reference': 'sql', 'value': -1.0} in result_list

if __name__ == '__main__':
unittest.main()