Skip to content

Commit 63c87d7

Browse files
committed
chore: prepare release 0.15.0
1 parent d28bc12 commit 63c87d7

11 files changed

+99
-118
lines changed

Diff for: .changeset/allow_customizing_the_underlying_httpx_clients.md

-47
This file was deleted.

Diff for: .changeset/authenticatedclient_no_longer_inherits_from_client.md

-7
This file was deleted.

Diff for: .changeset/client_and_authenticatedclient_now_use_the_newer_attrs_define_and_field_apis.md

-7
This file was deleted.

Diff for: .changeset/clients_now_reuse_connections_between_requests.md

-7
This file was deleted.

Diff for: .changeset/connections_dont_close.md

-18
This file was deleted.

Diff for: .changeset/minimum_httpx_version_raised_to_020.md

-7
This file was deleted.

Diff for: .changeset/removed_public_attributes_for_client_and_authenticatedclient.md

-14
This file was deleted.

Diff for: .changeset/stop_showing_poetry_instructions_in_generated_readmes_when_not_appropriate.md

-5
This file was deleted.

Diff for: .changeset/the_timeout_param_and_with_timeout_now_take_an_httpxtimeout_instead_of_a_float.md

-5
This file was deleted.

Diff for: CHANGELOG.md

+98
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,104 @@ Programmatic usage of this project (e.g., importing it as a Python module) and t
1313

1414
The 0.x prefix used in versions for this project is to indicate that breaking changes are expected frequently (several times a year). Breaking changes will increment the minor number, all other changes will increment the patch number. You can track the progress toward 1.0 [here](https://github.com/openapi-generators/openapi-python-client/projects/2).
1515

16+
## 0.15.0 (2023-07-23)
17+
18+
### Breaking Changes
19+
20+
#### Minimum httpx version raised to 0.20
21+
22+
Some features of generated clients already failed at runtime when using httpx < 0.20, but now the minimum version is enforced at generation time.
23+
24+
#### Connections from clients no longer automatically close (PR [#775](https://github.com/openapi-generators/openapi-python-client/pull/775))
25+
26+
`Client` and `AuthenticatedClient` now reuse an internal [`httpx.Client`](https://www.python-httpx.org/advanced/#client-instances) (or `AsyncClient`)—keeping connections open between requests. This will improve performance overall, but may cause resource leaking if clients are not closed properly. The new clients are intended to be used via context managers—though for compatibility they don't _have_ to be used with context managers. If not using a context manager, connections will probably leak. Note that once a client is closed (by leaving the context manager), it can no longer be used—and attempting to do so will raise an exception.
27+
28+
APIs should now be called like:
29+
30+
```python
31+
with client as client:
32+
my_api.sync(client)
33+
another_api.sync(client)
34+
# client is closed here and can no longer be used
35+
```
36+
37+
Generated READMEs reflect the new syntax, but READMEs for existing generated clients should be updated manually. See [this diff](https://github.com/openapi-generators/openapi-python-client/pull/775/files#diff-62b50316369f84439d58f4981c37538f5b619d344393cb659080dadbda328547) for inspiration.
38+
39+
#### Generated clients and models now use the newer attrs `@define` and `field` APIs
40+
41+
See [the attrs docs](https://www.attrs.org/en/stable/names.html#attrs-tng) for more information on how these may affect you.
42+
43+
#### Removed public attributes for `Client` and `AuthenticatedClient`
44+
45+
The following attributes have been removed from `Client` and `AuthenticatedClient`:
46+
47+
- `base_url`—this can now only be set via the initializer
48+
- `cookies`—set at initialization or use `.with_cookies()`
49+
- `headers`—set at initialization or use `.with_headers()`
50+
- `timeout`—set at initialization or use `.with_timeout()`
51+
- `verify_ssl`—this can now only be set via the initializer
52+
- `follow_redirects`—this can now only be set via the initializer
53+
54+
#### The `timeout` param and `with_timeout` now take an `httpx.Timeout` instead of a float
55+
56+
#### `AuthenticatedClient` no longer inherits from `Client`
57+
58+
The API of `AuthenticatedClient` is still a superset of `Client`, but the two classes no longer share a common base class.
59+
60+
### Features
61+
62+
#### Allow customizing the underlying `httpx` clients
63+
64+
There are many use-cases where customizing the underlying `httpx` client directly is necessary. Some examples are:
65+
66+
- [Event hooks](https://www.python-httpx.org/advanced/#event-hooks)
67+
- [Proxies](https://www.python-httpx.org/advanced/#http-proxying)
68+
- [Custom authentication](https://www.python-httpx.org/advanced/#customizing-authentication)
69+
- [Retries](https://www.python-httpx.org/advanced/#usage_1)
70+
71+
The new `Client` and `AuthenticatedClient` classes come with several methods to customize underlying clients. You can pass arbitrary arguments to `httpx.Client` or `httpx.AsyncClient` when they are constructed:
72+
73+
```python
74+
client = Client(base_url="https://api.example.com", httpx_args={"proxies": {"https://": "https://proxy.example.com"}})
75+
```
76+
77+
**The underlying clients are constructed lazily, only when needed. `httpx_args` are stored internally in a dictionary until the first request is made.**
78+
79+
You can force immediate construction of an underlying client in order to edit it directly:
80+
81+
```python
82+
import httpx
83+
from my_api import Client
84+
85+
client = Client(base_url="https://api.example.com")
86+
sync_client: httpx.Client = client.get_httpx_client()
87+
sync_client.timeout = 10
88+
async_client = client.get_async_httpx_client()
89+
async_client.timeout = 15
90+
```
91+
92+
You can also completely override the underlying clients:
93+
94+
```python
95+
import httpx
96+
from my_api import Client
97+
98+
client = Client(base_url="https://api.example.com")
99+
# The params you put in here ^ are discarded when you call set_httpx_client or set_async_httpx_client
100+
sync_client = httpx.Client(base_url="https://api.example.com", timeout=10)
101+
client.set_httpx_client(sync_client)
102+
async_client = httpx.AsyncClient(base_url="https://api.example.com", timeout=15)
103+
client.set_async_httpx_client(async_client)
104+
```
105+
106+
#### Clients now reuse connections between requests
107+
108+
This happens every time you use the same `Client` or `AuthenticatedClient` instance for multiple requests, however it is best to use a context manager (e.g., `with client as client:`) to ensure the client is closed properly.
109+
110+
### Fixes
111+
112+
#### Stop showing Poetry instructions in generated READMEs when not appropriate
113+
16114
## 0.14.1
17115

18116
### Fixes

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "openapi-python-client"
3-
version = "0.14.1"
3+
version = "0.15.0"
44
description = "Generate modern Python clients from OpenAPI"
55
repository = "https://github.com/triaxtec/openapi-python-client"
66
license = "MIT"

0 commit comments

Comments
 (0)