module documentation

High-level gRPC channel manager for the Nebius Python SDK.

Channel locks follow one order. Code can acquire _channel_pool_lock before _tasks_lock or a runtime lock, and _close_submit_lock before a runtime lock. It must not acquire these locks in reverse order. No code awaits, joins a thread, or waits for a future while it holds a channel lock. SDK task objects are copied under their lock and then cancelled or awaited after the lock is released.

Class Channel Manage high-level gRPC channels for the SDK.
Class NebiusUnaryUnaryMultiCallable A small callable wrapper that binds RPC calls to a Channel-managed address.
Class NoCredentials Marker type used to explicitly disable authorization.
Exception ChannelClosedError Raised when an operation is attempted on a closed Channel.
Exception LoopError Exception raised when a synchronous helper conflicts with an asyncio event loop.
Function set_user_agent_option Set or override the grpc.primary_user_agent channel option.
Constant P Undocumented
Type Variable C Undocumented
Type Variable Req Undocumented
Type Variable Res Undocumented
Type Variable T Undocumented
Variable Credentials Undocumented
Variable logger Undocumented
Class _CrossLoopUnaryUnaryCall Provide cross-loop access to one unary gRPC call.
Class _RuntimeAuthenticator Run one authorization authenticator on the SDK event loop.
Class _RuntimeAuthorizationProvider Run an authorization provider on the SDK event loop.
Class _ServiceAddressChannel Resolve and retain one operation-service address on the SDK loop.
Function _finalize_runtime Shut down a runtime only in the process that created it.
Function _get_working_loop Return the loop that a newly created gRPC AsyncIO channel will use.
Function _monitor_transport_closes Release close reservations when their owner loops stop.
Function _reset_detached_foreign_close_tasks_after_fork Drop parent-process task and lock state in a forked child.
Function _retain_detached_foreign_close Retain foreign-loop cleanup without retaining its parent channel.
Function _schedule_detached_close_factory Create detached close work only after its owner loop executes.
Function _shutdown_runtime_on_init_failure Stop a partially constructed channel's runtime before re-raising.
Function _start_detached_foreign_close Start and retain detached close work on the current owner loop.
Function _watch_transport_close Use one daemon monitor for all close callbacks on stopped loops.
Constant _DETACHED_FOREIGN_CLOSE_RETENTION_SECONDS Undocumented
Variable _detached_foreign_close_handles Undocumented
Variable _detached_foreign_close_tasks_lock Undocumented
Variable _transport_close_watch_entries Undocumented
Variable _transport_close_watch_event Undocumented
Variable _transport_close_watch_lock Undocumented
Variable _transport_close_watch_thread Undocumented
def set_user_agent_option(user_agent: str, options: ChannelArgumentType | None) -> ChannelArgumentType: (source)

Set or override the grpc.primary_user_agent channel option.

This helper appends the provided user-agent string to the options sequence, which is passed to gRPC when creating channels. If the grpc.primary_user_agent option is already present in options, it will be replaced with the new value.

Parameters
user_agent:strThe user-agent string to set.
options:optional list of (str, Any) tuplesExisting channel options, if any.
Returns
list of (str, Any) tuplesThe updated channel options including the user-agent.

Undocumented

Value
ParamSpec('P')

Undocumented

Value
TypeVar('C')

Undocumented

Value
TypeVar('Req',
        bound=Message)

Undocumented

Value
TypeVar('Res',
        bound=Message)

Undocumented

Value
TypeVar('T')
Credentials = (source)

Undocumented

Undocumented

def _finalize_runtime(runtime: AsyncRuntime, process_id: int): (source)

Shut down a runtime only in the process that created it.

Threads and locks do not survive fork coherently. A child finalizer must therefore avoid touching inherited runtime state.

Parameters
runtime:AsyncRuntimeRuntime owned by the finalized channel.
process_id:intProcess that created runtime.
def _get_working_loop() -> AbstractEventLoop: (source)

Return the loop that a newly created gRPC AsyncIO channel will use.

def _monitor_transport_closes(): (source)

Release close reservations when their owner loops stop.

def _reset_detached_foreign_close_tasks_after_fork(): (source)

Drop parent-process task and lock state in a forked child.

Event-loop tasks cannot be transferred across fork. Replacing both objects also prevents a child from observing a lock held by a vanished parent thread.

