NexusClient
The Nexus client — one object, every Nexus product.
from nexus import NexusClientThe Nexus client — one object, every Nexus product.
from nexus import NexusClient
nexus = NexusClient("nxs_live_xxx")
nexus.identify("user_123", email="a@b.com")
nexus.events.track("order_placed", {"total": 42})
nexus.realtime.emit("orders:42", "status", {"state": "shipped"})The client is thread-safe and meant to be built once per process and shared.
In a web app, build it at import time (or in your framework's startup hook) and
reuse it; the integrations in nexus.integrations do that for you.
NexusClient
classA configured connection to one Nexus environment.
View sourceNexusClient
constructorNexusClient(api_key=None, *, config=None, transport=None, dispatcher=None, **options)Parameters
Prop
Type
distinct_id
propertydistinct_id: Optional[str]The user bound to the current context, if any.
View sourcesession_key
propertysession_key: Optional[str]The session bound to the current context, if any.
View sourcepending
propertypending: intHow many buffered items are waiting to be sent.
View sourceclosed
propertyclosed: boolidentify()
methoddef identify(distinct_id, *, email=None, name=None, phone=None, traits=None, remote=True, **context_fields) -> Dict[str, Any]Set the current user locally and upsert them server-side.
Pass remote=False to only bind the local context (useful in a hot
loop where the person already exists).
Parameters
Prop
Type
Returns Dict[str, Any]
reset()
methoddef reset() -> NoneForget the user and start a new session — call this on logout.
View sourcecurrent_distinct_id()
methoddef current_distinct_id() -> Optional[str]Returns Optional[str]
ambient_properties()
methoddef ambient_properties() -> Mapping[str, Any]Properties bound via nexus.context.scope.
Returns Mapping[str, Any]
resolve_context()
methoddef resolve_context(**overrides) -> Dict[str, Any]Merge config defaults, ambient context and explicit overrides.
Keys are the API's camelCase field names. Precedence, lowest first:
client config → nexus.context → overrides.
Parameters
Prop
Type
Returns Dict[str, Any]
request()
methoddef request(request) -> AnyExecute one partner-API request.
Raises a nexus.exceptions.NexusError subclass on failure,
unless the client is configured silent=True — then it logs and
returns None.
Parameters
Prop
Type
Returns Any
enabled()
methoddef enabled(service) -> boolWhether a product is switched on — services / NEXUS_<SERVICE>_ENABLED.
Parameters
Prop
Type
Returns bool
enqueue_event()
methoddef enqueue_event(item, context) -> NoneBuffer one event (or send it now when batching is off).
Parameters
Prop
Type
enqueue_log()
methoddef enqueue_log(item, context) -> NoneBuffer one log line (or send it now when batching is off).
Parameters
Prop
Type
flush_events()
methoddef flush_events(timeout=None) -> NoneParameters
Prop
Type
flush_logs()
methoddef flush_logs(timeout=None) -> NoneParameters
Prop
Type
flush()
methoddef flush(timeout=None) -> NoneShip every buffered event and log line, and drain any background dispatcher. Call it before a short-lived process exits (the SDK also does this at interpreter exit).
Parameters
Prop
Type
with_dispatcher()
methoddef with_dispatcher(dispatcher) -> 'NexusClient'A sibling client that delivers through a different dispatcher.
The two share nothing but configuration, so buffering and shutdown stay independent.
Parameters
Prop
Type
Returns 'NexusClient'
background()
methoddef background(*, workers=1) -> 'NexusClient'A sibling client where every call is fire-and-forget.
bg = nexus.background()
bg.push.send_to_user("u_1", title="Welcome") # returns NoneResult-returning calls (flags, Remote Config) can't work here — use the normal client for those.
Parameters
Prop
Type
Returns 'NexusClient'
track()
methoddef track(name, properties=None, **kwargs) -> NoneShortcut for client.events.track.
Parameters
Prop
Type
capture_exception()
methoddef capture_exception(exc=None, **options) -> Dict[str, Any]Shortcut for client.errors.capture_exception.
Parameters
Prop
Type
Returns Dict[str, Any]
emit()
methoddef emit(room, events, payload=None) -> Dict[str, Any]Shortcut for client.realtime.emit.
Parameters
Prop
Type
Returns Dict[str, Any]
is_enabled()
methoddef is_enabled(key, distinct_id=None, **kwargs) -> boolShortcut for client.flags.is_enabled.
Parameters
Prop
Type
Returns bool
close()
methoddef close(timeout=3.0) -> NoneFlush and release everything. Idempotent.
Parameters
Prop
Type
