typing-extensions

4.15.0 · active · verified Fri Mar 27

typing-extensions provides backported and experimental type hints for Python, serving two purposes: enabling use of new type system features on older Python versions (e.g., TypeGuard from 3.10 is available on 3.9+), and enabling experimentation with new PEP-proposed typing constructs before they land in the standard library. The library also re-exports all names from the standard typing module, so it can serve as a single import source. Current version is 4.15.0 (as of early 2026); feature releases follow an irregular cadence under Semantic Versioning where only the major version is bumped for breaking changes.

Warnings

Install

Imports

Quickstart

Demonstrates the most commonly used constructs: TypedDict with ReadOnly/NotRequired fields, TypeAlias, Self, runtime_checkable Protocol, TypeIs narrowing, the @deprecated decorator, and @override.

from typing_extensions import (
    TypedDict,
    NotRequired,
    ReadOnly,
    Annotated,
    Self,
    TypeAlias,
    override,
    deprecated,
    TypeIs,
    Protocol,
    runtime_checkable,
)
import sys

# TypedDict with optional and read-only fields (PEP 655, PEP 705)
class Movie(TypedDict):
    title: ReadOnly[str]
    year: NotRequired[int]

movie: Movie = {"title": "Blade Runner"}

# TypeAlias for clarity
Vector: TypeAlias = list[float]

# Self in method signatures
class Builder:
    def set_name(self, name: str) -> Self:
        self.name = name
        return self

# Protocol with runtime checking
@runtime_checkable
class Drawable(Protocol):
    def draw(self) -> None: ...

# TypeIs for narrowing
def is_str_list(val: list[object]) -> TypeIs[list[str]]:
    return all(isinstance(x, str) for x in val)

# deprecated decorator
@deprecated("Use new_api() instead")
def old_api() -> None:
    pass

# override for subclass safety
class Base:
    def compute(self) -> int:
        return 0

class Child(Base):
    @override
    def compute(self) -> int:
        return 42

print(f"typing_extensions quickstart OK — Python {sys.version}")

view raw JSON →