Skip to content

Message objects

pykka.messages

The pykka.messages module contains Pykka's own actor messages.

In general, you should not need to use any of these classes. However, they have been made part of the public API so that certain optimizations can be done without touching Pykka's internals.

An example is to combine ask() and ProxyCall to call a method on an actor without having to spend any resources on creating a proxy object:

reply = actor_ref.ask(
    ProxyCall(
        attr_path=('my_method',),
        args=('foo',),
        kwargs={'bar': 'baz'}
    )
)

Another example is to use tell() instead of ask() for the proxy method call, and thus avoid the creation of a future for the return value if you don't need it.

It should be noted that these optimizations should only be necessary in very special circumstances.

ProxyCall

Bases: NamedTuple

Message to ask the actor to call the method with the arguments.

Version added: Pykka 2.0

Source code in src/pykka/messages.py
class ProxyCall(NamedTuple):
    """Message to ask the actor to call the method with the arguments.

    /// note | Version added: Pykka 2.0
    ///
    """

    attr_path: AttrPath
    """List with the path from the actor to the method."""

    args: tuple[Any, ...]
    """List with positional arguments."""

    kwargs: dict[str, Any]
    """Dict with keyword arguments."""

args instance-attribute

args: tuple[Any, ...]

List with positional arguments.

attr_path instance-attribute

attr_path: AttrPath

List with the path from the actor to the method.

kwargs instance-attribute

kwargs: dict[str, Any]

Dict with keyword arguments.

ProxyGetAttr

Bases: NamedTuple

Message to ask the actor to return the value of the attribute.

Version added: Pykka 2.0

Source code in src/pykka/messages.py
class ProxyGetAttr(NamedTuple):
    """Message to ask the actor to return the value of the attribute.

    /// note | Version added: Pykka 2.0
    ///
    """

    attr_path: AttrPath
    """List with the path from the actor to the attribute."""

attr_path instance-attribute

attr_path: AttrPath

List with the path from the actor to the attribute.

ProxySetAttr

Bases: NamedTuple

Message to ask the actor to set the attribute to the value.

Version added: Pykka 2.0

Source code in src/pykka/messages.py
class ProxySetAttr(NamedTuple):
    """Message to ask the actor to set the attribute to the value.

    /// note | Version added: Pykka 2.0
    ///
    """

    attr_path: AttrPath
    """List with the path from the actor to the attribute."""

    value: Any
    """The value to set the attribute to."""

attr_path instance-attribute

attr_path: AttrPath

List with the path from the actor to the attribute.

value instance-attribute

value: Any

The value to set the attribute to.