Replies: 1 comment 7 replies
-
|
Thanks. Appreciate the work, though wouldn't want this built in. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Background: Complex Query Parameters in HTTP APIs
HTTPX handles basic query parameters well (flat key–value pairs and simple lists). However, many web APIs (e.g., headless CMSs, search endpoints) use nested or structured query parameters to express filters, arrays, or deep object structures. In the Node.js ecosystem, the widely used
qslibrary enables this with bracket and dot notation (foo[bar]=baz,a.b=c) and is commonly used by frameworks such as Express.Current situation: HTTPX does not natively expand nested dictionaries into bracket/dot notation and only supports simple lists by repeating a key. More complex structures require manual encoding. This makes interacting with APIs that expect
qs-style query strings tedious and error-prone.What is
qs_codec?qs_codecis a faithful Python port of Node’sqslibrary. It brings to Python the same semantics for encoding and decoding nested query strings:Features and Advantages of
qs_codec'foo[bar][baz]=qux'⇄{'foo': {'bar': {'baz': 'qux'}}}.arr[0]=x&arr[1]=y), brackets (arr[]=x&arr[]=y), repeated keys (arr=x&arr=y), comma-separated (arr=x,y) with optional comma round-trip on decode.a.b=c⇄{'a': {'b': 'c'}}, with options to encode literal dots when needed.utf8=✓) to auto-detect encodings.encoder/decoder, sorting and filtering, control over percent-encoding (keys-only, values-only), alternate delimiters (string orre.Pattern), ignore leading?.strict_null_handling,skip_nulls, and support for empty lists.serialize_datefor ISO 8601 or custom (e.g., UNIX timestamp).combine/first/last).Usage Example:
qs_codecin Practice (Strapi Client + HTTPX)The Python package
strapi-clientuses HTTPX and employsqs_codecto serialize complex, nested queries compatible with Strapi (which commonly expectsqs-style parameters). See the implementation in their repo:api_parameters.py#L62.A simplified example of how developers can pair HTTPX with
qs_codectoday:Decoding is equally straightforward (e.g., when inspecting or transforming an incoming query string):
Proposal: Integrate or Recommend
qs_codecin HTTPXTwo possible directions:
Native integration (optional/flagged): HTTPX could delegate nested query encoding to
qs_codecwhen a nested structure is detected or when a specific flag is set (e.g.,params_style="qs"). Becauseqs_codechas zero external dependencies and comprehensive tests, this would bring robustqs-style semantics directly into HTTPX.Documentation recommendation: If integration is out of scope, the HTTPX docs could recommend
qs_codecfor advanced/nested query parameters. HTTPX already accepts a prebuilt query string (e.g.,client.get(url, params="a[b]=c&d[0]=e")), so pointing users toqs_codecprovides a clear, supported path without changing core behavior.Why this benefits HTTPX users
qs).Links
qs_codec(Python): https://github.com/techouse/qs_codecqs: https://www.npmjs.com/package/qsstrapi-clienton PyPI: https://pypi.org/project/strapi-client/strapi-client: https://github.com/Roslovets-Inc/strapi-client/blob/5bebcdad131c134fe47faca9b6e02eba0b100df1/src/strapi_client/models/api_parameters.py#L62Beta Was this translation helpful? Give feedback.
All reactions