[](https://github.com/asottile/typing-derive/actions/workflows/main.yml)
[](https://results.pre-commit.ci/latest/github/asottile/typing-derive/main)
typing-derive
=============
derive types from other types to make it easier to type code!
## Installation
```bash
pip install typing-derive
```
## usage
add as a mypy plugin
```ini
[mypy]
plugins = typing_derive.plugin
```
### `typing_derive.impl.typeddict_from_func`
create a usable `TypedDict` from some callable. useful if you need to
dynamically build up `**kwargs` to call a function
```python
from typing_derive.impl import typeddict_from_func
def f(x: int, y: str) -> None: ...
TD = typeddict_from_func('TD', f)
x: TD = {
'x': 1,
'y': 'hello hello',
}
f(**x)
```
### `typing_derive.impl.typeof`
create a type alias for the type of a function / variable.
one use might be to pass functions of matching signatures as objects
```python
def f(x: int, y: str) -> None: ...
F = typeof('F', f)
def g(func: F) -> None:
func(x=1, y='two')
def h(x: int, y: str) -> None: ...
def j(x: str, y: str) -> None: ...
def k(x1: int, y: str) -> None: ...
g(f) # ok
g(h) # ok
g(j) # error: `x` is `str` not `int`
g(k) # error: `x1` mismatches `x`
```
it also just works on normal variables too -- though I haven't come up with a
use for this yet
```python
x = 5
X = typeof('X', x) # effectively `type X = int`
y: X = 6 # ok
z: X = 'no' # not ok!
```
Raw data
{
"_id": null,
"home_page": "https://github.com/asottile/typing-derive",
"name": "typing-derive",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": null,
"author": "Anthony Sottile",
"author_email": "asottile@umich.edu",
"download_url": "https://files.pythonhosted.org/packages/04/24/900a308e114bfead2ba1e14ece8a14231dad3411ef8c629635d3b505b12b/typing_derive-1.1.0.tar.gz",
"platform": null,
"description": "[](https://github.com/asottile/typing-derive/actions/workflows/main.yml)\n[](https://results.pre-commit.ci/latest/github/asottile/typing-derive/main)\n\ntyping-derive\n=============\n\nderive types from other types to make it easier to type code!\n\n## Installation\n\n```bash\npip install typing-derive\n```\n\n## usage\n\nadd as a mypy plugin\n\n```ini\n[mypy]\nplugins = typing_derive.plugin\n```\n\n### `typing_derive.impl.typeddict_from_func`\n\ncreate a usable `TypedDict` from some callable. useful if you need to\ndynamically build up `**kwargs` to call a function\n\n```python\nfrom typing_derive.impl import typeddict_from_func\n\ndef f(x: int, y: str) -> None: ...\n\nTD = typeddict_from_func('TD', f)\n\nx: TD = {\n 'x': 1,\n 'y': 'hello hello',\n}\n\nf(**x)\n```\n\n### `typing_derive.impl.typeof`\n\ncreate a type alias for the type of a function / variable.\n\none use might be to pass functions of matching signatures as objects\n\n```python\ndef f(x: int, y: str) -> None: ...\n\nF = typeof('F', f)\n\ndef g(func: F) -> None:\n func(x=1, y='two')\n\ndef h(x: int, y: str) -> None: ...\ndef j(x: str, y: str) -> None: ...\ndef k(x1: int, y: str) -> None: ...\n\ng(f) # ok\ng(h) # ok\ng(j) # error: `x` is `str` not `int`\ng(k) # error: `x1` mismatches `x`\n```\n\nit also just works on normal variables too -- though I haven't come up with a\nuse for this yet\n\n```python\nx = 5\n\nX = typeof('X', x) # effectively `type X = int`\n\ny: X = 6 # ok\nz: X = 'no' # not ok!\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "derive types from other types to make it easier to type code!",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/asottile/typing-derive"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3c00ec26a8f9c2aef7499bf1a1dd9d7754ed668b2dfc4572904c22fad346743e",
"md5": "9f68867e1e189e4fd43d063fd050f4b7",
"sha256": "0c6ac7fc959418a58b95d34e5b8f75ebcc6eb6d7ef80a822e0b399a0735b16fc"
},
"downloads": -1,
"filename": "typing_derive-1.1.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "9f68867e1e189e4fd43d063fd050f4b7",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.12",
"size": 4891,
"upload_time": "2025-07-13T21:25:46",
"upload_time_iso_8601": "2025-07-13T21:25:46.011956Z",
"url": "https://files.pythonhosted.org/packages/3c/00/ec26a8f9c2aef7499bf1a1dd9d7754ed668b2dfc4572904c22fad346743e/typing_derive-1.1.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0424900a308e114bfead2ba1e14ece8a14231dad3411ef8c629635d3b505b12b",
"md5": "3b36f20e3afa0aa18ea0c4dd1e01beb9",
"sha256": "ff9d0786dafaab3eca3dc6e64418d1e28e053a8e9137bb3153131b818b26e953"
},
"downloads": -1,
"filename": "typing_derive-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "3b36f20e3afa0aa18ea0c4dd1e01beb9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 4385,
"upload_time": "2025-07-13T21:25:47",
"upload_time_iso_8601": "2025-07-13T21:25:47.059543Z",
"url": "https://files.pythonhosted.org/packages/04/24/900a308e114bfead2ba1e14ece8a14231dad3411ef8c629635d3b505b12b/typing_derive-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-13 21:25:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "asottile",
"github_project": "typing-derive",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "typing-derive"
}