Skip to content

Use the Scripting API in a Model

Use datamimic_ee.scripting inside functions that a DSL script= expression calls. The API is read-only: container values are copied before they cross the boundary, so changing a returned dictionary never changes the active model.

The snapshot helpers return None, an empty mapping, or the supplied default when no matching value exists. load_memstore() and load_memstore_page() are stricter: they require an active evaluation context and a non-empty product name; paging additionally requires skip >= 0 and limit > 0.

Project script

script/scripting_api.scr.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from datamimic_ee.scripting import (
    get_context_info,
    get_current_product,
    get_property,
    get_record_position,
    get_variable,
    load_memstore,
    load_memstore_page,
)


def current_name():
    return get_context_info().get("current_name")


def current_key_count():
    return len(get_current_product() or {})


def memstore_count(product_name):
    return len(load_memstore(product_name))


def first_memstore_id(product_name):
    return load_memstore_page(product_name, 0, 1)[0]["id"]

Descriptor

datamimic.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<setup>
    <execute uri="script/scripting_api.scr.py"/>
    <generate name="seed" count="2" target="mem">
        <key name="id" generator="IncrementGenerator"/>
    </generate>
    <generate name="scripting_snapshot" count="1" target="LogExporter">
        <variable name="marker" constant="ready"/>
        <key name="current_name" script="current_name()"/>
        <key name="record_position" script="get_record_position()"/>
        <key name="marker" script="get_variable('marker', 'missing')"/>
        <key name="region" script="get_property('region', 'not-configured')"/>
        <key name="current_key_count" script="current_key_count()"/>
        <key name="stored_count" script="memstore_count('seed')"/>
        <key name="first_id" script="first_memstore_id('seed')"/>
    </generate>
</setup>

The <execute> element loads trusted project code. Keep the call itself inside script= so the evaluation context exists. For field lookup in nested products, use the separate scope guide.

The generated Scripting API reference lists the exact functions and signatures available in the current EE version.