class Operation(Generic[
Constructor: Operation(source_method, channel, operation)
Wrap an operation message.
The Operation wrapper normalizes
nebius.api.nebius.common.v1.Operation
and nebius.api.nebius.common.v1alpha1.Operation representations.
Its methods:
- inspect operation metadata (id, resource_id, timestamps),
- poll/update the operation state via the corresponding operation service, and
- wait for completion either asynchronously or synchronously.
The wrapper stores an operation-service client. A
nebius.aio.constant_channel.Constant points this client at
source_method. The client reuses channel for network and
authorization functions.
Built-in channels schedule polling on the SDK loop, so this wrapper can be used from unrelated caller loops. A legacy custom channel without run_async keeps the historical local-awaitable fallback. Its update lock becomes bound to the first caller loop that contends for it, and the same wrapper must not then be used concurrently from another loop.
Example
Operation from a service action (e.g., creating a bucket):
from nebius.sdk import SDK
from nebius.aio.cli_config import Config
from nebius.api.nebius.storage.v1 import (
BucketServiceClient,
CreateBucketRequest
)
sdk = SDK(
config_reader=Config(),
user_agent_prefix="example-application/1.0",
)
service = BucketServiceClient(sdk)
# Create operation from service action
operation = await service.create(CreateBucketRequest(
# fill-in necessary fields
))
# Wait for completion
await operation.wait()
print(f"New bucket ID: {operation.resource_id}")
Operation from list of operations:
from nebius.sdk import SDK
from nebius.aio.cli_config import Config
from nebius.api.nebius.storage.v1 import BucketServiceClient
from nebius.api.nebius.common.v1 import ListOperationsRequest
sdk = SDK(
config_reader=Config(),
user_agent_prefix="example-application/1.0",
)
service = BucketServiceClient(sdk)
# Get operation service client from the bucket service
operation_service = service.operation_service()
operations_response = await operation_service.list(ListOperationsRequest(
# fill-in necessary fields
))
# Get first operation from list
if operations_response.operations:
operation = operations_response.operations[0]
# Manual update
await operation.update()
print(f"Operation status: {operation.status()}")
| Parameters | |
| source | the originating service.method name used to build a constant channel for operation management calls |
| channel | channel used for network and auth operations |
| operation | an operation protobuf instance (v1 or v1alpha1) |
| Method | __init__ |
Create an operation wrapper from the operation protobuf. |
| Method | __repr__ |
Return a compact string representation useful for debugging. |
| Method | done |
Return True when the operation has reached a terminal state. |
| Method | progress |
Return an operation progress tracker when available. |
| Method | raw |
Return the underlying operation protobuf object. |
| Method | status |
Return the operation's current status object or None. |
| Method | successful |
Return True when the operation completed successfully. |
| Method | sync |
Synchronously perform a single update of the operation state. |
| Method | sync |
Synchronously wait for the operation to complete. |
| Async Method | update |
Fetch the latest operation data from the operation service. |
| Async Method | wait |
Asynchronously wait until the operation reaches a terminal state. |
| Property | created |
Return the operation creation timestamp. |
| Property | created |
Return the identity that created the operation (string). |
| Property | description |
Return the operation description as provided by the service. |
| Property | finished |
Return the completion time or None if the operation is not finished. |
| Property | id |
Return the operation identifier (string). |
| Property | resource |
Return the resource id associated with the operation. |
| Method | _check |
Reject an operation inherited across fork before locking. |
| Method | _operation |
Return the current operation message under the state lock. |
| Method | _set |
Replace the wrapped operation object with a new instance. |
| Async Method | _update |
Submit one update with a caller-captured monotonic start time. |
| Async Method | _update |
Fetch and store one operation update on the SDK event loop. |
| Async Method | _wait |
Submit polling with a caller-captured monotonic start time. |
| Async Method | _wait |
Poll the operation on the SDK event loop until it is complete. |
| Instance Variable | _channel |
Undocumented |
| Instance Variable | _get |
Undocumented |
| Instance Variable | _operation |
Undocumented |
| Instance Variable | _process |
Undocumented |
| Instance Variable | _service |
Undocumented |
| Instance Variable | _state |
Undocumented |
| Instance Variable | _update |
Undocumented |
str, channel: ClientChannelInterface, operation: OperationPb):
(source)
¶
Create an operation wrapper from the operation protobuf.
Return an operation progress tracker when available.
Return None if the operation has no progress tracker. For example, v1alpha1 operations do not have one.
Example
Polling with a single-line progress display:
from asyncio import sleep
from datetime import datetime
from nebius.base.protos.well_known import local_timezone
while not operation.done():
await operation.update()
tracker = operation.progress_tracker()
parts = [f"waiting for operation {operation.id} to complete:"]
if tracker:
work = tracker.work_fraction()
if work is not None:
parts.append(f"{work:.0%}")
desc = tracker.description()
if desc:
parts.append(desc)
started = tracker.started_at()
if started is not None:
elapsed = datetime.now(local_timezone) - started
parts.append(f"{elapsed}")
eta = tracker.estimated_finished_at()
if eta is not None:
parts.append(f"eta {eta}")
print(" ".join(parts), end="\r", flush=True)
await sleep(1)
print()
Return the underlying operation protobuf object.
Use this to access version-specific fields that are not exposed by the normalized wrapper. The returned object preserves the existing mutable compatibility surface; mutating it concurrently bypasses this wrapper's snapshot and locking guarantees. Callers must serialize such mutation.
| Returns | |
OperationPb | Current mutable operation protobuf object. |
Synchronously perform a single update of the operation state.
This wraps the coroutine update and runs it via the channel's
synchronous runner. An applicable authorization budget bounds the
whole authorized flow; otherwise the request budget bounds SDK-loop
queueing. Legacy channels whose provider is discoverable only on
their owner loop enforce both clocks internally. A small safety margin
accommodates scheduling overhead. Mutable metadata and authorization
options are copied before the method dispatches work.
| Parameters | |
**kwargs:Unpack[ | additional request keyword arguments
see nebius.aio.request_kwargs.RequestKwargs for details. |
| Raises | |
ValueError | If timeout or auth_timeout is NaN or infinite. Use None for an unlimited timeout. |
Fetch the latest operation data from the operation service.
This coroutine performs a single get operation using the internal operation service client and replaces the wrapped operation object with the returned value.
| Parameters | |
**kwargs:Unpack[ | additional request keyword arguments
see nebius.aio.request_kwargs.RequestKwargs for details. |
| Raises | |
ValueError | If timeout or auth_timeout is NaN or infinite. Use None for an unlimited timeout. |
float | timedelta = 1, timeout: float | None = None, poll_iteration_timeout: float | UnsetType | None = Unset, poll_per_retry_timeout: float | UnsetType | None = Unset, poll_retries: int | None = None, **kwargs: Unpack[ RequestKwargsForOperation]):
(source)
¶
Asynchronously wait until the operation reaches a terminal state.
The method repeatedly invokes update at the specified
interval until the operation is done or the overall timeout is
reached. Certain transient errors (deadline exceeded) are treated as
ignorable and will be retried.
| Parameters | |
interval:float or timedelta | Positive, finite polling interval (seconds or timedelta). This value is ignored when the operation is already terminal. |
timeout:optional float | overall timeout (seconds) for waiting, or None for
infinite timeout, default infinite. |
pollfloat or None | timeout used for each polling iteration, will be
passed as the timeout to each update call. |
pollfloat or None, will be passed as the
per_retry_timeout to each update call. | per-retry timeout for polling requests, will
be passed as the per_retry_timeout to each update call. |
pollint | None | retry count used for polling requests, will be passed as
the retries to each update call. |
**kwargs:Unpack[ | additional request keyword arguments
see nebius.aio.request_kwargs.RequestKwargsForOperation for
details. Mutable metadata and authorization options are copied
before polling is submitted to the SDK event loop. |
| Raises | |
TimeoutError | when the overall timeout is exceeded |
ValueError | When an unfinished operation receives a non-positive/non-finite polling interval or a non-finite overall timeout. Use None for an unlimited timeout. |
Return the operation creation timestamp.
If the underlying protobuf does not expose a creation time this helper returns the current time in the local timezone. :rtype: datetime
Replace the wrapped operation object with a new instance.
The replacement is only allowed when the new operation has the same
protobuf class as the currently wrapped object; otherwise an
SDKError is raised.
float, **kwargs: Unpack[ RequestKwargs]):
(source)
¶
Submit one update with a caller-captured monotonic start time.
| Parameters | |
submittedfloat | Monotonic time when the caller submitted the update. Request and authorization deadlines include all later dispatch delay. |
**kwargs:Unpack[ | Additional request options for the operation service. |
float | None = None, authorization_deadline: float | None = None, **kwargs: Unpack[ RequestKwargs]):
(source)
¶
Fetch and store one operation update on the SDK event loop.
Updates are serialized for this operation. A pending response therefore cannot arrive after a newer terminal response and regress the stored operation state. Once a terminal response is stored, later queued updates return without making another request.
| Parameters | |
requestfloat | None | Absolute monotonic request deadline captured before SDK-loop dispatch. |
authorizationfloat | None | Absolute monotonic authorization deadline captured before SDK-loop dispatch. |
**kwargs:Unpack[ | Request options for the operation service. |
float, interval: float | timedelta = 1, timeout: float | None = None, poll_iteration_timeout: float | UnsetType | None = Unset, poll_per_retry_timeout: float | UnsetType | None = Unset, poll_retries: int | None = None, **kwargs: Unpack[ RequestKwargsForOperation]):
(source)
¶
Submit polling with a caller-captured monotonic start time.
| Parameters | |
submittedfloat | Monotonic time when the caller submitted the wait. The overall timeout includes all later dispatch delay. |
interval:float | timedelta | Positive delay between polling attempts. |
timeout:float | None | Overall wait limit, or None for no limit. |
pollfloat | UnsetType | None | Limit for one polling request. |
pollfloat | UnsetType | None | Limit for each retry. |
pollint | None | Retry count for each polling request. |
**kwargs:Unpack[ | Additional request options for the operation service. |
float | timedelta = 1, timeout: float | None = None, deadline: float | None = None, poll_iteration_timeout: float | UnsetType | None = Unset, poll_per_retry_timeout: float | UnsetType | None = Unset, poll_retries: int | None = None, **kwargs: Unpack[ RequestKwargsForOperation]):
(source)
¶
Poll the operation on the SDK event loop until it is complete.
A local timeout and a service DEADLINE_EXCEEDED response are transient for one polling iteration. Other errors stop the wait.
| Parameters | |
interval:float | timedelta | Delay between polling attempts, in seconds or as a time delta. |
timeout:float | None | Overall wait limit in seconds. Use None for no limit. |
deadline:float | None | Absolute monotonic deadline captured before dispatch to the SDK loop. This includes runtime queueing and update-lock acquisition in the overall timeout. |
pollfloat | UnsetType | None | Timeout for one update request. |
pollfloat | UnsetType | None | Timeout for each retry of an update request. |
pollint | None | Retry count for each update request. |
**kwargs:Unpack[ | Additional request options for the operation service. |
| Raises | |
TimeoutError | If the overall wait limit expires. |