tomchristie: Later follow ups:

* Allow `typing.Union[PrimitiveData, typing.List[PrimitiveData]]` for eg. `{a: [1, 2, 3]}` => `a=1&a=2&a=3`
* Use same style for urlencoded and multipart data.
diff --git a/httpx/__init__.py b/httpx/__init__.py
index 8de5276..fd17441 100644
--- a/httpx/__init__.py
+++ b/httpx/__init__.py
@@ -34,6 +34,8 @@ from .interfaces import (
     AsyncDispatcher,
     BaseReader,
     BaseWriter,
+    BaseBackgroundManager,
+    BasePoolSemaphore,
     ConcurrencyBackend,
     Dispatcher,
     Protocol,
diff --git a/httpx/models.py b/httpx/models.py
index f98447c..df5d071 100644
--- a/httpx/models.py
+++ b/httpx/models.py
@@ -34,14 +34,17 @@ from .utils import (
     is_known_encoding,
     normalize_header_key,
     normalize_header_value,
+    str_query_param
 )
 
+PrimitiveData = typing.Union[str, int, float, bool, type(None)]
+
 URLTypes = typing.Union["URL", str]
 
 QueryParamTypes = typing.Union[
     "QueryParams",
-    typing.Mapping[str, str],
-    typing.List[typing.Tuple[typing.Any, typing.Any]],
+    typing.Mapping[str, PrimitiveData],
+    typing.List[typing.Tuple[str, PrimitiveData]],
     str,
 ]
 
@@ -268,8 +271,8 @@ class QueryParams(typing.Mapping[str, str]):
         else:
             items = value.items()  # type: ignore
 
-        self._list = [(str(k), str(v)) for k, v in items]
-        self._dict = {str(k): str(v) for k, v in items}
+        self._list = [(str(k), str_query_param(v)) for k, v in items]
+        self._dict = {str(k): str_query_param(v) for k, v in items}
 
     def getlist(self, key: typing.Any) -> typing.List[str]:
         return [item_value for item_key, item_value in self._list if item_key == key]
diff --git a/httpx/utils.py b/httpx/utils.py
index 3d0d660..e96335f 100644
--- a/httpx/utils.py
+++ b/httpx/utils.py
@@ -20,6 +20,21 @@ def normalize_header_value(value: typing.AnyStr, encoding: str = None) -> bytes:
     return value.encode(encoding or "ascii")
 
 
+def str_query_param(value: typing.Union[str, int, float, bool, type(None)]) -> str:
+    """
+    Coerce a primitive data type into a string value for query params.
+
+    Note that we prefer JSON-style 'true'/'false' for boolean values here.
+    """
+    if value is True:
+        return "true"
+    elif value is False:
+        return "false"
+    elif value is None:
+        return ""
+    return str(value)
+
+
 def is_known_encoding(encoding: str) -> bool:
     """
     Return `True` if `encoding` is a known codec.

Change QueryParams(key=None) to not emit a parameter
This one I know is [`requests` behaviour](https://github.com/psf/requests/blob/9a2e5df000691ad28613524ca7f80aa28a94a8d5/requests/models.py#L101):

Take a dict:
```py
>>> from httpx import QueryParams
>>> params = {"thing_one": 1, "thing_two": [1,2,3], "thing_three": None}
>>> QueryParams(params)
QueryParams('thing_one=1&thing_two=%5B1%2C+2%2C+3%5D&thing_three=None')
```
Expected:
```py
QueryParams('thing_one=1&thing_two=%5B1%2C+2%2C+3%5D')
```
Adding `if v is not None` [here](https://github.com/encode/httpx/blob/master/httpx/models.py#L263-L264) will do it.
diff --git a/tests/models/test_queryparams.py b/tests/models/test_queryparams.py
index 983b09f..fbb559f 100644
--- a/tests/models/test_queryparams.py
+++ b/tests/models/test_queryparams.py
@@ -31,3 +31,23 @@ def test_queryparams():
 
     q = QueryParams([("a", "123"), ("a", "456")])
     assert QueryParams(q) == q
+
+
+def test_queryparam_types():
+    q = QueryParams({"a": True})
+    assert str(q) == "a=true"
+
+    q = QueryParams({"a": False})
+    assert str(q) == "a=false"
+
+    q = QueryParams({"a": ""})
+    assert str(q) == "a="
+
+    q = QueryParams({"a": None})
+    assert str(q) == "a="
+
+    q = QueryParams({"a": 1.23})
+    assert str(q) == "a=1.23"
+
+    q = QueryParams({"a": 123})
+    assert str(q) == "a=123"

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-asyncio pytest-cov
apt-get update apt-get install -y gcc
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==24.2.0
autoflake==2.1.1
Babel==2.14.0
black==23.3.0
brotlipy==0.7.0
cached-property==1.5.2
certifi @ file:///croot/certifi_1671487769961/work/certifi
cffi==1.15.1
chardet==3.0.4
charset-normalizer==3.4.1
click==8.1.8
colorama==0.4.6
coverage==7.2.7
cryptography==44.0.2
exceptiongroup==1.2.2
flake8==2.3.0
flake8-bugbear==16.7.0
flake8-comprehensions==2.3.0
ghp-import==2.1.0
h11==0.8.1
h2==3.2.0
hpack==3.0.0
hstspreload==2025.1.1
-e git+https://github.com/encode/httpx.git@db6731a3d2dc882fc9bd9b9791544a2fba2cb559#egg=httpx
hyperframe==5.2.0
idna==2.10
importlib-metadata==6.7.0
iniconfig==2.0.0
isort==5.11.5
Jinja2==3.1.6
Markdown==3.4.4
MarkupSafe==2.1.5
mccabe==0.7.0
mergedeep==1.3.4
mkdocs==1.5.3
mkdocs-material==9.2.7
mkdocs-material-extensions==1.2
mypy==1.4.1
mypy-extensions==1.0.0
packaging==24.0
paginate==0.5.7
pathspec==0.11.2
pep8==1.7.1
platformdirs==4.0.0
pluggy==1.2.0
pycparser==2.21
pyflakes==3.0.1
Pygments==2.17.2
pymdown-extensions==10.2.1
pytest==7.4.4
pytest-asyncio==0.21.2
pytest-cov==4.1.0
python-dateutil==2.9.0.post0
pytz==2025.2
PyYAML==6.0.1
pyyaml_env_tag==0.1
regex==2022.10.31
requests==2.31.0
rfc3986==1.5.0
six==1.17.0
tomli==2.0.1
trustme==1.0.0
typed-ast==1.5.5
typing_extensions==4.7.1
urllib3==2.0.7
uvicorn==0.22.0
watchdog==3.0.0
zipp==3.15.0

name: httpx
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==24.2.0
      - autoflake==2.1.1
      - babel==2.14.0
      - black==23.3.0
      - brotlipy==0.7.0
      - cached-property==1.5.2
      - cffi==1.15.1
      - chardet==3.0.4
      - charset-normalizer==3.4.1
      - click==8.1.8
      - colorama==0.4.6
      - coverage==7.2.7
      - cryptography==44.0.2
      - exceptiongroup==1.2.2
      - flake8==2.3.0
      - flake8-bugbear==16.7.0
      - flake8-comprehensions==2.3.0
      - ghp-import==2.1.0
      - h11==0.8.1
      - h2==3.2.0
      - hpack==3.0.0
      - hstspreload==2025.1.1
      - hyperframe==5.2.0
      - idna==2.10
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - isort==5.11.5
      - jinja2==3.1.6
      - markdown==3.4.4
      - markupsafe==2.1.5
      - mccabe==0.7.0
      - mergedeep==1.3.4
      - mkdocs==1.5.3
      - mkdocs-material==9.2.7
      - mkdocs-material-extensions==1.2
      - mypy==1.4.1
      - mypy-extensions==1.0.0
      - packaging==24.0
      - paginate==0.5.7
      - pathspec==0.11.2
      - pep8==1.7.1
      - platformdirs==4.0.0
      - pluggy==1.2.0
      - pycparser==2.21
      - pyflakes==3.0.1
      - pygments==2.17.2
      - pymdown-extensions==10.2.1
      - pytest==7.4.4
      - pytest-asyncio==0.21.2
      - pytest-cov==4.1.0
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - pyyaml==6.0.1
      - pyyaml-env-tag==0.1
      - regex==2022.10.31
      - requests==2.31.0
      - rfc3986==1.5.0
      - six==1.17.0
      - tomli==2.0.1
      - trustme==1.0.0
      - typed-ast==1.5.5
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - uvicorn==0.22.0
      - watchdog==3.0.0
      - zipp==3.15.0
prefix: /opt/conda/envs/httpx

tests/models/test_queryparams.py::test_queryparam_types
tests/models/test_queryparams.py::test_queryparams
httpx/utils.py httpx/__init__.py httpx/models.py
httpx/utils.py httpx/__init__.py httpx/models.py