[Python] Add HTTPX2 client library support

Merged
BE
2mo ago
+101386-116

Adds httpx2 as a library option for the existing Python generator, allowing clients to use HTTPX2 without custom templates or manual changes after generation.

Closes #24965

Changes

  • Add --library httpx2, using httpx2.AsyncClient.
  • Support optional synchronous wrappers through supportHttpxSync=true.
  • Reuse the existing HTTPX transport templates.
  • Generate HTTPX2-specific packaging with PEP 621 metadata, PEP 735 development dependency groups, and PEP 639 license expressions.
  • Configure Hatchling and setuptools packaging, including py.typed.
  • Add asynchronous and synchronous Petstore samples, tests, documentation, and CI coverage.

Existing Python library defaults and packaging behavior remain unchanged.

Example

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
  -i openapi.yaml \
  -g python \
  --library httpx2 \
  --additional-properties=supportHttpxSync=true \
  -o ./client

Validation

Validated locally with Python 3.13 and HTTPX2 2.13.0:

  • Python generator tests: 72 passed.
  • HTTPX2 async sample: 214 passed, 2 skipped.
  • HTTPX2 sync sample: 277 passed, 2 skipped.
  • Both HTTPX2 samples passed mypy and Poetry installation.
  • Wheel and source distributions built with Hatchling and setuptools.
  • Wheels installed and imported successfully in clean environments.
  • Verified py.typed, runtime dependencies, and SPDX license metadata.
  • Confirmed generated output for HTTPX, urllib3, and asyncio remains unchanged.
  • Integration tests used a local Petstore server.
  • Python 3.10–3.14 coverage is configured in CI; only Python 3.13 was exercised locally.

Summary by cubic

Adds httpx2 as a built-in library option for the Python generator, closing #24965. --library httpx2 now generates a client using httpx2.AsyncClient without custom templates. Packaging for httpx2 is unified with the other Python libraries; non-httpx2 projects were regenerated with the new pyproject.toml and README format, which now uses PEP 621/735/639 metadata, SPDX licenses, and py.typed. Legacy poetry1=true keeps the deprecated [tool.poetry.dev-dependencies] and works for httpx2 as well.

New Features

  • supportHttpxSync=true adds blocking _sync variants alongside async methods for httpx and httpx2.
  • Projects use PEP 621/735/639 metadata, SPDX license expressions, and py.typed; legacy poetry1=true retains deprecated dev-dependencies and is supported for httpx2.
  • Supports Hatchling and setuptools builds.
  • Adds async and sync Petstore samples, generator tests, docs, and CI coverage.

Migration

  • Requires Python 3.10+ and httpx2>=2.13.0,<3.
  • Dev dependency groups require Poetry 2.2+ or pip 25.1+.