Skip to content

[python] add supportHttpxSync option for sync httpx methods#24128

Merged
wing328 merged 6 commits into
masterfrom
LeComptoirDesPharmacies-feature/23032
Jun 25, 2026
Merged

[python] add supportHttpxSync option for sync httpx methods#24128
wing328 merged 6 commits into
masterfrom
LeComptoirDesPharmacies-feature/23032

Conversation

@wing328

@wing328 wing328 commented Jun 25, 2026

Copy link
Copy Markdown
Member

based on #23032 with updated samples, workflows, test files

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Adds synchronous method generation for Python httpx via a new supportHttpxSync option, creating _sync variants that call their async counterparts and block on a shared background event loop.

  • New Features
    • Generate _sync, _sync_with_http_info, _sync_without_preload_content for httpx only; ignored with a warning for other libraries.
    • New httpx/sync_helper.mustache with run_sync() using a dedicated, reused loop so httpx.AsyncClient stays on one loop.
    • Updated templates (api.mustache, api_doc.mustache, api_test.mustache) and docs; added petstore python-httpx-sync sample, copied tests, and updated CI to run samples/openapi3/client/petstore/python-httpx-sync.

Written for commit a436bdd. Summary will update on new commits.

Review in cubic

Add a new `supportHttpxSync` option to the Python generator (httpx library only) that generates synchronous `_sync` variants of each API method inside the same API class, instead of a separate `httpx-sync` library.

Following the maintainer's review feedback on #23044, each generated `_sync` method simply calls its asynchronous counterpart and waits for completion, so both synchronous and asynchronous methods are available from the same SDK (matching the sync/async layout already used by other generators).

- PythonClientCodegen: new `supportHttpxSync` CLI option, wired for the httpx library only (ignored with a warning otherwise)
- httpx/sync_helper.mustache: `run_sync()` helper running coroutines to completion on a dedicated, reused background event loop so the httpx AsyncClient stays bound to a single loop across calls
- api.mustache: generate `_sync`, `_sync_with_http_info` and `_sync_without_preload_content` variants under `{{#supportHttpxSync}}`
- api_doc / api_test: document and stub the sync variants
- new sample petstore python-httpx-sync (bin/configs/python-httpx-sync.yaml)
- docs/generators/python.md regenerated
Fix FILES
@wing328 wing328 changed the title Le comptoir des pharmacies feature/23032 [python] add supportHttpxSync option for sync httpx methods Jun 25, 2026
@wing328 wing328 added this to the 7.24.0 milestone Jun 25, 2026
@wing328 wing328 marked this pull request as ready for review June 25, 2026 11:10
@wing328 wing328 merged commit 5165243 into master Jun 25, 2026
42 checks passed
@wing328 wing328 deleted the LeComptoirDesPharmacies-feature/23032 branch June 25, 2026 11:10

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

