A DataMap is a typed Python dataclass that acts as a template context for mapres. By decorating a plain class withDocumentation 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, you turn it into a structured container whose fields become the key-value pairs available for placeholder substitution. DataMaps carry their own syntax preference and resolution mode alongside the data itself, making them self-describing units that the resolver can consume without any additional configuration.
The DataMap base class
Every DataMap ultimately inherits fromDataMap, a thin base class defined in mapres.datamap:
| Field | Type | Default | Purpose |
|---|---|---|---|
__syntax__ | str | syntax.braces | Regex pattern (with one capture group) used to match placeholders |
__mode__ | str | None | None | Set to "dynamic" to enable callable-based providers |
as_map().
as_map()
as_map() converts the dataclass instance into a plain dictionary that the resolver operates on:
- Fields named
__syntax__and__mode__are always excluded. - Non-init fields (e.g.
field(init=False, ...)) are excluded. - In
dynamicmode, callable values — and any callable found in theprovidersdict — are called immediately and replaced with their return value.
The @datamap decorator
The @datamap decorator is the main entry point for creating DataMaps. It wraps your class, injects __syntax__ and __mode__, makes it inherit from DataMap, and applies @dataclass — all in one step.
Form 1 — bare decorator
syntax.braces) and no special mode.
Form 2 — decorator with options
datamap is:
syntax— any regex string with exactly one capture group (see Syntax Patterns).mode— pass"dynamic"to enable provider resolution;None(default) for static fields.
Form 3 — shortcut decorators
Four pre-configured shortcuts are attached directly todatamap:
Dynamic mode
Settingmode="dynamic" tells as_map() to resolve callable field values at the moment resolution is requested rather than when the dataclass is instantiated. This is useful for timestamps, random values, environment lookups, or any value that must be fresh on every call.
Using callables as field defaults
as_map() is called, timestamp field holds the callable time.time. Because __mode__ == "dynamic", as_map() calls time.time() and stores the returned float.
Using the providers dict
You can also supply a separate providers dictionary on the instance. Any key present in providers overrides the field value before the callable check:
as_map() checks providers[f.name] first; if found and callable, it calls it. This pattern lets you inject per-instance provider logic without changing field defaults.
If
providers is declared as a regular dataclass field (as shown above), it will appear as a key in the output of as_map() — because it is an ordinary init field tracked by fields(). To prevent it from being emitted, declare it with field(init=False, repr=False) or manage it outside the dataclass fields entirely.Custom syntax
__syntax__ accepts any valid Python regex string as long as it contains exactly one capture group. The capture group is what the resolver extracts as the placeholder key.