This release is a pre-release and may not be stable for production use.
create-inspect-typeddict
Compatibility helpers for creating and inspecting TypedDict types.
Example
from typing import List
from create_inspect_typeddict import (
create_typeddict,
get_hints,
get_required_and_optional_keys,
)
Item = create_typeddict(
"Item",
{
"name": str,
"tags": List[str],
"description": str,
},
optional_keys=["description"],
)
print(get_hints(Item))
required_keys, optional_keys = get_required_and_optional_keys(Item)
print(sorted(required_keys))
print(sorted(optional_keys))
Expected result:
nameandtagsare requireddescriptionis optional
Main Functions
is_typeddict(typ)
Returns True when typ appears to be a TypedDict type.
It prefers typing_extensions.is_typeddict() when available and otherwise falls back to structural checks.
create_typeddict(name, annotations, optional_keys=None)
Creates a TypedDict class dynamically.
Arguments:
name: class nameannotations: field name to type mappingoptional_keys: iterable of keys that should be optional
Behavior:
- validates that every optional key exists in
annotations - creates the
TypedDict - populates
__required_keys__and__optional_keys__
get_hints(typ)
Returns a dictionary of resolved type hints for typ.
It tries:
typing_extensions.get_type_hints()typing.get_type_hints()- raw
__annotations__
This is useful when consuming TypedDict definitions that may contain forward references or compatibility-layer typing objects.
get_required_and_optional_keys(typ)
Returns a (required_keys, optional_keys) tuple of frozenset values for a TypedDict.
Resolution order:
__required_keys__/__optional_keys____total__
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Release files for create-inspect-typeddict 0.1.0a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| create_inspect_typeddict-0.1.0a0.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| create_inspect_typeddict-0.1.0a0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / create_inspect_typeddict-0.1.0a0.tar.gz
| Download URL | create_inspect_typeddict-0.1.0a0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1cf48e72cb8f2d9d1c7f544807e9a01acfcc742446463815fe7a5cb58f6c6af
|
|
BLAKE2b-256 checksum How to use checksums |
6da122756305eb27ee0fc32d3391461c77478c85b6c516b984c70ba5df4c251b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / create_inspect_typeddict-0.1.0a0-py2.py3-none-any.whl
| Download URL | create_inspect_typeddict-0.1.0a0-py2.py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0b8405750456f956abe80149865a4f4c6a974ffb999a29d9227d92efb9c7faa5
|
|
BLAKE2b-256 checksum How to use checksums |
be5d860d9d936b955de8f0e9a65b2553d7b03e0bc99813bc0b4ccd3d0c718fd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|