16 issues found across 406 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/AllOfWithSingleRef.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/AllOfWithSingleRef.md:21">
P1: Example code calls `AllOfWithSingleRef.to_json()` as a class/static method, but `to_json` is an instance method. This raises TypeError at runtime.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/CreatureInfo.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/CreatureInfo.md:20">
P1: Documentation example calls `CreatureInfo.to_json()` as a class method, but `to_json()` is an instance method. This would raise a TypeError at runtime.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/Cat.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/Cat.md:20">
P1: Example code calls `Cat.to_json()` (class-method style) but `to_json()` is an instance method — should be `cat_instance.to_json()` using the already-created instance.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/Creature.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/Creature.md:21">
P1: `Creature.to_json()` calls an instance method via the class — will raise TypeError. Should use `creature_instance.to_json()` instead.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/CircularReferenceModel.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/CircularReferenceModel.md:21">
P2: `CircularReferenceModel.to_json()` called as class method but `to_json()` is an instance method — should be `circular_reference_model_instance.to_json()`.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/Color.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/Color.md:20">
P1: `to_json()` is an instance method but called as a class method (`Color.to_json()`). Should be `color_instance.to_json()` as shown in the variable assignment above.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/AdditionalPropertiesAnyType.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/AdditionalPropertiesAnyType.md:20">
P1: Calling instance method `to_json()` on the class instead of the instance variable raises TypeError at runtime. Use `additional_properties_any_type_instance.to_json()`.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/CircularAllOfRef.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/CircularAllOfRef.md:21">
P1: Example code calls `to_json()` on the class instead of the instance. `to_json()` is an instance method; calling it as `CircularAllOfRef.to_json()` raises `TypeError: missing 1 required positional argument: 'self'`. Use `circular_all_of_ref_instance.to_json()` instead.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/ClassModel.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/ClassModel.md:21">
P1: `ClassModel.to_json()` calls an instance method on the class, missing the `self` argument. Will raise `TypeError` at runtime.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfArrayOfModel.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfArrayOfModel.md:20">
P1: Example code calls `ArrayOfArrayOfModel.to_json()` on the class, but `to_json()` is an instance method and will raise `TypeError: missing 1 required positional argument: 'self'`</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/Animal.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/Animal.md:21">
P1: Instance method `to_json()` called on class `Animal` instead of on the `animal_instance` variable created two lines above. This will raise a TypeError at runtime.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/BaseDiscriminator.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/BaseDiscriminator.md:20">
P1: `BaseDiscriminator.to_json()` calls instance method `to_json(self)` on the class. Should be `base_discriminator_instance.to_json()` using the instance created above.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfArrayOfNumberOnly.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfArrayOfNumberOnly.md:20">
P2: Example code calls `ArrayOfArrayOfNumberOnly.to_json()` as a class method, but `to_json` is an instance method — will raise TypeError at runtime.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/Bathing.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/Bathing.md:22">
P0: Call `Bathing.to_json()` on the class but `to_json` is an instance method. This will raise `TypeError: Bathing.to_json() missing 1 required positional argument: 'self'` at runtime.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfNumberOnly.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfNumberOnly.md:20">
P1: Calls `ArrayOfNumberOnly.to_json()` on the class, but `to_json()` is an instance method. At runtime this raises TypeError: missing 1 required positional argument 'self'. Should use the instance `array_of_number_only_instance` instead.</violation>
</file>

<file name="samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfMapModel.md">

<violation number="1" location="samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfMapModel.md:20">
P2: `ArrayOfMapModel.to_json()` calls an instance method on the class, not an instance. `to_json(self)` expects `self`, so this raises `TypeError: ArrayOfMapModel.to_json() missing 1 required positional argument: 'self'` at runtime.</violation>
</file>

Note: This PR contains a large number of files. cubic only reviews up to 40 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.

Re-trigger cubic

