typemap
PEP 827 type manipulation library for Python 3.14+
Installation
pip install typemap
Overview
typemap provides utilities for working with PEP 827 type manipulation operators. It includes:
eval_typing- Evaluate type expressions at runtime- Type operators via
typemap_extensions:Member- Access type members by nameAttrs- Get class attributesIter- Iterate over type contentsParam- Define callable parametersUpdateClass- Generate class modificationsNewProtocol- Create protocols dynamicallyIsAssignable- Check type assignabilityKeyOf- Get all member names as tuple of LiteralsTemplate- Build template literal stringsDeepPartial- Make all fields recursively optionalPartial- Make all fields optional (non-recursive)Required- Remove Optional from all fieldsPick- Pick specific fields from a typeOmit- Omit specific fields from a type
Usage
Evaluating Types
from typemap import eval_typing
class MyClass:
x: int
y: str
result = eval_typing(MyClass)
print(result)
Type Utilities
typemap provides several type utility operators for transforming types:
from typing import Literal
import typemap_extensions as tm
# KeyOf - Get all member names as tuple of Literals
class User:
name: str
age: int
keys = tm.KeyOf[User]
# Result: tuple[Literal["name"], Literal["age"]]
# Partial - Make all fields optional (non-recursive)
PartialUser = tm.Partial[User]
# Result: class with name: str | None, age: int | None
# DeepPartial - Make all fields recursively optional
DeepUser = tm.DeepPartial[User]
# Result: class with all nested fields optional
# Required - Remove Optional from all fields
class OptionalUser:
name: str | None
age: int | None
RequiredUser = tm.Required[OptionalUser]
# Result: class with name: str, age: int
# Pick - Select specific fields
PublicUser = tm.Pick[User, tuple["name"]]
# Result: class with only name: str
# Omit - Exclude specific fields
SafeUser = tm.Omit[User, tuple["password"]]
# Result: class without password field
Using UpdateClass
from typing import Callable, Literal, Self, Never
import typemap_extensions as typing
type InitFn[T] = typing.Member[
Literal["__init__"],
Callable[
[
typing.Param[Literal["self"], Self],
*[
typing.Param[p.name, p.type]
for p in typing.Iter[typing.Attrs[T]]
],
],
None,
],
Literal["ClassVar"],
]
class Model:
def __init_subclass__[T](cls: type[T]) -> typing.UpdateClass[InitFn[T]]:
super().__init_subclass__()
class User(Model):
name: str
age: int
Development
# Install dependencies
cd packages/typemap
uv sync
# Run tests
uv run pytest
# Run type checking
uv run mypy src/typemap/
# Run linting
uv run ruff check src/typemap/
Requirements
- Python 3.14+
- typing_extensions >= 4.0
Metadata
Release files for typemap 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| typemap-0.2.3.tar.gz | 68.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| typemap-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 102.3 kB
Release files / typemap-0.2.3.tar.gz
| Download URL | typemap-0.2.3.tar.gz |
|---|---|
| Size | 68.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d4f26986469ed341c5b40e9eb5dcab4bc66cfdbf36ab2478accaf50b8372b2f
|
|
BLAKE2b-256 checksum How to use checksums |
74ed2b298c23048121118fdfb1c8107385bd50e53903d5b84b06abbdd8c0d2df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / typemap-0.2.3-py3-none-any.whl
| Download URL | typemap-0.2.3-py3-none-any.whl |
|---|---|
| Size | 33.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84c818c21867c723c9f610e5c115926084591021e74a8a197f94fc3748836411
|
|
BLAKE2b-256 checksum How to use checksums |
57610b0d6d7b425c2283078ed64a3b08cd46757afece5457e7db74e4d8c74547
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for typemap 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.