class documentation

Provide a high-level interface for Nebius services.

The SDK is a small wrapper for a gRPC channel. It supplies high-level methods, such as a method to get the authenticated profile. It inherits channel functions such as resolution, pooling, credential configuration, and synchronous and asynchronous calls.

Quick start -- initialization

These examples show common SDK configurations. Replace example-application/1.0 with your application name and version.

  • From an IAM token in the environment (default behavior):

    sdk = SDK(user_agent_prefix="example-application/1.0")
    
  • With an explicit token string or static bearer:

    sdk = SDK(
        credentials="MY_IAM_TOKEN",
        user_agent_prefix="example-application/1.0",
    )
    # or
    sdk = SDK(
        credentials=Bearer("MY_IAM_TOKEN"),
        user_agent_prefix="example-application/1.0",
    )
    
  • From an env-backed token provider:

    from nebius.aio.token.static import EnvBearer
    sdk = SDK(
        credentials=EnvBearer("NEBIUS_IAM_TOKEN"),
        user_agent_prefix="example-application/1.0",
    )
    
  • From the CLI config reader (reads endpoints/profile like the CLI):

    from nebius.aio.cli_config import Config
    sdk = SDK(
        config_reader=Config(),
        user_agent_prefix="example-application/1.0",
    )
    
  • Service account private key or credentials file:

    sdk = SDK(
        service_account_private_key_file_name="private.pem",
        service_account_public_key_id="pub-id",
        service_account_id="service-account-id",
        user_agent_prefix="example-application/1.0",
    )
    # or
    sdk = SDK(
        credentials_file_name="path/to/credentials.json",
        user_agent_prefix="example-application/1.0",
    )
    

Async vs sync usage and lifecycle

The SDK is designed for asyncio. The asynchronous context manager stops background tasks correctly:

async with SDK(
    ...,
    user_agent_prefix="example-application/1.0",
) as sdk:
    resp = await sdk.whoami()

Each SDK owns a separate daemon event-loop thread and a private daemon executor by default. Its awaitable handles may be awaited from any asyncio loop. Synchronous helpers remain invalid inside an active async call stack; await the handle there. Use synchronous helpers from regular threads:

sdk = SDK(
    ...,
    user_agent_prefix="example-application/1.0",
)
try:
    resp = sdk.whoami().wait()
finally:
    sdk.sync_close()

To use a caller-owned loop, pass an already-running event_loop. Closing the SDK does not stop or reconfigure a supplied loop or its default executor. Do not fill that executor with synchronous SDK waits: custom SDK work on the supplied loop may need an executor worker, and the SDK cannot reliably identify threads owned by an arbitrary caller executor.

Set loop_exception_handler to a synchronous asyncio exception handler. Do not use an async def function. A synchronous wrapper must return None instead of a coroutine or another awaitable. The SDK rejects directly recognizable async functions. If a synchronous handler returns any other value, the SDK closes a newly returned, unstarted native coroutine and reports both the original context and the contract violation through asyncio's default exception handler. It does not change a suspended coroutine, returned Future, Task, or opaque awaitable because the handler might not own that work. The SDK cannot know whether an invalid handler processed the original context, so default reporting can duplicate a diagnostic that the handler already emitted. The loop calls the handler on its thread, and the handler must return promptly. A blocking handler stops all work on that loop. On a supplied loop, the handler receives diagnostics from SDK work and other loop users. After all other SDK initialization succeeds, the handler starts receiving diagnostics. A later loop assignment replaces that handler. The handler remains installed after SDK close. It does not automatically call asyncio's default handler. An exception context can contain sensitive data and objects owned by the event loop. Read these objects only on that loop. Copy and redact the required immutable fields before another thread processes them. Request and operation failures still propagate through their returned awaitables. The handler can retain objects that it captures until another handler replaces it or the loop closes. SDK construction raises RuntimeError if a supplied loop stops before the SDK installs the handler. If construction fails after the SDK starts to use a caller-supplied loop, the SDK starts cleanup before it propagates the error. Cleanup can continue after the constructor returns. Construction from another thread waits up to 30 seconds for a supplied loop to install the handler. The event loop stores an SDK forwarding callable for the handler. loop.get_exception_handler() does not have to return the same callable that the caller passed to the SDK. Handler installation is the final SDK initialization action. If an asynchronous BaseException arrives after the loop accepts the handler but before the constructor returns, the handler can remain installed even though construction did not return an SDK.

Authentication and auth_timeout

  • auth_timeout limits credential acquisition, credential renewal, and the request. Many calls accept this parameter.
  • The default is 15 minutes (900 seconds). Set auth_timeout=None to remove the limit. Authentication can then wait indefinitely.
  • Use auth_options to control renewal. For example, make renewal synchronous or return renewal errors as request errors.

