Skip to content

Placement

nats.js.api.Placement dataclass #

Bases: Base

Placement directives to consider when placing replicas of this stream

cluster class-attribute instance-attribute #

cluster: Optional[str] = None

tags class-attribute instance-attribute #

tags: Optional[List[str]] = None

as_dict #

as_dict() -> Dict[str, object]

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()
        result[field.name] = val
    return result

evolve #

evolve(**params) -> _B

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)

from_response classmethod #

from_response(resp: Dict[str, Any]) -> _B

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)

Last update: 2023-11-13