Skip to content

feat(python): add serverUrlVariables config flag to Python SDK generator#17119

Open
willkendall01 wants to merge 2 commits into
mainfrom
feat/python-server-url-variables-flag
Open

feat(python): add serverUrlVariables config flag to Python SDK generator#17119
willkendall01 wants to merge 2 commits into
mainfrom
feat/python-server-url-variables-flag

Conversation

@willkendall01

Copy link
Copy Markdown
Contributor

Summary

Adds a new serverUrlVariables custom config flag (boolean, defaults to true) to the Python v1 SDK generator (generators/python).

  • When true (default): behavior is unchanged. The generated client exposes server-URL-variable constructor kwargs (e.g. region: typing.Optional[str]) and performs runtime URL-template interpolation.
  • When false: the generator falls back to the pre-feature base-URL behavior, emitting neither the server-URL-variable constructor kwargs nor the URL-template interpolation.

Details

  • Config: new field server_url_variables: bool = True on SDKCustomConfig, mapped from the camelCase JSON key serverUrlVariables in parse_obj (mirroring the existing optional flags). Snake_case is also accepted directly.
  • Gate: the flag is consulted at the single narrowest point — RootClientGenerator._get_server_variables, which returns an empty list when the flag is disabled. Both the constructor-parameter loop and _write_url_template_interpolation key off this list, so suppressing it disables both behaviors.
  • Changelog: new 5.21.0 entry (minor bump) at the top of generators/python/sdk/versions.yml.
  • Tests: added config-parsing tests (default true, camelCase alias, snake_case, forbid-conflict) and generator gate tests covering both the enabled (variables surfaced) and disabled (variables suppressed) states.

Verification

  • python -m py_compile on all changed modules and test files: passed.
  • Full poetry install + pytest was not run in this environment (poetry unavailable; install too heavy to complete within time limits).

Generated with Claude Code

Add a `serverUrlVariables` custom config flag (boolean, defaults to true)
to the Python v1 SDK generator. When true (default), behavior is unchanged:
the generated client exposes server-URL-variable constructor kwargs and
performs runtime URL-template interpolation. When false, the generator falls
back to the pre-feature base-URL behavior, emitting neither the kwargs nor
the interpolation.

Co-Authored-By: Claude <noreply@anthropic.com>

@nitpickybot nitpickybot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI Review Summary

Adds a serverUrlVariables config flag to gate server-URL-variable generation. The gate implementation and config parsing look correct and mirror existing patterns. Main concern is the stub-based test being brittle and not exercising the enabled path through the real environments-config code.

  • 🔵 1 suggestion(s)

Comment on lines +80 to +84
def test_get_server_variables_default_surfaces_variables() -> None:
"""With server_url_variables enabled (default), server variables are surfaced."""
stub = _make_server_variables_generator_stub(server_url_variables=True)
variables = RootClientGenerator._get_server_variables(stub) # type: ignore[arg-type]
assert [var.id for var in variables] == ["region"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 suggestion

This test only validates that a SimpleNamespace stub with hand-rolled get_as_union returns the variable — it duplicates the internal shape of _get_server_variables rather than testing it against real IR types. If the method's parsing of environments_config changes, this test won't catch it because it mirrors the implementation. Consider using a real ir_types fixture, or at minimum note that this test is tightly coupled to the current internals.

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

SDK Generation Benchmark Results

Comparing PR branch against median of 5 nightly run(s) on main (latest: 2026-07-16T05:00:50Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
python-sdk square 138s (n=5) 239s (n=5) 129s -9s (-6.5%)

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).
Baseline from nightly runs on main (latest: 2026-07-16T05:00:50Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-07-17 04:57 UTC

Add a `disable-server-url-variables` seed fixture output (customConfig
`serverUrlVariables: false`) for both the `server-url-templating` and
`server-url-templating-single-url` fixtures, alongside the existing
default output. The default output keeps the server-URL-variable
constructor kwargs and runtime URL-template interpolation; the disabled
output omits both, exercising the pre-feature base-URL fallback.

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant