# context

URL: /patitas/api/context/
Section: api
Description: Content-aware context mapping for Patitas AST nodes.

Maps AST node types to the template context paths they affect. This defines
how content structure maps to template variables, enabling reactive systems
(like Purr) to determine which template blocks need re-rendering when
specific content nodes change.

The mapping is conservative — it may over-identify affected context paths
(causing unnecessary re-renders) but never under-identify (causing stale
content). When a node type isn't in the map, the fallback covers it.

Example:
    from patitas.context import context_paths_for
    from patitas.nodes import Heading

    paths = context_paths_for(heading_node)
    # frozenset({"page.toc", "page.headings", "page.body"})

Thread Safety:
    All data is immutable (frozensets). Safe to call from any thread.

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/context/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fcontext%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fcontext%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fcontext%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fcontext%2Findex.txt)

Module

#
`context`

Content-aware context mapping for Patitas AST nodes.

Maps AST node types to the template context paths they affect. This defines
how content structure maps to template variables, enabling reactive systems
(like Purr) to determine which template blocks need re-rendering when
specific content nodes change.

The mapping is conservative — it may over-identify affected context paths
(causing unnecessary re-renders) but never under-identify (causing stale
content). When a node type isn't in the map, the fallback covers it.

Example:

```
from patitas.context import context_paths_for
from patitas.nodes import Heading

paths = context_paths_for(heading_node)
# frozenset({"page.toc", "page.headings", "page.body"})
```

Thread Safety:

```
All data is immutable (frozensets). Safe to call from any thread.
```

1Function

## Functions

`context_paths_for`

1

`frozenset[str]`

▼

Return the template context paths affected by this node type.

Uses the node's …

`def context_paths_for(node: Node) -> frozenset[str]`

Return the template context paths affected by this node type.

Uses the node's class name to look up affected paths. Returns the
conservative fallback for unknown node types.

##### Parameters

Name
Type
Description

`node`
`Node (/patitas/api/nodes/#Node)`

Any Patitas AST node.

##### Returns

`frozenset[str]`
