Skip to content

Placement

nats.js.api.Placement dataclass #

Placement(cluster=None, tags=None)

Bases: Base

Placement directives to consider when placing replicas of this stream

cluster class-attribute instance-attribute #

cluster = None

tags class-attribute instance-attribute #

tags = None

from_response classmethod #

from_response(resp)

Read the class instance from a server response.

Unknown fields are ignored ("open-world assumption").

Source code in nats/js/api.py
@classmethod
def from_response(cls: type[_B], resp: Dict[str, Any]) -> _B:
    """Read the class instance from a server response.

    Unknown fields are ignored ("open-world assumption").
    """
    params = {}
    for field in fields(cls):
        if field.name in resp:
            params[field.name] = resp[field.name]
    return cls(**params)

evolve #

evolve(**params)

Return a copy of the instance with the passed values replaced.

Source code in nats/js/api.py
def evolve(self: _B, **params) -> _B:
    """Return a copy of the instance with the passed values replaced.
    """
    return replace(self, **params)

as_dict #

as_dict()

Return the object converted into an API-friendly dict.

Source code in nats/js/api.py
def as_dict(self) -> Dict[str, object]:
    """Return the object converted into an API-friendly dict.
    """
    result = {}
    for field in fields(self):
        val = getattr(self, field.name)
        if val is None:
            continue
        if isinstance(val, Base):
            val = val.as_dict()
        if isinstance(val, list):
            if len(val) > 0 and isinstance(val[0], Base):
                val = [v.as_dict() for v in val if isinstance(v, Base)]
        result[field.name] = val
    return result