Timeouts and retries (summary)

  • The overall timeout limits the request and all retries.
  • The per-retry timeout limits each retry attempt.
  • The default overall timeout is 60 seconds.
  • Requests make up to three retries by default. The default per-retry timeout is 20 seconds (60 seconds / 3 retries).
  • Set timeout=None to disable the request deadline.
  • Set retries and per_retry_timeout for each call as necessary.

Keepalive

  • By default, SDK channels use gRPC keepalive settings that are compatible with the Nebius SDK for Go.
  • The SDK reads the NEBIUS_GRPC_KEEPALIVE_* environment variables.
  • Set keepalive=False to disable SDK keepalive.
  • To change the settings, give nebius.aio.keepalive.KeepaliveOptions or a mapping. The mapping can contain time_ms, timeout_ms, and permit_without_stream.
  • gRPC options in options or address_options apply later. These options can replace individual keepalive arguments.

Metrics

  • Give metrics to receive configuration-reader and authentication events.
  • Give auth_metrics to receive only authentication events.
  • If you give metrics, the SDK uses it for authentication callbacks and ignores auth_metrics.
  • A metric sink can be an object with callback methods. It can also be a mapping of callback names to functions.
  • Callback names can use Python snake_case or TypeScript-style camelCase.
  • callback_timeout_seconds limits awaitable callback results. The SDK adjusts invalid or too-large values to its limits.
  • The SDK ignores callback failures. Metrics do not affect SDK requests.

Parent ID auto-population

  • The SDK can set parent_id automatically for applicable methods. It gets the value from nebius.aio.cli_config.Config or the SDK parent_id initialization parameter.
  • To use the CLI configuration without its parent ID, set no_parent_id=True.

Operations

  • Long-running service calls return an nebius.aio.operation.Operation wrapper. You can await this wrapper until the operation is complete.
  • Use the source service's operation_service() method to list operations.
  • The Operation wrapper supplies .wait() and .resource_id.

Request metadata and debugging

  • Service methods return Request objects. These objects supply metadata such as the request ID and trace ID.

  • You can await a request or wait for it synchronously.

  • Example:

    request = sdk.whoami()  # Do not await the request yet.
    resp = await request
    request_id = await request.request_id()
    trace_id = await request.trace_id()
    

Error handling and nebius.aio.service_error.RequestError

User-agent customization

  • Set user_agent_prefix when you construct the SDK.
  • You can also set grpc.primary_user_agent in options.
  • The SDK combines these values with its internal version string.

See Also

  • See the project README and API reference for more examples and explanations.
Method whoami Return a request to get the profile for the current credentials.

Inherited from Channel:

