Documentation Index
Fetch the complete documentation index at: https://mintlify.com/iFamishedX/mapres/llms.txt
Use this file to discover all available pages before exploring further.
DataMap is the base class for all template contexts in mapres. It is a
dataclass subclass that pairs structured field definitions with a regex syntax
pattern, allowing MapResolver to extract placeholder keys and substitute them
with the correct values. The @datamap decorator transforms any ordinary Python
class into a DataMap-backed dataclass without requiring manual inheritance or
@dataclass usage.
Import
syntax class
The syntax class is a plain namespace that exposes four pre-built regex
patterns, each targeting a different placeholder style. Pass any of these as the
syntax argument to @datamap or MapResolver.
| Attribute | Pattern | Matches |
|---|---|---|
syntax.braces | r"\{([^{}]+)\}" | {key} |
syntax.dollars | r"\$\{([^{}]+)\}" | ${key} |
syntax.angles | r"<([^<>]+)>" | <key> |
syntax.percents | r"%([^%]+)%" | %key% |
DataMap base class
DataMap is a dataclass with two reserved class-level attributes that control
how a resolver identifies and evaluates its fields.
Class attributes
The regex pattern used by
MapResolver to identify placeholders that should
be replaced with values from this map. Captured group 1 of each match is
treated as the field name. Defaults to syntax.braces ({key} style).Controls how field values are evaluated when
as_map() is called. When set
to "dynamic", callable fields are invoked with no arguments and their return
values are used in place of the raw callable. When None (the default),
fields are returned as-is regardless of whether they are callable.Methods
as_map() -> dict
Returns a flat dictionary mapping each field name to its resolved value.
Fields named __syntax__ and __mode__ are always excluded. In "dynamic"
mode, callable values are called and their results are used; if a providers
dict attribute is present on the instance, provider entries take precedence over
the raw field values.
get_syntax() -> str (classmethod)
Returns the __syntax__ pattern for the class, falling back to syntax.braces
if the attribute is not set. MapResolver calls this method internally when
building the list of patterns to apply during map resolution.
@datamap decorator
The @datamap decorator wraps any class, sets __syntax__ and __mode__ on
it, re-creates it as a subclass of DataMap, and then applies @dataclass to
it. The result is a fully functional dataclass whose instances can be dropped
directly into a Layer.
Forms
Bare decorator — @datamap
Applied directly to a class with no arguments. Uses syntax.braces for the
placeholder pattern and mode=None.
Decorator with options — @datamap(syntax=..., mode=...)
Called with keyword arguments to customise the placeholder syntax or evaluation
mode.
The regex pattern to assign to
__syntax__. Accepts any string value,
including the pre-built constants from the syntax class.Pass
"dynamic" to enable callable field evaluation inside as_map().
Any other value (including None) leaves fields unevaluated.Shortcut attributes
datamap exposes four pre-configured decorator shortcuts, one for each entry in
the syntax class. Each shortcut is equivalent to calling
@datamap(syntax=syntax.<name>).
| Shortcut | Equivalent to |
|---|---|
datamap.braces | @datamap(syntax=syntax.braces) |
datamap.angles | @datamap(syntax=syntax.angles) |
datamap.dollars | @datamap(syntax=syntax.dollars) |
datamap.percents | @datamap(syntax=syntax.percents) |
Code examples
Bare decorator
Decorator with options
Dynamic mode with callable fields
In"dynamic" mode, fields whose values are callables are invoked at
as_map() time, making it easy to inject runtime-computed values.
Each call to
as_map() in "dynamic" mode invokes the callable afresh.
This means two resolution passes on the same template may produce different
values if the callable is not pure (e.g., time.time or uuid.uuid4).