def _retain_detached_foreign_close(handle: Any, owner_loop: AbstractEventLoop): (source)

Retain foreign-loop cleanup without retaining its parent channel.

A caller-owned event loop keeps only weak references to tasks. A cross-thread dispatch returns a concurrent Future. The SDK retains either handle until completion. A callback in the owner loop's public scheduling queue retains the handle. It renews a long timer while the close is pending. The module-level weak set is only for diagnostics and tests. As a result, the retention cycle has no process-global strong reference. If the application drops a stopped loop, its pending close state can be collected with it. This design does not add private attributes to the loop, so it also supports fixed-slot loop types.

The registry contains only detached cleanup. It does not contain per-SDK scheduler or bridge state. Its lock lets independent SDK instances and owner-loop threads use it at the same time.

Parameters
handle:AnyForeign-loop transport-close task or Future to retain.
owner_loop:AbstractEventLoopEvent loop that owns the close operation.
def _schedule_detached_close_factory(factory: Callable[[], Coroutine[Any, Any, None]], owner_loop: AbstractEventLoop, name: str, completion: ConcurrentFuture[None] | None = None) -> bool: (source)

Create detached close work only after its owner loop executes.

A loop can accept a thread-safe callback and stop before it executes that callback. The callback retains the factory instead of a coroutine, so loop closure cannot discard unawaited close work. The detached task settles an optional SDK reservation after it starts or rejects the close work.

Parameters
factory:Callable[[], Coroutine[Any, Any, None]]Function that creates close work on the owner loop.
owner_loop:AbstractEventLoopEvent loop that owns the close work.
name:strDiagnostic task name.
completion:ConcurrentFuture[None] | NoneOptional SDK lifecycle reservation.
Returns
boolTrue if the loop accepted or started the close work.
def _shutdown_runtime_on_init_failure(initializer: Callable[Concatenate[C, P], None]) -> Callable[Concatenate[C, P], None]: (source)

Stop a partially constructed channel's runtime before re-raising.

A constructor traceback can retain the incomplete channel, so its weakref finalizer is not a timely resource boundary. This wrapper starts cleanup for every exception after runtime creation without obscuring the public signature or documentation. It waits for an owned runtime. It only schedules cleanup on a running caller-owned loop, because waiting for an unresponsive borrowed loop would prevent the constructor from propagating an interruption.

Parameters
initializer:Callable[Concatenate[C, P], None]Channel initializer to guard.
Returns
Callable[Concatenate[C, P], None]Initializer that stops an acquired runtime on failure.
def _start_detached_foreign_close(close_coro: Coroutine[Any, Any, None], owner_loop: AbstractEventLoop, name: str, completion: ConcurrentFuture[None] | None = None) -> bool: (source)

Start and retain detached close work on the current owner loop.

A custom task factory can reject task creation. This helper closes the rejected coroutine and settles an optional SDK lifecycle reservation, so the rejection cannot strand shutdown.

Parameters
close_coro:Coroutine[Any, Any, None]Transport-close coroutine to start.
owner_loop:AbstractEventLoopRunning loop that owns close_coro.
name:strDiagnostic task name.
completion:ConcurrentFuture[None] | NoneOptional SDK lifecycle reservation to settle on failure.
Returns
boolTrue if task creation succeeded.
def _watch_transport_close(owner_loop: AbstractEventLoop, completion: ConcurrentFuture[None]): (source)

Use one daemon monitor for all close callbacks on stopped loops.

Parameters
owner_loop:AbstractEventLoopLoop that accepted the close callback.
completion:ConcurrentFuture[None]SDK lifecycle reservation to release if the loop stops.
_DETACHED_FOREIGN_CLOSE_RETENTION_SECONDS: float = (source)

Undocumented

Value
3600.0
_detached_foreign_close_handles = (source)

Undocumented

_detached_foreign_close_tasks_lock = (source)

Undocumented

_transport_close_watch_entries: list[tuple[Callable[[], AbstractEventLoop | None], ConcurrentFuture[None]]] = (source)

Undocumented

_transport_close_watch_event = (source)

Undocumented

_transport_close_watch_lock = (source)

Undocumented

_transport_close_watch_thread: Thread | None = (source)

Undocumented