Metadata-Version: 2.4
Name: ty-extensions
Version: 0.3.0
Summary: Runtime support for experimental type system features supported by ty
Author: Astral Software Inc.
Author-email: Astral Software Inc. <hey@astral.sh>
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.11
Project-URL: Documentation, https://docs.astral.sh/ty/
Project-URL: Repository, https://github.com/astral-sh/ty-extensions
Description-Content-Type: text/markdown

# ty-extensions

[![PyPI](https://img.shields.io/pypi/v/ty-extensions.svg)](https://pypi.org/project/ty-extensions/)

This package makes [ty]'s experimental typing extensions importable at runtime. You can
add this package as a dependency to your project, if you want to use features from
`ty_extensions` and rely on runtime evaluation of these symbols.

```sh
uv add ty-extensions
```

You can then make use of features like [intersection types]:

```python
import json
from typing import Protocol

from ty_extensions import Intersection


class Serializable(Protocol):
    def serialize_json(self) -> str: ...


class Versioned(Protocol):
    @property
    def version(self) -> int: ...


def output_as_json(obj: Intersection[Serializable, Versioned]) -> str:
    return json.dumps({
        "data": json.loads(obj.serialize_json()),
        "version": obj.version,
    })
```

[ty] checks these symbols using its [bundled `ty_extensions` stubs][stubs],
but the runtime will use the code defined in this package.

[intersection types]: https://docs.astral.sh/ty/features/type-system/#intersection-types
[ty]: https://docs.astral.sh/ty/
[stubs]: https://github.com/astral-sh/ruff/blob/main/crates/ty_vendored/ty_extensions/__init__.pyi
