Skip to content

Commit 1f53f76

Browse files
release: 1.8.0 (#51)
* feat(api): api update * chore(tests): add tests for httpx client instantiation & proxies * chore(internal): update conftest.py * chore(ci): enable for pull requests * chore(readme): update badges * fix(tests): fix: tests which call HTTP endpoints directly with the example parameters * docs(client): fix httpx.Timeout documentation reference * feat(client): add support for aiohttp * release: 1.8.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
1 parent a6934b7 commit 1f53f76

34 files changed

+314
-56
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
- 'integrated/**'
88
- 'stl-preview-head/**'
99
- 'stl-preview-base/**'
10+
pull_request:
11+
branches-ignore:
12+
- 'stl-preview-head/**'
13+
- 'stl-preview-base/**'
1014

1115
jobs:
1216
lint:

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.7.1"
2+
".": "1.8.0"
33
}

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 89
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/knock%2Fknock-ba629bb393f43737dec9702d5610ac4b5696e58f58177d1d98f4f832c9553b76.yml
3-
openapi_spec_hash: abeac01a8a235ea114e466d4f06e70ad
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/knock%2Fknock-c15e6924891ae19a301d5e878d353bda7cf6aa486c13be9525fe9d4d06eb140f.yml
3+
openapi_spec_hash: 397a88d71e81d4339d41c151a61e12b9
44
config_hash: b4c547c1d4c8cd0834bc793ddf5388ee

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# Changelog
22

