httpx-qs 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of httpx-qs might be problematic. Click here for more details.
- httpx_qs-0.1.2/CHANGELOG.md +11 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/PKG-INFO +2 -1
- httpx_qs-0.1.2/docs/README.rst +139 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/pyproject.toml +1 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/src/httpx_qs/__init__.py +1 -1
- httpx_qs-0.1.1/CHANGELOG.md +0 -7
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/.gitignore +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/CODE-OF-CONDUCT.md +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/LICENSE +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/README.rst +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/requirements_dev.txt +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/src/httpx_qs/enums/merge_policy.py +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/src/httpx_qs/py.typed +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/src/httpx_qs/transporters/smart_query_strings.py +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/src/httpx_qs/utils/merge_query.py +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/tests/unit/test_merge_query.py +0 -0
- {httpx_qs-0.1.1 → httpx_qs-0.1.2}/tests/unit/test_transport.py +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: httpx-qs
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: HTTPX transport leveraging qs-codec for advanced query string encoding and decoding.
|
|
5
5
|
Project-URL: Homepage, https://techouse.github.io/httpx_qs/
|
|
6
|
+
Project-URL: Documentation, https://techouse.github.io/httpx_qs/
|
|
6
7
|
Project-URL: Repository, https://github.com/techouse/httpx_qs.git
|
|
7
8
|
Project-URL: Issues, https://github.com/techouse/httpx_qs/issues
|
|
8
9
|
Project-URL: Changelog, https://github.com/techouse/httpx_qs/blob/master/CHANGELOG.md
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Using Merge Policies
|
|
2
|
+
--------------------
|
|
3
|
+
|
|
4
|
+
Conflict resolution when a key already exists is controlled by ``MergePolicy``.
|
|
5
|
+
|
|
6
|
+
Available policies:
|
|
7
|
+
|
|
8
|
+
* ``combine`` (default): concatenate values → existing first, new afterward (``a=1&a=2``)
|
|
9
|
+
* ``replace``: last-wins, existing value is overwritten (``a=2``)
|
|
10
|
+
* ``keep``: first-wins, ignore the new value (``a=1``)
|
|
11
|
+
* ``error``: raise ``ValueError`` on duplicate key
|
|
12
|
+
|
|
13
|
+
Specify per request:
|
|
14
|
+
|
|
15
|
+
.. code-block:: python
|
|
16
|
+
|
|
17
|
+
from httpx_qs import MergePolicy
|
|
18
|
+
|
|
19
|
+
r = client.get(
|
|
20
|
+
"https://api.example.com/resources",
|
|
21
|
+
params={"dup": "original"},
|
|
22
|
+
extensions={
|
|
23
|
+
"extra_query_params": {"dup": "override"},
|
|
24
|
+
"extra_query_params_policy": MergePolicy.REPLACE,
|
|
25
|
+
},
|
|
26
|
+
)
|
|
27
|
+
# Query contains only dup=override
|
|
28
|
+
|
|
29
|
+
Async Usage
|
|
30
|
+
-----------
|
|
31
|
+
|
|
32
|
+
``SmartQueryStrings`` works equally for ``AsyncClient``:
|
|
33
|
+
|
|
34
|
+
.. code-block:: python
|
|
35
|
+
|
|
36
|
+
import httpx
|
|
37
|
+
from httpx_qs.transporters.smart_query_strings import SmartQueryStrings
|
|
38
|
+
|
|
39
|
+
async def main() -> None:
|
|
40
|
+
async with httpx.AsyncClient(transport=SmartQueryStrings(httpx.AsyncHTTPTransport())) as client:
|
|
41
|
+
r = await client.get(
|
|
42
|
+
"https://example.com/items",
|
|
43
|
+
params={"filters": "active"},
|
|
44
|
+
extensions={"extra_query_params": {"page": 2}},
|
|
45
|
+
)
|
|
46
|
+
print(r.request.url)
|
|
47
|
+
|
|
48
|
+
# Run with: asyncio.run(main())
|
|
49
|
+
|
|
50
|
+
``merge_query`` Utility
|
|
51
|
+
-----------------------
|
|
52
|
+
|
|
53
|
+
You can use the underlying function directly:
|
|
54
|
+
|
|
55
|
+
.. code-block:: python
|
|
56
|
+
|
|
57
|
+
from httpx_qs import merge_query, MergePolicy
|
|
58
|
+
from qs_codec import EncodeOptions, ListFormat
|
|
59
|
+
|
|
60
|
+
new_url = merge_query(
|
|
61
|
+
"https://example.com?a=1",
|
|
62
|
+
{"a": 2, "tags": ["x", "y"]},
|
|
63
|
+
options=EncodeOptions(list_format=ListFormat.REPEAT),
|
|
64
|
+
policy=MergePolicy.COMBINE,
|
|
65
|
+
)
|
|
66
|
+
# → https://example.com/?a=1&a=2&tags=x&tags=y
|
|
67
|
+
|
|
68
|
+
Why ``ListFormat.REPEAT`` by Default?
|
|
69
|
+
-------------------------------------
|
|
70
|
+
|
|
71
|
+
``qs-codec`` exposes several list formatting strategies (e.g. repeat, brackets, indices). ``httpx-qs`` defaults to
|
|
72
|
+
``ListFormat.REPEAT`` because:
|
|
73
|
+
|
|
74
|
+
* It matches common server expectations (``key=value&key=value``) without requiring bracket parsing logic.
|
|
75
|
+
* It preserves original ordering while remaining unambiguous and simple for log inspection.
|
|
76
|
+
* Many API gateways / proxies / caches reliably forward repeated keys whereas bracket syntaxes can be normalized away.
|
|
77
|
+
|
|
78
|
+
If your API prefers another convention (e.g. ``tags[]=x&tags[]=y`` or ``tags[0]=x``) just pass a custom ``EncodeOptions`` via
|
|
79
|
+
``extensions['extra_query_params_options']`` or parameter ``options`` when calling ``merge_query`` directly.
|
|
80
|
+
|
|
81
|
+
Advanced Per-Request Customization
|
|
82
|
+
----------------------------------
|
|
83
|
+
|
|
84
|
+
.. code-block:: python
|
|
85
|
+
|
|
86
|
+
from qs_codec import EncodeOptions, ListFormat
|
|
87
|
+
|
|
88
|
+
r = client.get(
|
|
89
|
+
"https://service.local/search",
|
|
90
|
+
params={"q": "test"},
|
|
91
|
+
extensions={
|
|
92
|
+
"extra_query_params": {"debug": True, "tags": ["alpha", "beta"]},
|
|
93
|
+
"extra_query_params_policy": "combine", # also accepts string values
|
|
94
|
+
"extra_query_params_options": EncodeOptions(list_format=ListFormat.BRACKETS),
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
# Example: ?q=test&debug=true&tags[]=alpha&tags[]=beta
|
|
98
|
+
|
|
99
|
+
Error Policy Example
|
|
100
|
+
--------------------
|
|
101
|
+
|
|
102
|
+
.. code-block:: python
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
client.get(
|
|
106
|
+
"https://example.com",
|
|
107
|
+
params={"token": "abc"},
|
|
108
|
+
extensions={
|
|
109
|
+
"extra_query_params": {"token": "xyz"},
|
|
110
|
+
"extra_query_params_policy": "error",
|
|
111
|
+
},
|
|
112
|
+
)
|
|
113
|
+
except ValueError as exc:
|
|
114
|
+
print("Duplicate detected:", exc)
|
|
115
|
+
|
|
116
|
+
Testing Strategy
|
|
117
|
+
----------------
|
|
118
|
+
|
|
119
|
+
The project includes unit tests covering policy behaviors, error handling, and transport-level integration. Run them with:
|
|
120
|
+
|
|
121
|
+
.. code-block:: bash
|
|
122
|
+
|
|
123
|
+
pytest
|
|
124
|
+
|
|
125
|
+
Further Reading
|
|
126
|
+
---------------
|
|
127
|
+
|
|
128
|
+
* HTTPX documentation: https://www.python-httpx.org
|
|
129
|
+
* qs-codec documentation: https://techouse.github.io/qs_codec/
|
|
130
|
+
|
|
131
|
+
License
|
|
132
|
+
-------
|
|
133
|
+
|
|
134
|
+
BSD-3-Clause. See ``LICENSE`` for details.
|
|
135
|
+
|
|
136
|
+
Contributing
|
|
137
|
+
------------
|
|
138
|
+
|
|
139
|
+
Issues & PRs welcome. Please add tests for new behavior and keep doc examples in sync.
|
|
@@ -44,6 +44,7 @@ dynamic = ["version"]
|
|
|
44
44
|
|
|
45
45
|
[project.urls]
|
|
46
46
|
Homepage = "https://techouse.github.io/httpx_qs/"
|
|
47
|
+
Documentation = "https://techouse.github.io/httpx_qs/"
|
|
47
48
|
Repository = "https://github.com/techouse/httpx_qs.git"
|
|
48
49
|
Issues = "https://github.com/techouse/httpx_qs/issues"
|
|
49
50
|
Changelog = "https://github.com/techouse/httpx_qs/blob/master/CHANGELOG.md"
|
httpx_qs-0.1.1/CHANGELOG.md
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|