# create an instance of Bathing from a JSON string
bathing_instance = Bathing.from_json(json)
# print the JSON string representation of the object
print(Bathing.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P0: Call Bathing.to_json() on the class but to_json is an instance method. This will raise TypeError: Bathing.to_json() missing 1 required positional argument: 'self' at runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/Bathing.md, line 22:

<comment>Call `Bathing.to_json()` on the class but `to_json` is an instance method. This will raise `TypeError: Bathing.to_json() missing 1 required positional argument: 'self'` at runtime.</comment>

<file context>
@@ -0,0 +1,31 @@
+# create an instance of Bathing from a JSON string
+bathing_instance = Bathing.from_json(json)
+# print the JSON string representation of the object
+print(Bathing.to_json())
+
+# convert the object into a dict
</file context>

# create an instance of AllOfWithSingleRef from a JSON string
all_of_with_single_ref_instance = AllOfWithSingleRef.from_json(json)
# print the JSON string representation of the object
print(AllOfWithSingleRef.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Example code calls AllOfWithSingleRef.to_json() as a class/static method, but to_json is an instance method. This raises TypeError at runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/AllOfWithSingleRef.md, line 21:

<comment>Example code calls `AllOfWithSingleRef.to_json()` as a class/static method, but `to_json` is an instance method. This raises TypeError at runtime.</comment>

<file context>
@@ -0,0 +1,30 @@
+# create an instance of AllOfWithSingleRef from a JSON string
+all_of_with_single_ref_instance = AllOfWithSingleRef.from_json(json)
+# print the JSON string representation of the object
+print(AllOfWithSingleRef.to_json())
+
+# convert the object into a dict
</file context>

# create an instance of CreatureInfo from a JSON string
creature_info_instance = CreatureInfo.from_json(json)
# print the JSON string representation of the object
print(CreatureInfo.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Documentation example calls CreatureInfo.to_json() as a class method, but to_json() is an instance method. This would raise a TypeError at runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/CreatureInfo.md, line 20:

<comment>Documentation example calls `CreatureInfo.to_json()` as a class method, but `to_json()` is an instance method. This would raise a TypeError at runtime.</comment>

<file context>
@@ -0,0 +1,29 @@
+# create an instance of CreatureInfo from a JSON string
+creature_info_instance = CreatureInfo.from_json(json)
+# print the JSON string representation of the object
+print(CreatureInfo.to_json())
+
+# convert the object into a dict
</file context>

# create an instance of Cat from a JSON string
cat_instance = Cat.from_json(json)
# print the JSON string representation of the object
print(Cat.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Example code calls Cat.to_json() (class-method style) but to_json() is an instance method — should be cat_instance.to_json() using the already-created instance.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/Cat.md, line 20:

<comment>Example code calls `Cat.to_json()` (class-method style) but `to_json()` is an instance method — should be `cat_instance.to_json()` using the already-created instance.</comment>

<file context>
@@ -0,0 +1,29 @@
+# create an instance of Cat from a JSON string
+cat_instance = Cat.from_json(json)
+# print the JSON string representation of the object
+print(Cat.to_json())
+
+# convert the object into a dict
</file context>
Suggested change
print(Cat.to_json())
print(cat_instance.to_json())

# create an instance of Creature from a JSON string
creature_instance = Creature.from_json(json)
# print the JSON string representation of the object
print(Creature.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Creature.to_json() calls an instance method via the class — will raise TypeError. Should use creature_instance.to_json() instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/Creature.md, line 21:

<comment>`Creature.to_json()` calls an instance method via the class — will raise TypeError. Should use `creature_instance.to_json()` instead.</comment>

<file context>
@@ -0,0 +1,30 @@
+# create an instance of Creature from a JSON string
+creature_instance = Creature.from_json(json)
+# print the JSON string representation of the object
+print(Creature.to_json())
+
+# convert the object into a dict
</file context>
Suggested change
print(Creature.to_json())
print(creature_instance.to_json())

# create an instance of BaseDiscriminator from a JSON string
base_discriminator_instance = BaseDiscriminator.from_json(json)
# print the JSON string representation of the object
print(BaseDiscriminator.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: BaseDiscriminator.to_json() calls instance method to_json(self) on the class. Should be base_discriminator_instance.to_json() using the instance created above.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/BaseDiscriminator.md, line 20:

<comment>`BaseDiscriminator.to_json()` calls instance method `to_json(self)` on the class. Should be `base_discriminator_instance.to_json()` using the instance created above.</comment>

<file context>
@@ -0,0 +1,29 @@
+# create an instance of BaseDiscriminator from a JSON string
+base_discriminator_instance = BaseDiscriminator.from_json(json)
+# print the JSON string representation of the object
+print(BaseDiscriminator.to_json())
+
+# convert the object into a dict
</file context>
Suggested change
print(BaseDiscriminator.to_json())
print(base_discriminator_instance.to_json())

# create an instance of ArrayOfNumberOnly from a JSON string
array_of_number_only_instance = ArrayOfNumberOnly.from_json(json)
# print the JSON string representation of the object
print(ArrayOfNumberOnly.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Calls ArrayOfNumberOnly.to_json() on the class, but to_json() is an instance method. At runtime this raises TypeError: missing 1 required positional argument 'self'. Should use the instance array_of_number_only_instance instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfNumberOnly.md, line 20:

<comment>Calls `ArrayOfNumberOnly.to_json()` on the class, but `to_json()` is an instance method. At runtime this raises TypeError: missing 1 required positional argument 'self'. Should use the instance `array_of_number_only_instance` instead.</comment>

<file context>
@@ -0,0 +1,29 @@
+# create an instance of ArrayOfNumberOnly from a JSON string
+array_of_number_only_instance = ArrayOfNumberOnly.from_json(json)
+# print the JSON string representation of the object
+print(ArrayOfNumberOnly.to_json())
+
+# convert the object into a dict
</file context>
Suggested change
print(ArrayOfNumberOnly.to_json())
print(array_of_number_only_instance.to_json())

# create an instance of CircularReferenceModel from a JSON string
circular_reference_model_instance = CircularReferenceModel.from_json(json)
# print the JSON string representation of the object
print(CircularReferenceModel.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: CircularReferenceModel.to_json() called as class method but to_json() is an instance method — should be circular_reference_model_instance.to_json().

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/CircularReferenceModel.md, line 21:

<comment>`CircularReferenceModel.to_json()` called as class method but `to_json()` is an instance method — should be `circular_reference_model_instance.to_json()`.</comment>

<file context>
@@ -0,0 +1,30 @@
+# create an instance of CircularReferenceModel from a JSON string
+circular_reference_model_instance = CircularReferenceModel.from_json(json)
+# print the JSON string representation of the object
+print(CircularReferenceModel.to_json())
+
+# convert the object into a dict
</file context>
Suggested change
print(CircularReferenceModel.to_json())
print(circular_reference_model_instance.to_json())

# create an instance of ArrayOfArrayOfNumberOnly from a JSON string
array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.from_json(json)
# print the JSON string representation of the object
print(ArrayOfArrayOfNumberOnly.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Example code calls ArrayOfArrayOfNumberOnly.to_json() as a class method, but to_json is an instance method — will raise TypeError at runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfArrayOfNumberOnly.md, line 20:

<comment>Example code calls `ArrayOfArrayOfNumberOnly.to_json()` as a class method, but `to_json` is an instance method — will raise TypeError at runtime.</comment>

<file context>
@@ -0,0 +1,29 @@
+# create an instance of ArrayOfArrayOfNumberOnly from a JSON string
+array_of_array_of_number_only_instance = ArrayOfArrayOfNumberOnly.from_json(json)
+# print the JSON string representation of the object
+print(ArrayOfArrayOfNumberOnly.to_json())
+
+# convert the object into a dict
</file context>

# create an instance of ArrayOfMapModel from a JSON string
array_of_map_model_instance = ArrayOfMapModel.from_json(json)
# print the JSON string representation of the object
print(ArrayOfMapModel.to_json())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: ArrayOfMapModel.to_json() calls an instance method on the class, not an instance. to_json(self) expects self, so this raises TypeError: ArrayOfMapModel.to_json() missing 1 required positional argument: 'self' at runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-httpx-sync/docs/ArrayOfMapModel.md, line 20:

<comment>`ArrayOfMapModel.to_json()` calls an instance method on the class, not an instance. `to_json(self)` expects `self`, so this raises `TypeError: ArrayOfMapModel.to_json() missing 1 required positional argument: 'self'` at runtime.</comment>

<file context>
@@ -0,0 +1,29 @@
+# create an instance of ArrayOfMapModel from a JSON string
+array_of_map_model_instance = ArrayOfMapModel.from_json(json)
+# print the JSON string representation of the object
+print(ArrayOfMapModel.to_json())
+
+# convert the object into a dict
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants