update_subscriber()
Update many aspects of a subscriber: email and name, custom attribute data, list membership, and status.
Usage
update_subscriber(
subscriber,
add_to_lists=None,
remove_from_lists=None,
status=None,
timeout_config=None
)Final list membership is computed from the subscriber’s existing lists minus remove_from_lists plus add_to_lists, and the affected subscriptions are preconfirmed. The subscriber keeps whatever global status they already have unless you pass status; a disabled or blocklisted subscriber stays that way after a name or attribute change. You can enable, disable, or block a subscriber here, but if that is all you want to do there are dedicated, simpler functions (enable_subscriber, disable_subscriber, block_subscriber).
Parameters
subscriber: models.Subscriber-
The full subscriber object to update, with the changed fields already set. Must have a valid id.
add_to_lists: Optional[set[int]] = None-
List IDs to add this subscriber to. Defaults to None (treated as an empty set).
remove_from_lists: Optional[set[int]] = None-
List IDs to remove this subscriber from. Defaults to None (treated as an empty set).
status: Optional[SubscriberStatuses] = None-
The subscriber’s new status, one of SubscriberStatuses.enabled, .disabled, or .blocklisted. Defaults to None, which keeps the status already on
subscriber(or enabled if the object carries no status at all). timeout_config: Optional[httpx2.Timeout] = None- Optional per-request timeout; defaults to 10 seconds.
Returns
Optional[models.Subscriber]-
The refreshed subscriber object fetched from the server after the update, or None if the subscriber
can no longer be found.
Raises
ValueError-
If subscriber is None or has no id.
OperationNotAllowedError-
If the base URL is not set or you are not logged in.
httpx2.HTTPStatusError-
If the server responds with a 4xx or 5xx status.
ValidationError- If the follow-up fetch returns an empty or invalid JSON response.
Examples
>>> import listmonk
>>> sub = listmonk.subscriber_by_email('some_user@talkpython.fm')
>>> sub.name = 'Some User'
>>> sub.attribs['rating'] = 7
>>> sub = listmonk.update_subscriber(sub, add_to_lists={4}, remove_from_lists={5})
>>> sub.attribs['rating']
7