3+
## 1.8.0 (2025-06-21)
4+
5+
Full Changelog: [v1.7.1...v1.8.0](https://github.com/knocklabs/knock-python/compare/v1.7.1...v1.8.0)
6+
7+
### Features
8+
9+
* **api:** api update ([4f1b799](https://github.com/knocklabs/knock-python/commit/4f1b799dcdf50253c531f5c1c9b71c6feec3cd98))
10+
* **client:** add support for aiohttp ([43bd2be](https://github.com/knocklabs/knock-python/commit/43bd2beae3e2e969ab3af11b3a40b0e3ce58a9c1))
11+
12+
13+
### Bug Fixes
14+
15+
* **tests:** fix: tests which call HTTP endpoints directly with the example parameters ([beb242d](https://github.com/knocklabs/knock-python/commit/beb242d5a2280d777875f6b2481f2647ae9656b1))
16+
17+
18+
### Chores
19+
20+
* **ci:** enable for pull requests ([38cb0ce](https://github.com/knocklabs/knock-python/commit/38cb0ce8e86ff6fe1c676805bfb708ab37ed4319))
21+
* **internal:** update conftest.py ([5bcbc15](https://github.com/knocklabs/knock-python/commit/5bcbc15a618a92a5b4bbf73c612583566d78989d))
22+
* **readme:** update badges ([b72984d](https://github.com/knocklabs/knock-python/commit/b72984d6cf99fbb5d78e5af92e6ef82cae007a31))
23+
* **tests:** add tests for httpx client instantiation & proxies ([e971449](https://github.com/knocklabs/knock-python/commit/e9714490d78f9f477437425a72451c1a5a74b16c))
24+
25+
26+
### Documentation
27+
28+
* **client:** fix httpx.Timeout documentation reference ([7239e56](https://github.com/knocklabs/knock-python/commit/7239e56653b2b96dda92053ef69c1e944e9e8980))
29+
330
## 1.7.1 (2025-06-13)
431

532
Full Changelog: [v1.7.0...v1.7.1](https://github.com/knocklabs/knock-python/compare/v1.7.0...v1.7.1)

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Knock Python API library
22

3-
[![PyPI version](https://img.shields.io/pypi/v/knockapi.svg)](https://pypi.org/project/knockapi/)
3+
[![PyPI version](<https://img.shields.io/pypi/v/knockapi.svg?label=pypi%20(stable)>)](https://pypi.org/project/knockapi/)
44

55
The Knock Python library provides convenient access to the Knock REST API from any Python 3.8+
66
application. The library includes type definitions for all request params and response fields,
@@ -72,6 +72,42 @@ asyncio.run(main())
7272

7373
Functionality between the synchronous and asynchronous clients is otherwise identical.
7474

75+
### With aiohttp
76+
77+
By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
78+
79+
You can enable this by installing `aiohttp`:
80+
81+
```sh
82+
# install from PyPI
83+
pip install knockapi[aiohttp]
84+
```
85+
86+
Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
87+
88+
```python
89+
import os
90+
import asyncio
91+
from knockapi import DefaultAioHttpClient
92+
from knockapi import AsyncKnock
93+
94+
95+
async def main() -> None:
96+
async with AsyncKnock(
97+
api_key=os.environ.get("KNOCK_API_KEY"), # This is the default and can be omitted
98+
http_client=DefaultAioHttpClient(),
99+
) as client:
100+
response = await client.workflows.trigger(
101+
key="dinosaurs-loose",
102+
recipients=["dnedry"],
103+
data={"dinosaur": "triceratops"},
104+
)
105+
print(response.workflow_run_id)
106+
107+
108+
asyncio.run(main())
109+
```
110+
75111
## Using types
76112

77113
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
@@ -229,7 +265,7 @@ client.with_options(max_retries=5).users.get(
229265
### Timeouts
230266

231267
By default requests time out after 1 minute. You can configure this with a `timeout` option,
232-
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:
268+
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
233269

234270
```python
235271
from knockapi import Knock

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "knockapi"
3-
version = "1.7.1"
3+
version = "1.8.0"
44
description = "The official Python library for the knock API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"
@@ -37,6 +37,8 @@ classifiers = [
3737
Homepage = "https://github.com/knocklabs/knock-python"
3838
Repository = "https://github.com/knocklabs/knock-python"
3939

40+
[project.optional-dependencies]
41+
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.6"]
4042

4143
[tool.rye]
4244
managed = true

requirements-dev.lock

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@
1010
# universal: false
1111

1212
-e file:.
13+
aiohappyeyeballs==2.6.1
14+
# via aiohttp
15+
aiohttp==3.12.8
16+
# via httpx-aiohttp
17+
# via knockapi
18+
aiosignal==1.3.2
19+
# via aiohttp
1320
annotated-types==0.6.0
1421
# via pydantic
1522
anyio==4.4.0
1623
# via httpx
1724
# via knockapi
1825
argcomplete==3.1.2
1926
# via nox
27+
async-timeout==5.0.1
28+
# via aiohttp
29+
attrs==25.3.0
30+
# via aiohttp
2031
certifi==2023.7.22
2132
# via httpcore
2233
# via httpx
@@ -34,23 +45,33 @@ execnet==2.1.1
3445
# via pytest-xdist
3546
filelock==3.12.4
3647
# via virtualenv
48+
frozenlist==1.6.2
49+
# via aiohttp
50+
# via aiosignal
3751
h11==0.14.0
3852
# via httpcore
3953
httpcore==1.0.2
4054
# via httpx
4155
httpx==0.28.1
56+
# via httpx-aiohttp
4257
# via knockapi
4358
# via respx
59+
httpx-aiohttp==0.1.6
60+
# via knockapi
4461
idna==3.4
4562
# via anyio
4663
# via httpx
64+
# via yarl
4765
importlib-metadata==7.0.0
4866
iniconfig==2.0.0
4967
# via pytest
5068
markdown-it-py==3.0.0
5169
# via rich
5270
mdurl==0.1.2
5371
# via markdown-it-py
72+
multidict==6.4.4
73+
# via aiohttp
74+
# via yarl
5475
mypy==1.14.1
5576
mypy-extensions==1.0.0
5677
# via mypy
@@ -65,6 +86,9 @@ platformdirs==3.11.0
6586
# via virtualenv
6687
pluggy==1.5.0
6788
# via pytest
89+
propcache==0.3.1
90+
# via aiohttp
91+
# via yarl
6892
pydantic==2.10.3
6993
# via knockapi
7094
pydantic-core==2.27.1
@@ -98,11 +122,14 @@ tomli==2.0.2
98122
typing-extensions==4.12.2
99123
# via anyio
100124
# via knockapi
125+
# via multidict
101126
# via mypy
102127
# via pydantic
103128
# via pydantic-core
104129
# via pyright
105130
virtualenv==20.24.5
106131
# via nox
132+
yarl==1.20.0
133+
# via aiohttp
107134
zipp==3.17.0
108135
# via importlib-metadata

requirements.lock

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,51 @@
1010
# universal: false
1111

1212
-e file:.
13+
aiohappyeyeballs==2.6.1
14+
# via aiohttp
15+
aiohttp==3.12.8
16+
# via httpx-aiohttp
17+
# via knockapi
18+
aiosignal==1.3.2
19+
# via aiohttp
1320
annotated-types==0.6.0
1421
# via pydantic
1522
anyio==4.4.0
1623
# via httpx
1724
# via knockapi
25+
async-timeout==5.0.1
26+
# via aiohttp
27+
attrs==25.3.0
28+
# via aiohttp
1829
certifi==2023.7.22
1930
# via httpcore
2031
# via httpx
2132
distro==1.8.0
2233
# via knockapi
2334
exceptiongroup==1.2.2
2435
# via anyio
36+
frozenlist==1.6.2
37+
# via aiohttp
38+
# via aiosignal
2539
h11==0.14.0
2640
# via httpcore
2741
httpcore==1.0.2
2842
# via httpx
2943
httpx==0.28.1
44+
# via httpx-aiohttp
45+
# via knockapi
46+
httpx-aiohttp==0.1.6
3047
# via knockapi
3148
idna==3.4
3249
# via anyio
3350
# via httpx
51+
# via yarl
52+
multidict==6.4.4
53+
# via aiohttp
54+
# via yarl
55+
propcache==0.3.1
56+
# via aiohttp
57+
# via yarl
3458
pydantic==2.10.3
3559
# via knockapi
3660
pydantic-core==2.27.1
@@ -41,5 +65,8 @@ sniffio==1.3.0
4165
typing-extensions==4.12.2
4266
# via anyio
4367
# via knockapi
68+
# via multidict
4469
# via pydantic
4570
# via pydantic-core
71+
yarl==1.20.0
72+
# via aiohttp

src/knockapi/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
UnprocessableEntityError,
2727
APIResponseValidationError,
2828
)
29-
from ._base_client import DefaultHttpxClient, DefaultAsyncHttpxClient
29+
from ._base_client import DefaultHttpxClient, DefaultAioHttpClient, DefaultAsyncHttpxClient
3030
from ._utils._logs import setup_logging as _setup_logging
3131

3232
__all__ = [
@@ -68,6 +68,7 @@
6868
"DEFAULT_CONNECTION_LIMITS",
6969
"DefaultHttpxClient",
7070
"DefaultAsyncHttpxClient",
71+
"DefaultAioHttpClient",
7172
]
7273

7374
if not _t.TYPE_CHECKING:

src/knockapi/_base_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,24 @@ def __init__(self, **kwargs: Any) -> None:
12891289
super().__init__(**kwargs)
12901290

12911291

1292+
try:
1293+
import httpx_aiohttp
1294+
except ImportError:
1295+
1296+
class _DefaultAioHttpClient(httpx.AsyncClient):
1297+
def __init__(self, **_kwargs: Any) -> None:
1298+
raise RuntimeError("To use the aiohttp client you must have installed the package with the `aiohttp` extra")
1299+
else:
1300+
1301+
class _DefaultAioHttpClient(httpx_aiohttp.HttpxAiohttpClient): # type: ignore
1302+
def __init__(self, **kwargs: Any) -> None:
1303+
kwargs.setdefault("timeout", DEFAULT_TIMEOUT)
1304+
kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS)
1305+
kwargs.setdefault("follow_redirects", True)
1306+
1307+
super().__init__(**kwargs)
1308+
1309+
12921310
if TYPE_CHECKING:
12931311
DefaultAsyncHttpxClient = httpx.AsyncClient
12941312
"""An alias to `httpx.AsyncClient` that provides the same defaults that this SDK
@@ -1297,8 +1315,12 @@ def __init__(self, **kwargs: Any) -> None:
12971315
This is useful because overriding the `http_client` with your own instance of
12981316
`httpx.AsyncClient` will result in httpx's defaults being used, not ours.
12991317
"""
1318+
1319+
DefaultAioHttpClient = httpx.AsyncClient
1320+
"""An alias to `httpx.AsyncClient` that changes the default HTTP transport to `aiohttp`."""
13001321
else:
13011322
DefaultAsyncHttpxClient = _DefaultAsyncHttpxClient
1323+
DefaultAioHttpClient = _DefaultAioHttpClient
13021324

13031325

13041326
class AsyncHttpxClientWrapper(DefaultAsyncHttpxClient):

0 commit comments

Comments
 (0)