snowflake.core.service.ServiceCollection¶
- 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¶
- root¶
Methods
- create(service: Service, *, mode: CreateMode = CreateMode.error_if_exists) ServiceResource ¶
Create a Snowpark Container service in Snowflake.
- Parameters:
service (Service) – The
Service
object, together with theService
’s properties: name, compute_pool, spec; auto_resume, min_instances, max_instances, status, external_access_integrations, query_warehouse, comment are optional.mode (CreateMode, optional)
values. (One of the following enum)
CreateMode.error_if_exists (Throw an
snowflake.core.exceptions.ConflictError
).... (create or replace service <name>)
CreateMode.or_replace (Replace if the service already exists in Snowflake. Equivalent to SQL)
....
CreateMode.if_not_exists (Do nothing if the service already exists in Snowflake.)
exists... (Equivalent to SQL create service <name> if not)
CreateMode.error_if_exists. (Default is)
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)
- execute_job(job_service: JobService) ServiceResource ¶
Executes a Snowpark Container job service in Snowflake.
- Parameters:
job_service (JobService) – The
JobService
object, together with theJobService
’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)
- 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:
like (str, optional) – A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).
starts_with (str, optional) – String used to filter the command output based on the string of characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.
show_limit (int, optional) – Limit of the maximum number of rows returned by iter(). The default is
None
, which behaves equivalently to show_limit=10000. This value must be between1
and10000
.from_name (str, optional) – Fetch rows only following the first row whose object name matches the specified string. This is case-sensitive and does not have to be the full name.
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)
- keys() KeysView[str] ¶
- values() ValuesView[T] ¶