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.
MapResolver is the central class in mapres. It combines layers, syntax providers, a pipeline, and context substitution into a single resolution call. When res() is invoked, it passes the input text through each processing stage — pipeline transforms, syntax provider substitutions, layered map lookups, and finally context variable replacement — repeating these passes recursively until the output stabilises or max_depth is reached.
Import
Constructor
MapResolver(layers, syntax, pipeline, cache, cache_size, max_depth)
Creates a new resolver instance with the given configuration.
A
LayerStack instance that defines the ordered map sources used during
resolution. When None or omitted, an empty LayerStack is created
automatically and no map lookups are performed. Pass a pre-built LayerStack
to supply one or more Layer objects.A list of syntax provider objects. Each provider must expose a
.pattern
attribute (regex string) and a .get_map(ctx, resolver) method that returns a
dict of substitution keys. Providers are applied in list order before layered
map resolution.A list of callables with the signature
(text: str, ctx: dict, resolver: MapResolver) -> str.
Pipeline stages are applied first in each resolution pass, before syntax
providers or map lookups. Any exception raised inside a stage is wrapped in a
MapResError.When
True, resolved results are stored in an internal LRU cache keyed by
(text, sorted_ctx_items). Cache is bypassed entirely when extra_maps or
override_maps are supplied to res().Maximum number of entries held in the LRU cache. Once the limit is reached,
the oldest entry is evicted before a new one is inserted.
Maximum number of recursive resolution passes. Each pass runs the full
pipeline → syntax → maps → context sequence. Iteration stops early if a pass
produces no change in the output string.
Instance method — res()
res(text, *, extra_maps=None, override_maps=None, **ctx) -> str
Resolves a template string against the resolver’s configured layers, syntax
providers, pipeline, and any additional context passed as keyword arguments.
The template string to resolve. Placeholders inside the string are matched
against the configured syntax patterns and replaced with values drawn from
the layer stack, syntax providers, or context kwargs.
An additional key-value map merged into a temporary
Layer named "extra"
with priority=999 (lowest priority — queried last). The resolver’s existing
layer stack is cloned and the extra layer is appended, leaving the original
stack unchanged. Cache is not consulted when this argument is provided.When set, replaces the entire layer stack with a single temporary
Layer
named "override" at priority=0. All other configured layers are ignored
for this call. Cache is not consulted when this argument is provided.Arbitrary keyword arguments passed as the resolution context. Context values
are substituted in the final stage of each resolution pass using
syntax.braces ({key} placeholders). Context keys also act as a fallback
during map lookups if a key is not found in any layer.str — the fully resolved string after all passes complete.
Raises:
| Exception | When |
|---|---|
MapResError | Base error; wraps unexpected resolver failures and pipeline stage errors. |
MissingKeyError | A placeholder key could not be found in any layer, syntax provider, or context. Subclass of MapResError. |
MapSyntaxError | A regex pattern (from a syntax provider, layer, or context) is malformed. Subclass of MapResError. |
extra_maps and override_maps are mutually exclusive — if both are
provided, override_maps takes precedence and extra_maps is ignored.Global res() function
res(text, **ctx) -> str
A module-level shortcut that resolves text using a shared default
MapResolver instance created with no layers, no syntax providers, and no
pipeline. It is equivalent to calling MapResolver().res(text, **ctx) and is
intended for quick, layer-free context substitutions.
The template string to resolve.
Key-value pairs injected as the resolution context. Placeholders in
text
using {key} syntax are replaced with the matching values.str — the resolved string.
Complete example
The following example builds a resolver with two layers — a base configuration layer and a per-environment override layer — then resolves a template string while injecting runtime context.Because
StagingOverride is in the layer with priority=0, its env and
version values shadow those from BaseConfig (at priority=10). Keys not
present in the higher-priority layer — such as app_name — fall through to
the base layer automatically.