annotated-types
Reusable constraint metadata objects for use with Python's typing.Annotated
Repository Health
Technical Analysis
annotated-types provides a small set of standardized metadata objects — Gt, Ge, Lt, Le, Interval, MultipleOf, MinLen, MaxLen, Len, Timezone, Predicate, and Doc — designed to be attached to types via PEP 593’s typing.Annotated. Rather than every validation library inventing its own constraint vocabulary, annotated-types gives them a shared, statically-inspectable representation that tools, IDEs, and runtime validators can all agree on.
It underpins constraint handling in Pydantic v2 and is recognized by FastAPI, msgspec, and other typing-aware libraries, making it a foundational piece of the modern Python typing ecosystem rather than a library developers typically import directly for standalone use.
What You Get
- Comparison constraints: Gt, Ge, Lt, Le, and a combined Interval type
- Collection/string constraints: MinLen, MaxLen, and Len
- MultipleOf for numeric divisibility constraints
- Timezone constraint for datetime/time annotations
- Predicate and GroupedMetadata for arbitrary runtime checks and downstream composition
- Prebuilt generic aliases like LowerCase, IsFinite, and IsDigit for common patterns
Common Use Cases
- Declaring field-level constraints consumed by Pydantic v2 models via Annotated types
- Building a custom validation library that needs to interoperate with the broader typing ecosystem
- Adding static, tool-inspectable documentation and constraints to function signatures
- Writing framework-agnostic type aliases (e.g. a shared ‘PositiveInt’) that multiple validators can consume identically
Under The Hood
Architecture: The entire implementation lives in a single module, annotated_types/__init__.py (~400 lines), defining frozen dataclasses for each constraint (Gt, Ge, Lt, Le, Interval, MultipleOf, MinLen, MaxLen, Len, Timezone, Predicate, Not, Doc) plus a GroupedMetadata protocol that downstream libraries implement to expose composite constraint bundles that iterate into individual metadata objects. There is no runtime enforcement logic at all — the package is purely descriptive metadata meant to be interpreted by consuming validators.
Tech Stack: Pure Python with zero runtime dependencies, using dataclasses and typing_extensions/typing for structural types, targeting Python 3.10 through 3.14. Packaging uses a standard pyproject.toml with Hatchling-style metadata and a Makefile for local dev tasks.
Code Quality: Tests are split between tests/ (test_main.py, test_grouped_metadata.py) and an in-package annotated_types/test_cases.py that other libraries can import and reuse to verify their own interpretation of these metadata types against a shared conformance suite — an unusually thoughtful design for an ecosystem-spec package. Type hints are exhaustive and the codebase is fully typed (Typing :: Typed classifier), with CI running across all supported Python versions per pyproject classifiers.
API Design: The API is deliberately minimal — plain dataclass constructors (Gt(0), Len(1, 10)) with obvious, self-documenting names and no configuration ceremony, designed to be composed inside Annotated[T, ...] with zero learning curve for anyone already familiar with PEP 593. Prebuilt generic aliases (LowerCase, IsFinite, IsDigit) further reduce boilerplate for common cases, and the README doubles as a de facto specification document for implementers.
Used by 10 apps in this directory
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
ClickHouse
Databases · Analytics · Data Engineering
Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.
GPT Researcher
Productivity · AI Assistants
The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.
GrowthBook
Developer Tools · Analytics · Monitoring
Open source feature flags, A/B testing, and warehouse-native experimentation that queries your existing data infrastructure—no data movement required.
Helicone
Monitoring · AI Development · Analytics
An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.
knowhere
AI Development · Developer Tools
Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.
Promptfoo
AI Development
An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.
rowboat
AI Assistants · AI Development
Build, test, and deploy multi-agent AI workflows with a visual editor, RAG data sources, MCP tool integration, and a production-ready REST API.
Scalar
Developer Tools
Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.