Skip to main content
See Services for usage and limits.

Service

Properties use the last response without making a request.

Static methods

Service.create()

Create a Service for a running target without retrying. Port zero raises InvalidConfigError before any request. Repeating a create with the same slug and target returns the existing Service while it is enabled. Get and check the Service if the task is cancelled after the request is sent.

Parameters

slugstr
Service slug, e.g. “my-app”.
The running sandbox and port that receive requests. The port is 1 through 65535.

Returns

The Service as committed.

Service.get()

Get a Service by slug.

Parameters

slugstr
Service slug.

Returns

The Service’s current state.

Service.list()

List the first page in slug order, including disabled and detached Services.

Returns

One page of Services.

Service.list_with()

List a configured page in slug order. A limit outside 1 through 100 raises InvalidConfigError before any request.

Parameters

sandboxstr | None
Target sandbox; an unknown name returns an empty page.
cursorstr | None
A previous next_cursor.
limitint | None
Page size from 1 to 100; defaults to 20.

Returns

One page of Services.

Instance properties

svc.slug

str The Service slug.

svc.url

str The public URL as returned by the backend.

svc.status

ServiceStatus Whether the Service routes requests, is disabled, or has no target, as of the read that returned this value. refresh() returns a current copy.

svc.target

ServiceTarget | None The target, or None when the Service is detached.

svc.created_at

float The creation time in milliseconds since epoch.

svc.updated_at

float The last state-change time in milliseconds since epoch.

Instance methods

svc.update()

Change the target without retrying. target is required; None or port zero raises InvalidConfigError before any request. Get and check the Service if the task is cancelled after the request is sent.

Parameters

Running target; also enables or reattaches the Service.

Returns

The Service as committed.

svc.enable()

Enable the Service without retrying. To enable a detached Service, set a running target with update() instead.

svc.disable()

Disable the Service without retrying while retaining its target.

svc.remove()

Remove the Service and release its slug without retrying.

svc.refresh()

Get the Service again and return its current state. This value is not changed.

Returns

The Service’s current state.

ServiceStatus

ServiceStatus.ENABLED”enabled”
Routes requests to its target.
ServiceStatus.DISABLED”disabled”
Retains its target without routing requests.
ServiceStatus.DETACHED”detached”
Has no target.
ServiceStatus.UNKNOWN”unknown”
The backend returned an unrecognized status.

ServiceTarget

A frozen dataclass; targets compare by value.
sandboxstr
Current name of the target sandbox.
portint
Sandbox port, 1 through 65535. A negative number or one above 65535 raises OverflowError before any request.

ServicePage

Services in this page, in slug order.
next_cursorstr | None
Cursor for the next page, or None on the final page.

ServiceError

A refused Service change or an unknown outcome. A missing Service raises ServiceNotFoundError, an unavailable slug raises ServiceAlreadyExistsError, and a missing target sandbox raises SandboxNotFoundError. Every exception raised by Service create, update, enable, disable, or remove carries changed, not only ServiceError: MicrosandboxError.changed is a ChangeState for those calls and None for other calls.
slugstr
Service slug.
Reason for the failure.
retry_afterfloat | None
Retry delay returned with the refusal, in seconds, or None.
ChangeState.UNKNOWN means the change may have been applied; get and check the Service.
raw_codestr | None
Raw error code of a refusal with reason OTHER, or None.
raw_statusint | None
HTTP status of a refusal with reason OTHER, or None.
raw_messagestr | None
Message of a refusal with reason OTHER, or None.

ServiceErrorReason

SERVICE_QUOTA_EXCEEDED
The organization’s Service limit was reached. Remove a Service or request a higher limit.
SANDBOX_SERVICE_LIMIT_EXCEEDED
The target sandbox’s Service limit was reached. Remove or move a Service, or request a higher limit.
SERVICE_CONFLICT
Another change to the Service committed first. Get it, then retry.
SERVICE_DETACHED
The Service is detached. Set a target.
TARGET_UNREACHABLE
The target sandbox cannot be reached right now. Retry later, after retry_after when set.
SANDBOX_NOT_RUNNING
The target sandbox is not running. Start it, then retry.
SERVICE_CHANGES_PAUSED
Service changes are paused. Retry later, after retry_after when set.
OUTCOME_UNKNOWN
The change may have been applied. Get and check the Service before retrying.
OTHER
A refusal this SDK does not recognize. raw_code, raw_status, and raw_message hold what was returned; changed still reports the outcome.

ChangeState

ChangeState.UNCHANGED”unchanged”
Nothing changed.
ChangeState.UNKNOWN”unknown”
The change may have been applied. Get and check the Service before retrying.