---
source: https://iinventedlight.com/library/notes/python-typing-annotated.md
title: "Attach metadata to a type with typing.Annotated"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Public-Domain (Python PEPs); PSF-2.0 (Python docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 593 – Flexible function and variable annotations; Python docs, typing — Support for type hints. Public-Domain; PSF-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: typing.Annotated and PEP 593"
tags: [python, typing, annotated, pep-593]
client: Librarian
sources:
  - id: S1
    title: "PEP 593 – Flexible function and variable annotations"
    publisher: Python PEPs
    url: https://peps.python.org/pep-0593/
    accessed: 2026-11-19
    license: "Public-Domain"
  - id: S2
    title: "typing — Support for type hints"
    publisher: Python docs
    url: https://docs.python.org/3/library/typing.html
    accessed: 2026-11-19
    license: "PSF-2.0"
---
# Attach metadata to a type with typing.Annotated
**Answer:** `Annotated` is a special typing form to add context-specific metadata to an annotation. Write `Annotated[T, x]` to add metadata `x` to a given type `T`. PEP 593 introduces this mechanism to extend PEP 484 annotations with arbitrary metadata.

## Static tools and runtime

Metadata added using `Annotated` can be used by static analysis tools or at runtime. The metadata is stored in a `__metadata__` attribute. The typing docs also show that `get_type_hints()` can return an `Annotated` type, depending on how you call it.

## What belongs in the metadata

PEP 484 is prescriptive about types. PEP 484 is prescriptive about types. `Annotated[T, x]` keeps `T` as the type and `x` as metadata.

| Annotated | metadata |
|---|---|
| Annotated[T, x] | Adds metadata x to type T |
| __metadata__ | Attribute that stores the metadata at runtime |
| static analysis tools | May consume the metadata |
| PEP 593 | Extends PEP 484 annotations with arbitrary metadata |

## See also

- [python-typing-annotations](https://iinventedlight.com/library/notes/python-typing-annotations/)
- [python-dataclasses](https://iinventedlight.com/library/notes/python-dataclasses/)
- [python-functools](https://iinventedlight.com/library/notes/python-functools/)

## Claims

- id: C1
  claim: PEP 593 extends PEP 484 type annotations with arbitrary metadata.
  source: S1
  evidence: "extend the type annotations from PEP 484 with arbitrary metadata"

- id: C2
  claim: Annotated adds context-specific metadata to an annotation.
  source: S2
  evidence: "Special typing form to add context-specific metadata to an annotation"

- id: C3
  claim: At runtime, that metadata is stored on the __metadata__ attribute.
  source: S2
  evidence: "the metadata is stored in a __metadata__"

## Sources

- [S1] PEP 593 – Flexible function and variable annotations. Python PEPs. https://peps.python.org/pep-0593/ . License: Public-Domain. Accessed 2026-11-19.

- [S2] typing — Support for type hints. Python docs. https://docs.python.org/3/library/typing.html . License: PSF-2.0. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python PEPs, PEP 593 – Flexible function and variable annotations; Python docs, typing — Support for type hints. Public-Domain; PSF-2.0. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
