snowflake.core.service.ServiceResource¶

class snowflake.core.service.ServiceResource(name: str, collection: ServiceCollection)¶

Bases: SchemaObjectReferenceMixin[ServiceCollection]

Represents a reference to a Snowflake Snowpark Container Service.

With this service reference, you can create, alter, and fetch information about services, as well as perform certain actions on them.

Attributes

database¶
fully_qualified_name¶
root¶

Methods

create_or_alter(service: Service) → None¶

Create a service in Snowflake or alter one if it already exists.

Parameters:

service (Service) – The Service object, together with the Service’s properties: name, compute_pool, spec; auto_resume, min_instances, max_instances, status, external_access_integrations, query_warehouse, comment are optional.

Examples

Creating or updating a service in Snowflake:

>>> service_parameters = Service(
...     name="your-service-name",
...     compute_pool="my_cp"
...     spec=ServiceSpecStageFile(stage="stage_name", spec_file=spec_file),
...)
>>> services = root.databases["my_db"].schemas["my_schema"].services
>>> services["your-service-name"].create_or_alter(service_parameters)
Copy
create_or_alter_async(service: Service) → PollingOperation[None]¶

An asynchronous version of create_or_alter().

Refer to PollingOperation for more information on asynchronous execution and the return type.

delete() → None¶

The delete method is deprecated; use drop instead.

drop(if_exists: bool | None = None) → None¶

Drop the service.

Parameters:

if_exists (bool, optional) – Check the existence of this service before dropping it. Default is None, which is equivalent to False.

Examples

Deleting a service using its reference:

>>> service_reference.drop()
Copy
drop_async(if_exists: bool | None = None) → PollingOperation[None]¶

An asynchronous version of drop().

Refer to PollingOperation for more information on asynchronous execution and the return type.

fetch() → Service¶

Fetch the details of a service.

Examples

Fetching a service using its reference:

>>> service_reference.fetch()
Copy
fetch_async() → PollingOperation[Service]¶

An asynchronous version of fetch().

Refer to PollingOperation for more information on asynchronous execution and the return type.

get_containers() → Iterator[ServiceContainer]¶

Show the containers corresponding to this service.

Examples

Showing the containers of a service using its reference:

>>> service_reference.get_containers()
Copy
get_containers_async() → PollingOperation[Iterator[ServiceContainer]]¶

An asynchronous version of get_containers().

Refer to PollingOperation for more information on asynchronous execution and the return type.

get_endpoints() → Iterator[ServiceEndpoint]¶

Show the endpoints corresponding to this service.

Examples

Showing the endpoints of a service using its reference:

>>> service_reference.get_endpoints()
Copy
get_endpoints_async() → PollingOperation[Iterator[ServiceEndpoint]]¶

An asynchronous version of get_endpoints().

Refer to PollingOperation for more information on asynchronous execution and the return type.

get_instances() → Iterator[ServiceInstance]¶

Show the instances corresponding to this service.

Examples

Showing the instances of a service using its reference:

>>> service_reference.get_instances()
Copy
get_instances_async() → PollingOperation[Iterator[ServiceInstance]]¶

An asynchronous version of get_instances().

Refer to PollingOperation for more information on asynchronous execution and the return type.

get_roles() → Iterator[ServiceRole]¶

Show the roles corresponding to this service.

Examples

Showing the roles of a service using its reference:

>>> service_reference.get_roles()
Copy
get_roles_async() → PollingOperation[Iterator[ServiceRole]]¶

An asynchronous version of get_roles().

Refer to PollingOperation for more information on asynchronous execution and the return type.

get_service_logs(instance_id: str, container_name: str, num_lines: int | None = None) → str¶

Get the service logs of the service.

Parameters:
  • instance_id (str) – Instance ID of the service.

  • container_name (str) – Container name of the service.

  • num_lines (int, optional) – Number of the most recent log lines to retrieve.

get_service_status() returns the instance_id and container_name as a part of its results.

Examples

Getting the logs of a service using its reference:

>>> service_reference.get_service_logs(instance_id="instance_id", container_name="container_name")
Copy
get_service_logs_async(instance_id: str, container_name: str, num_lines: int | None = None) → PollingOperation[str]¶

An asynchronous version of get_service_logs().

Refer to PollingOperation for more information on asynchronous execution and the return type.

get_service_status(timeout: int = 0) → list[dict[str, Any]]¶

Get the status of the service.

Parameters:

timeout (int) –

Number of seconds to wait for the service to reach a steady state (for example, READY) before returning the status. If the service does not reach steady state within the specified time, Snowflake returns the current state.

If not specified or 0, Snowflake returns the current state immediately.

Default: 0 seconds.

Examples

Getting the status of a service using its reference:

>>> service_reference.get_service_status()
Copy

Getting the status of a service using its reference with a timeout:

>>> service_reference.get_service_status(timeout=10)
Copy
get_service_status_async(timeout: int = 0) → PollingOperation[list[dict[str, Any]]]¶

An asynchronous version of get_service_status().

Refer to PollingOperation for more information on asynchronous execution and the return type.

iter_grants_of_service_role(role_name: str) → Iterator[GrantOf]¶

Show the grants of the service role associated with this service.

Parameters:

role_name (str) – Name of the service role.

Examples

Showing the grants of the service role associated with a service using the service reference:

>>> service_reference.iter_grants_of_service_role("all_endpoints_usage")
Copy
iter_grants_of_service_role_async(role_name: str) → PollingOperation[Iterator[GrantOf]]¶

An asynchronous version of iter_grants_of_service_role().

Refer to PollingOperation for more information on asynchronous execution and the return type.

iter_grants_to_service_role(role_name: str) → Iterator[ServiceRoleGrantTo]¶

Show the grants given to the service role associated with this service.

Parameters:

role_name (str) – Name of the service role.

Examples

Showing the grants given to the service role associated with a service using the service reference:

>>> service_reference.iter_grants_to_service_role("all_endpoints_usage")
Copy
iter_grants_to_service_role_async(role_name: str) → PollingOperation[Iterator[ServiceRoleGrantTo]]¶

An asynchronous version of iter_grants_to_service_role().

Refer to PollingOperation for more information on asynchronous execution and the return type.

resume(if_exists: bool | None = None) → None¶

Resumes the service.

Parameters:

if_exists (bool, optional) – Check the existence of this service before resuming it. Default is None, which is equivalent to False.

Examples

Resuming a service using its reference:

>>> service_reference.resume()
Copy
resume_async(if_exists: bool | None = None) → PollingOperation[None]¶

An asynchronous version of resume().

Refer to PollingOperation for more information on asynchronous execution and the return type.

suspend(if_exists: bool | None = None) → None¶

Suspend the service.

Parameters:

if_exists (bool, optional) – Check the existence of this service before suspending it. Default is None, which is equivalent to False.

Examples

Suspending a service using its reference:

>>> service_reference.suspend()
Copy
suspend_async(if_exists: bool | None = None) → PollingOperation[None]¶

An asynchronous version of suspend().

Refer to PollingOperation for more information on asynchronous execution and the return type.