Skip to content

Add server URL normalization for flexible server_url input#122

Merged
chris-freeman-glean merged 3 commits intomainfrom
cfreeman/server-url-normalization
Mar 4, 2026
Merged

Add server URL normalization for flexible server_url input#122
chris-freeman-glean merged 3 commits intomainfrom
cfreeman/server-url-normalization

Conversation

@chris-freeman-glean
Copy link
Contributor

Summary

Adds server URL normalization so users can pass schemeless URLs (e.g., "mycompany-be.glean.com") as server_url when constructing the SDK client. This is part of promoting server_url as the primary configuration option, replacing instance in all documentation and examples.

Python-specific implementation

Uses Speakeasy's SDKInit hook mechanism (src/glean/api_client/_hooks/server_url_normalizer.py). The hook receives the raw server URL string during SDK initialization and normalizes it before it's used for requests. This is the standard approach — the Python SDK passes raw strings to the SDKInit hook (unlike TypeScript which passes parsed URL objects).

The hook is registered in registration.py as the first hook to run during initialization.

Normalization rules

  • No scheme → prepend https://
  • http:// preserved (for localhost/dev)
  • https:// preserved
  • Trailing slashes stripped

User-facing API

# All of these now work identically:
glean = Glean(server_url="mycompany-be.glean.com")
glean = Glean(server_url="https://mycompany-be.glean.com")
glean = Glean(server_url="https://mycompany-be.glean.com/")

Backwards compatibility

The instance parameter continues to work unchanged. No breaking changes.

Test plan

  • 13 unit tests pass covering normalization logic and hook integration

Prepends https:// to server URLs when no scheme is provided and strips
trailing slashes, improving developer experience for SDK initialization.
@chris-freeman-glean chris-freeman-glean marked this pull request as ready for review March 3, 2026 22:38
@chris-freeman-glean chris-freeman-glean requested a review from a team as a code owner March 3, 2026 22:38
Replace all code examples and documentation to use server_url as the
primary configuration parameter. The instance parameter is preserved
for backwards compatibility but deprioritized in documentation.
@chris-freeman-glean chris-freeman-glean merged commit 6efbd21 into main Mar 4, 2026
3 checks passed
@chris-freeman-glean chris-freeman-glean deleted the cfreeman/server-url-normalization branch March 4, 2026 17:15
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