snowflake.core.service.ServiceCollection | Snowflake Documentation (original) (raw)

class snowflake.core.service.ServiceCollection(schema: SchemaResource)

Bases: SchemaObjectCollectionParent[ServiceResource]

Represents the collection operations on the Snowflake Snowpark Container Service resource.

With this collection, you can create, update, iterate through, and fetch SPCSs that you have access to in the current context.

Examples

Creating a service instance:

my_service = Service( ... name="my_service", ... min_instances=1, ... max_instances=2, ... compute_pool="my_compute_pool", ... spec=ServiceSpec("@my_stage/my_service_spec.yaml") ... ) root.databases["my_db"].schemas["my_schema"].services.create(my_service)

Attributes

database

The DatabaseResource this collection belongs to.

root

The Root object this collection belongs to.

Methods

create(service: Service, *, mode: CreateMode = CreateMode.error_if_exists) → ServiceResource

Create a Snowpark Container service in Snowflake.

Parameters:

Examples

Creating a service, replacing any existing service with the same name:

services = root.databases["my_db"].schemas["my_schema"].services my_service = Service( ... name="my_service", ... compute_pool="my_compute_pool", ... spec=ServiceSpec("@my_stage/my_service_spec.yaml") ... ) services.create(my_service, mode=CreateMode.or_replace)

create_async(service: Service, *, mode: CreateMode = CreateMode.error_if_exists) → PollingOperation[ServiceResource]

An asynchronous version of create().

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

execute_job(job_service: JobService) → ServiceResource

Execute a Snowpark Container job service in Snowflake.

Parameters:

job_service (JobService) – The JobService object, together with the JobService’s properties: name, compute_pool, spec; status, external_access_integrations, query_warehouse, comment are optional

Examples

Executing a job service:

job_service = JobService( ... name="my_job_service", ... compute_pool="my_cp", ... spec=ServiceSpec("@my_stage/my_service_spec.yaml"), ... ) services.execute_job(job_service)

execute_job_async(job_service: JobService) → PollingOperation[ServiceResource]

An asynchronous version of execute_job().

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

items() → ItemsView[str, T]

iter(*, like: str | None = None, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None) → Iterator[Service]

Iterate through Service objects from Snowflake, filtering on any optional ‘like’ pattern.

Parameters:

Examples

Showing all services that you have access to see:

services = service_collection.iter()

Showing information of the exact service you want to see:

services = service_collection.iter(like="your-service-name")

Showing services starting with ‘your-service-name-‘:

services = service_collection.iter(like="your-service-name-%")

Using a for loop to retrieve information from iterator:

for service in services: print(service.name)

iter_async(*, like: str | None = None, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None) → PollingOperation[Iterator[Service]]

An asynchronous version of iter().

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

keys() → KeysView[str]

values() → ValuesView[T]