Skip to main content
Pre-release

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:

  • name and tags are required
  • description is 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 name
  • annotations: field name to type mapping
  • optional_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:

  1. typing_extensions.get_type_hints()
  2. typing.get_type_hints()
  3. 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:

  1. __required_keys__ / __optional_keys__
  2. __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)

Source distribution for create-inspect-typeddict 0.1.0a0
File Size Uploaded
create_inspect_typeddict-0.1.0a0.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for create-inspect-typeddict 0.1.0a0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.1.0a0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page