Resolve your first option¶
We will create a recipe bundle with a timeout option and read its value as
an integer. This example runs in a Python interpreter without a Momotor Broker.
Use Python 3.11 through 3.14 with momotor-engine-options installed.
Import the bundle and option classes:
>>> from momotor.bundles import RecipeBundle >>> from momotor.bundles.elements.options import Option >>> from momotor.options import OptionDefinition, OptionNameDomain >>> from momotor.options.providers import Providers
Create a recipe with a string value of
"30":>>> recipe = RecipeBundle() >>> timeout = Option(recipe).create(name='timeout', value='30') >>> _ = recipe.create(options=[timeout], steps=[])
Define how to read the option:
>>> definition = OptionDefinition( ... name=OptionNameDomain('timeout'), ... type='integer', ... location=('recipe',), ... default=10, ... doc='Maximum runtime in seconds.', ... )
OptionNameDomainsupplies the default domain,checklet.locationselects the bundles to search.Resolve the option from the recipe:
>>> definition.resolve(Providers(recipe=recipe)) 30
The result is the integer
30.Resolve the same definition without a recipe:
>>> definition.resolve(Providers()) 10
The result is the default value because no provider supplies the option.
See Option definitions for lookup order, required options, and multiple values. To publish the definition’s description, follow Generate documentation for option definitions.