Skip to content

Refactor write HTTP stack: introduce internal _RestClient and bypass OpenAPI WriteService #216

@bednar

Description

@bednar

Background

influxdb3-python still uses a legacy OpenAPI-style HTTP stack for write requests:

  • WriteApi -> WriteService -> ApiClient -> RESTClientObject -> Configuration

This stack was inherited from the InfluxDB v2 client and is now heavier than needed for the InfluxDB 3 client. Sign-in/sign-out services have already been removed, but write requests still depend on the generated-style ApiClient and WriteService layers.

Goal

Introduce a small internal _RestClient for HTTP-based endpoints and route writes through it directly, while preserving the current public write API behavior.

Scope

  1. Add an internal _RestClient

Suggested location:

influxdb_client_3/write_client/_sync/rest_client.py

Responsibilities:

  • Build request URLs from base host, endpoint path, and query params.
  • Add default headers:
    • Authorization
    • User-Agent
  • Send HTTP requests using urllib3.
  • Support existing write HTTP options:
    • verify_ssl
    • ssl_ca_cert
    • cert_file
    • cert_key_file
    • cert_key_password
    • ssl_context
    • proxy
    • proxy_headers
    • connection_pool_maxsize
    • request timeout in milliseconds
    • gzip via enable_gzip and gzip_threshold
  • Raise the existing ApiException or compatible error type for non-2xx responses.
  1. Route write requests through _RestClient

Refactor WriteApi._post_write(...) so it no longer calls WriteService.post_write(...).

Preserve current endpoint behavior:

  • use_v2_api=True
    • endpoint: /api/v2/write
    • query params: org, bucket, precision
  • use_v2_api=False
    • endpoint: /api/v3/write_lp
    • query params: org, db, precision
    • optional: no_sync=true
    • optional: accept_partial=false

Preserve current validation:

  • use_v2_api=True with no_sync=True raises:
    • ValueError("invalid write options: no_sync cannot be used with use_v2_api")

Preserve current error translation:

  • 405 on /api/v2/write suggests use_v2_api=False
  • 405 on /api/v3/write_lp suggests use_v2_api=True
  • partial write responses are translated to InfluxDBPartialWriteError

Acceptance criteria

  • Write requests work through both /api/v2/write and /api/v3/write_lp.
  • accept_partial, no_sync, and use_v2_api keep their current behavior.
  • gzip, timeout, proxy, and TLS options still work.
  • Runtime write path no longer depends on WriteService, ApiClient, or RESTClientObject.
  • Existing high-level public APIs remain compatible:
    • InfluxDBClient3
    • WriteOptions
    • client.write(...)
    • client.flush()
    • client.close()
  • Tests that currently cover WriteService/ApiClient are replaced or updated to cover _RestClient and the new write path directly.

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions