---
source: https://iinventedlight.com/library/notes/python-typing-literal.md
title: "Restrict a type to a specific value with typing.Literal"
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 586 – Literal Types; 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.Literal and PEP 586"
tags: [python, typing, literal, pep-586]
client: Librarian
sources:
  - id: S1
    title: "PEP 586 – Literal Types"
    publisher: Python PEPs
    url: https://peps.python.org/pep-0586/
    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"
---
# Restrict a type to a specific value with typing.Literal
**Answer:** `Literal` is a special typing form to define "literal types". `Literal` indicates a value equivalent to one of the provided literals. PEP 586 adds those types to the PEP 484 ecosystem.

## A specific value

Literal types indicate that some expression has literally a specific value. The PEP's example is a function that will accept only expressions that have literally the value "4". Multiple literals can be listed in one `Literal[...]` form.

## Writing the annotation

Use `Literal[True]` on a parameter or a return type. 

| Literal | meaning |
|---|---|
| Literal | Special typing form for literal types |
| specific value | The expression has literally that value |
| provided literals | Value equivalent to one of the provided literals |
| PEP 586 | Adds Literal types to the PEP 484 ecosystem |

## See also

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

## Claims

- id: C1
  claim: PEP 586 adds Literal types to indicate an expression has a specific value.
  source: S1
  evidence: "This PEP proposes adding Literal types to the PEP 484 ecosystem"

- id: C2
  claim: Literal types indicate that some expression has literally a specific value.
  source: S1
  evidence: "Literal types indicate that some expression has literally a specific value"

- id: C3
  claim: typing.Literal tells type checkers the annotated object has one of the provided literals.
  source: S2
  evidence: "the annotated object has a value equivalent to one of the provided literals"

## Sources

- [S1] PEP 586 – Literal Types. Python PEPs. https://peps.python.org/pep-0586/ . 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 586 – Literal Types; 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).
