state

state(*, signal: Union[ravestate.constraint.Signal, NoneType] = '', write: Tuple[ravestate.property.Property] = (), read: Tuple[ravestate.property.Property] = (), cond: ravestate.constraint.Constraint = None, emit_detached: bool = False, weight: float = 1.0, cooldown: float = 0.0, boring: bool = False)

Decorator to declare a new state, which may emit a certain signal, write to a certain set of properties (calling write, push, pop), and read from certain properties (calling read).

Example (Module that outputs "Don't Panic" after startup):

with Module(name="my_module"):
    @state(cond=startup())
    def after_startup(context, write=OUTPUT_PROPERTY):
        context[OUTPUT_PROPERTY] = "Don't Panic"

ravestate.constraint

ConfigurableAge

ConfigurableAge(self, key: str)

Class for having min/max_age parameters for Constraints configurable with a config key

key

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

Constraint

Constraint(self, /, *args, **kwargs)

Superclass for Signal, Conjunct and Disjunct

Signal

Signal(self, name: str, *, min_age=0.0, max_age=5.0, detached=False, _skip_module_context=False)

Class that represents a Signal. Should be constructed in a with Module(..) context, such that it's module scope is set automatically.

SignalRef

SignalRef(self, name: str, *, min_age=0.0, max_age=5.0, detached=False)

Signal reference. Almost the same as a signal, except that it will not try to auto-discover it's module out of thread-local context (module_name will stay unfilled). Needed, because sometimes you need to reference a singal within a module scope without assigning that signal to the contextual module.

Conjunct

Conjunct(self, *args)

Class that represents a Conjunction of Signals. Can be constructed using an overloaded & operator.

Example:

signal_A & signal_B

Disjunct

Disjunct(self, *args)

Class that represents a Disjunction of Conjunctions Can be constructed using an overloaded | operator.

Examples:

conjunction_A | conjunction_B

(signal_A & signal_B) | (signal_C & signal_D)

receptor

receptor(*, ctx_wrap: Union[ravestate.wrappers.ContextWrapper, ravestate.context.Context], write: Union[str, ravestate.property.Property, Tuple[Union[str, ravestate.property.Property]]])

A receptor is a special state which can be invoked from outside, to push values into the context.

  • ctx_wrap: A context wrapper as is always given into the state functions as their first argument.

  • write: The property, or tuple of properties, which are going to be written.

Example:

# Module that outputs "Don't Panic" one minute after startup
# Because a receptor is used, the OUTPUT_PROPERTY is not blocked the whole time
with Module(name="my_module"):
    @state(cond=startup())
    def after_startup(context):
        @receptor(ctx_wrap=context, write=OUTPUT_PROPERTY)
        def dont_panic(ctx_write):
            ctx_write[OUTPUT_PROPERTY] = "Don't Panic"

        sleep(60)
        dont_panic()