InvergeDocs
PythonAPI reference

NexusClient

The Nexus client — one object, every Nexus product.

from nexus import NexusClient

The 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

class

A configured connection to one Nexus environment.

View source

NexusClient

constructor
NexusClient(api_key=None, *, config=None, transport=None, dispatcher=None, **options)

Parameters

Prop

Type

View source

distinct_id

property
distinct_id: Optional[str]

The user bound to the current context, if any.

View source

session_key

property
session_key: Optional[str]

The session bound to the current context, if any.

View source

pending

property
pending: int

How many buffered items are waiting to be sent.

View source

closed

property
closed: bool
View source

identify()

method
def 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]

View source

reset()

method
def reset() -> None

Forget the user and start a new session — call this on logout.

View source

current_distinct_id()

method
def current_distinct_id() -> Optional[str]

Returns Optional[str]

View source

ambient_properties()

method
def ambient_properties() -> Mapping[str, Any]

Properties bound via nexus.context.scope.

Returns Mapping[str, Any]

View source

resolve_context()

method
def 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]

View source

request()

method
def request(request) -> Any

Execute 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

View source

enabled()

method
def enabled(service) -> bool

Whether a product is switched on — services / NEXUS_<SERVICE>_ENABLED.

Parameters

Prop

Type

Returns bool

View source

enqueue_event()

method
def enqueue_event(item, context) -> None

Buffer one event (or send it now when batching is off).

Parameters

Prop

Type

View source

enqueue_log()

method
def enqueue_log(item, context) -> None

Buffer one log line (or send it now when batching is off).

Parameters

Prop

Type

View source

flush_events()

method
def flush_events(timeout=None) -> None

Parameters

Prop

Type

View source

flush_logs()

method
def flush_logs(timeout=None) -> None

Parameters

Prop

Type

View source

flush()

method
def flush(timeout=None) -> None

Ship 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

View source

with_dispatcher()

method
def 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'

View source

background()

method
def 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 None

Result-returning calls (flags, Remote Config) can't work here — use the normal client for those.

Parameters

Prop

Type

Returns 'NexusClient'

View source

track()

method
def track(name, properties=None, **kwargs) -> None

Shortcut for client.events.track.

Parameters

Prop

Type

View source

capture_exception()

method
def capture_exception(exc=None, **options) -> Dict[str, Any]

Shortcut for client.errors.capture_exception.

Parameters

Prop

Type

Returns Dict[str, Any]

View source

emit()

method
def emit(room, events, payload=None) -> Dict[str, Any]

Shortcut for client.realtime.emit.

Parameters

Prop

Type

Returns Dict[str, Any]

View source

is_enabled()

method
def is_enabled(key, distinct_id=None, **kwargs) -> bool

Shortcut for client.flags.is_enabled.

Parameters

Prop

Type

Returns bool

View source

close()

method
def close(timeout=3.0) -> None

Flush and release everything. Idempotent.

Parameters

Prop

Type

View source

On this page