Openapi-python-client

Latest version: v0.19.1

Safety actively analyzes 619599 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 12

0.20

Some features of generated clients already failed at runtime when using httpx < 0.20, but now the minimum version is enforced at generation time.

Connections from clients no longer automatically close (PR [775](https://github.com/openapi-generators/openapi-python-client/pull/775))

`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.

APIs should now be called like:

python
with client as client:
my_api.sync(client)
another_api.sync(client)
client is closed here and can no longer be used


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.

Generated clients and models now use the newer attrs `define` and `field` APIs

See [the attrs docs](https://www.attrs.org/en/stable/names.html#attrs-tng) for more information on how these may affect you.

Removed public attributes for `Client` and `AuthenticatedClient`

The following attributes have been removed from `Client` and `AuthenticatedClient`:

- `base_url`—this can now only be set via the initializer
- `cookies`—set at initialization or use `.with_cookies()`
- `headers`—set at initialization or use `.with_headers()`
- `timeout`—set at initialization or use `.with_timeout()`
- `verify_ssl`—this can now only be set via the initializer
- `follow_redirects`—this can now only be set via the initializer

The `timeout` param and `with_timeout` now take an `httpx.Timeout` instead of a float

`AuthenticatedClient` no longer inherits from `Client`

The API of `AuthenticatedClient` is still a superset of `Client`, but the two classes no longer share a common base class.

Features

Allow customizing the underlying `httpx` clients

There are many use-cases where customizing the underlying `httpx` client directly is necessary. Some examples are:

- [Event hooks](https://www.python-httpx.org/advanced/#event-hooks)
- [Proxies](https://www.python-httpx.org/advanced/#http-proxying)
- [Custom authentication](https://www.python-httpx.org/advanced/#customizing-authentication)
- [Retries](https://www.python-httpx.org/advanced/#usage_1)

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:

python
client = Client(base_url="https://api.example.com", httpx_args={"proxies": {"https://": "https://proxy.example.com"}})


**The underlying clients are constructed lazily, only when needed. `httpx_args` are stored internally in a dictionary until the first request is made.**

You can force immediate construction of an underlying client in order to edit it directly:

python
import httpx
from my_api import Client

client = Client(base_url="https://api.example.com")
sync_client: httpx.Client = client.get_httpx_client()
sync_client.timeout = 10
async_client = client.get_async_httpx_client()
async_client.timeout = 15


You can also completely override the underlying clients:

python
import httpx
from my_api import Client

client = Client(base_url="https://api.example.com")
The params you put in here ^ are discarded when you call set_httpx_client or set_async_httpx_client
sync_client = httpx.Client(base_url="https://api.example.com", timeout=10)
client.set_httpx_client(sync_client)
async_client = httpx.AsyncClient(base_url="https://api.example.com", timeout=15)
client.set_async_httpx_client(async_client)


Clients now reuse connections between requests

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.

Fixes

Stop showing Poetry instructions in generated READMEs when not appropriate

0.19.1

Features

Add config option to override content types

You can now define a `content_type_overrides` field in your `config.yml`:

yaml
content_type_overrides:
application/zip: application/octet-stream


This allows `openapi-python-client` to generate code for content types it doesn't recognize.

PR 1010 closes 810. Thanks gaarutyunov!

Fixes

Add aliases to `Client` for pyright

This should resolve incompatibilities between the generated `Client` class and the pyright type checker.

PR 1009 closes 909. Thanks patrick91!

0.19.0

Breaking Changes

Update PDM metadata syntax

Metadata generated for PDM will now use the new `distribution = true` syntax instead of `package-type = "library"`.
New packages generated with `--meta pdm` will require PDM `2.12.0` or later to build.

Features

Add response content to `UnexpectedStatus` exception

The error message for `UnexpectedStatus` exceptions will now include the UTF-8 decoded (ignoring errors) body of the response.

PR 989 implements 840. Thanks harabat!

Fixes

Allow hyphens in path parameters

Before now, path parameters which were invalid Python identifiers were not allowed, and would fail generation with an
"Incorrect path templating" error. In particular, this meant that path parameters with hyphens were not allowed.
This has now been fixed!

PR 986 fixed issue 976. Thanks harabat!

> [!WARNING]
> This change may break custom templates, see [this diff](https://github.com/openapi-generators/openapi-python-client/pull/986/files#diff-0de8437b26075d8fe8454cf47d8d95d4835c7f827fa87328e03f690412be803e)
> if you have trouble upgrading.

0.18.0

Breaking Changes

For custom templates, changed type of endpoint parameters

**This does not affect projects that are not using `--custom-template-path`**

The type of these properties on `Endpoint` has been changed from `Dict[str, Property]` to `List[Property]`:

- `path_parameters`
- `query_parameters`
- `header_parameters`
- `cookie_parameters`

If your templates are very close to the default templates, you can probably just remove `.values()` anywhere it appears.

The type of `iter_all_parameters()` is also different, you probably want `list_all_parameters()` instead.

0.17.3

Fixes

Remove spurious field_dict.update({}) for types without properties (969)

Fix invalid type check for nested unions

Nested union types (unions of unions) were generating `isinstance()` checks that were not valid (at least for Python 3.9).

Thanks to codebutler for PR 959 which fixes 958 and 967.

0.17.2

Features

Add `--meta=pdm` option for generating PEP621 + PDM metadata

The default metadata is still `--meta=poetry`, which generates a `pyproject.toml` file with Poetry-specific metadata.
This change adds the `--meta=pdm` option which includes [PDM](https://pdm-project.org/latest/)-specific metadata, but also
standard [PEP621](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#writing-pyproject-toml)
metadata. This may be useful as a starting point for other dependency managers & build tools (like Hatch).

Add original OpenAPI `data` attribute to `Response` object

PR 767

In custom templates, you can now access a `response.data` attribute that contains the original OpenAPI definition of the
response (Response Object or Reference Object).

Include the `UP` rule for generated Ruff config

This enables [pyupgrade-like improvements](https://docs.astral.sh/ruff/rules/#pyupgrade-up) which should replace some
`.format()` calls with f-strings.

Fixes

Fix Ruff formatting for `--meta=none`

PR 940 fixes issue 939. Thanks satwell!

Due to the lack of `pyproject.toml`, Ruff was not getting configured properly when `--meta=none`.
As a result, it didn't clean up common generation issues like duplicate imports, which would then cause errors from
linters.

This is now fixed by changing the default `post_hook` to `ruff check . --fix --extend-select=I` when `--meta=none`.
Using `generate --meta=none` should now be almost identical to the code generated by `update`.

Page 1 of 12

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.