Async Method __aenter__ Enter the async context manager.
Async Method __aexit__ Exit the async context manager.
Method __init__ Construct a new Channel.
Method bg_task Run an awaitable in the background.
Async Method channel_ready Channel is always ready, nothing to do here.
Async Method close Gracefully close the channel and all associated background work.
Method create_address_channel Create a new underlying gRPC channel for the given address.
Method discard_channel Dispose of an AddressChannel by scheduling its close.
Method get_addr_by_method Return the cached address for a fully-qualified RPC method name.
Method get_addr_by_route Resolve immutable generated route metadata without global descriptors.
Method get_addr_from_service_name Resolve a logical service name into a transport address.
Method get_addr_from_stub Resolve the concrete address for a generated service stub class.
Method get_address_interceptors Return the ordered list of interceptors to apply to a channel.
Method get_address_options Compute effective gRPC channel options for a specific address.
Method get_authorization_provider Return the configured AuthorizationProvider.
Method get_channel_by_addr Request an AddressChannel for the given resolved address.
Method get_channel_by_method Get an AddressChannel for an RPC method name.
Method get_channel_by_route Return a pooled channel selected from generated route metadata.
Method get_corresponding_operation_service Return an operations service stub for a generated service stub's address.
Method get_corresponding_operation_service_alpha Return an alpha-version operations stub for a generated service's address.
Method get_state Nebius Python SDK channels are always ready unless closed.
Async Method get_token Asynchronously fetch an authorization Token.
Method get_token_sync Get an authorization Token synchronously.
Method parent_id Return the channel-wide default parent ID used for certain requests.
Method release_channel Release an internal transport without masking a concurrent shutdown.
Method return_channel Return an AddressChannel to the internal pool.
Method run_async Submit SDK work to the channel's event loop.
Method run_sync Run an awaitable to completion on the channel's event loop.
Method stream_stream Nebius Python SDK does not support streaming RPCs.
Method stream_unary Nebius Python SDK does not support streaming RPCs.
Method sync_close Synchronously close the channel and wait for graceful shutdown.
Method unary_stream Nebius Python SDK does not support streaming RPCs.
Method unary_unary A method to support using SDK channel as gRPC Channel.
Async Method wait_for_state_change Nebius Python SDK channels are always ready unless closed.
Instance Variable user_agent The user-agent string used by channels created by this Channel instance.
Static Method _registry_for_service Undocumented
Method _check_process Reject a channel inherited from another process before locking.
Async Method _close_address_channel Close a pooled transport on its owner loop when that loop is running.
Async Method _close_internal Close SDK resources without stopping the runtime.
Method _configure_metrics_on_config_reader Undocumented
Async Method _create_address_channel Create an address channel on the SDK event loop.
Method _create_address_channel_internal Create a configured gRPC channel without loop dispatch.
Method _discard_background_task Remove completed background work from channel tracking.
Async Method _get_addr_by_method Resolve and cache a method address on the SDK event loop.
Method _get_addr_by_method_internal Resolve and cache a method address without loop dispatch.
Async Method _get_addr_by_route Resolve and cache a generated route on the SDK event loop.
Method _get_addr_by_route_internal Resolve and cache generated route metadata without loop dispatch.
Async Method _get_addr_from_service_name Resolve a service name on the SDK event loop.
Method _get_addr_from_service_name_internal Normalize and resolve a service name without loop dispatch.
Async Method _get_channel_by_addr Lease an address channel on the SDK event loop.
Method _get_channel_by_addr_internal Lease or create an address channel without loop dispatch.
Method _get_close_handle Return the single channel cleanup submission.
Method _get_runtime_authorization_provider Return a private provider that uses the SDK event loop.
Async Method _get_token_internal Get a token on the SDK event loop.
Async Method _get_token_with_deadline Fetch a token within a deadline captured on the caller thread.
Method _has_authorization_provider Return whether requests use this channel's fixed auth provider.
Method _is_config_metrics_aware_config_reader Undocumented
Method _lease_address_channel Track a checked-out transport or retire it if shutdown won the race.
Method _release_address_channel Undocumented
Async Method _release_address_channel_async Release an address channel from an SDK-loop coroutine.
Method _release_channel_on_sdk_loop Release a channel on the SDK loop or dispatch the release to it.
Method _release_channel_soon Schedule transport release without blocking the caller thread.
Method _run_sdk_callable Call a function on the SDK event loop.
Method _schedule_address_channel_close Schedule and retain an SDK-loop transport close until it finishes.
Method _shutdown_after_internal_caller Start shutdown after an internal close caller can return.
Instance Variable _address_interceptors Undocumented
Instance Variable _address_options Undocumented
Instance Variable _auth_metrics Undocumented
Instance Variable _authorization_provider Undocumented
Instance Variable _channel_lifecycle_ready Undocumented
Instance Variable _channel_pool_lock Undocumented
Instance Variable _close_completion Undocumented
Instance Variable _close_handle Undocumented
Instance Variable _close_submit_lock Undocumented
Instance Variable _close_task Undocumented
Instance Variable _closed Undocumented
Instance Variable _event_loop Undocumented
Instance Variable _free_channels Undocumented
Instance Variable _global_interceptors Undocumented
Instance Variable _global_interceptors_inner Undocumented
Instance Variable _global_options Undocumented
Instance Variable _gracefuls Undocumented
Instance Variable _keepalive_config Undocumented
Instance Variable _leased_channels Undocumented
Instance Variable _max_free_channels_per_address Undocumented
Instance Variable _methods Undocumented
Instance Variable _metrics Undocumented
Instance Variable _parent_id Undocumented
Instance Variable _process_id Undocumented
Instance Variable _resolver Undocumented
Instance Variable _route_custom_resolver Undocumented
Instance Variable _route_substitutions Undocumented
Instance Variable _routes Undocumented
Instance Variable _runtime Undocumented
Instance Variable _runtime_finalizer Undocumented
Instance Variable _tasks Undocumented
Instance Variable _tasks_lock Undocumented
Instance Variable _tls_credentials Undocumented
Instance Variable _token_bearer Undocumented
Instance Variable _transport_closes Undocumented

Return a request to get the profile for the current credentials.

This method wraps the generated ProfileServiceClient.get method.

Give request arguments as keyword arguments. See nebius.aio.request_kwargs.RequestKwargs for details.

Returns
Request of GetProfileResponseA Request for the active RPC. Await it or use its .wait() methods.