Typing Stubs for JMESPath

1.1.0.20260408 · active · verified Sun Apr 12

types-jmespath is a type stub package that provides static type annotations for the `jmespath` library. It is part of the Typeshed project, the central repository for Python type stubs, and is automatically released to PyPI (up to once a day). This package helps type checkers like MyPy and Pyright understand the types used in `jmespath` expressions, improving code quality and maintainability. Its versioning aims to align with `jmespath==1.1.*`, ensuring compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic usage of the `jmespath` library. When `types-jmespath` is installed alongside `jmespath`, type checkers will use the provided stubs to validate the type correctness of your `jmespath` operations without altering runtime behavior.

import jmespath
from typing import Any, Dict, List

data: Dict[str, Any] = {
    "store": {
        "book": [
            {"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95},
            {"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99}
        ],
        "bicycle": {"color": "red", "price": 19.95}
    }
}

# Example 1: Simple retrieval
title: Any = jmespath.search("store.book[0].title", data)
print(f"Title: {title}")

# Example 2: Projection to get all authors
authors: List[str] = jmespath.search("store.book[*].author", data)
print(f"Authors: {authors}")

# Example 3: Filtering based on a condition
fiction_books: List[Dict[str, Any]] = jmespath.search("store.book[?category=='fiction']", data)
print(f"Fiction books: {fiction_books}")

# With types-jmespath installed, a type checker (like mypy or pyright)
# would utilize these stubs to perform static analysis,
# ensuring that `jmespath.search` calls conform to its expected signature
# and that return types are handled correctly based on the JMESPath expression.

view raw JSON →