snowflake.core.warehouse.WarehouseCollection

class snowflake.core.warehouse.WarehouseCollection(root: Root)

Bases: AccountObjectCollectionParent[WarehouseResource]

Represents the collection operations of the Snowflake Warehouse resource.

With this collection, you can create, iterate through, and search for warehouses that you have access to in the current context.

Examples

Creating a warehouse instance:

>>> warehouses = root.warehouses
>>> new_wh = Warehouse(
...     name="my_wh",
...     warehouse_size="XSMALL")
>>> warehouses.create(new_wh)
Copy

Attributes

root

Methods

create(warehouse: WarehouseModel, *, mode: CreateMode = CreateMode.error_if_exists) WarehouseResource

Create a warehouse in Snowflake.

Parameters:
  • warehouse (Warehouse)

  • mode (CreateMode, optional) –

    One of the below enum values.

    CreateMode.error_if_exists: Throw an snowflake.core.exceptions.ConflictError if the warehouse already exists in Snowflake. Equivalent to SQL create warehouse <name> ....

    CreateMode.or_replace: Replace if the warehouse already exists in Snowflake. Equivalent to SQL create or replace warehouse <name> ....

    CreateMode.if_not_exists: Do nothing if the warehouse already exists in Snowflake. Equivalent to SQL create warehouse <name> if not exists...

    Default value is CreateMode.error_if_exists.

Examples

Creating a warehouse in Snowflake and getting the reference to it:

>>> warehouse_parameters = Warehouse(
...     name="your-warehouse-name",
...     warehouse_size="SMALL",
...     auto_suspend=500,
...)
Copy
>>> # Use the warehouse collection created before to create a reference to a warehouse resource
>>> # in Snowflake.
>>> warehouse_reference = warehouse_collection.create(warehouse_parameters)
Copy
items() ItemsView[str, T]
iter(*, like: str | None = None) Iterator[WarehouseModel]

Iterate through Warehouse objects in 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 _).

Examples

Showing all warehouses that you have access to see:

>>> warehouses = warehouse_collection.iter()
Copy

Showing information of the exact warehouse you want to see:

>>> warehouses = warehouse_collection.iter(like="your-warehouse-name")
Copy

Showing warehouses starting with ‘your-warehouse-name-‘:

>>> warehouses = warehouse_collection.iter(like="your-warehouse-name-%")
Copy

Using a for loop to retrieve information from iterator:

>>> for warehouse in warehouses:
>>>     print(warehouse.name, warehouse.warehouse_size)
Copy
keys() KeysView[str]
values() ValuesView[T]