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
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
fetch() → Service¶

Fetch the details of a service.

Examples

Fetching a service using its reference:

>>> service_reference.fetch()
Copy
get_containers() → Iterable[ServiceContainer]¶

Show the containers corresponding to this service.

Examples

Showing the containers of a service using its reference:

>>> service_reference.get_containers()
Copy
get_endpoints() → Iterable[ServiceEndpoint]¶

Show the endpoints corresponding to this service.

Examples

Showing the endpoints of a service using its reference:

>>> service_reference.get_endpoints()
Copy
get_instances() → Iterable[ServiceInstance]¶

Show the instances corresponding to this service.

Examples

Showing the instances of a service using its reference:

>>> service_reference.get_instances()
Copy
get_roles() → Iterable[ServiceRole]¶

Show the roles corresponding to this service.

Examples

Showing the roles of a service using its reference: >>> service_reference.get_roles()

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_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
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
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