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 or update or fetch all warehouses that you have access to.

Parameters:

root – A Root instance.

Example

Create a WarehouseCollection instance:

>>> # after creating a root instance
>>> warehouse_collection = root.warehouses
Copy

Attributes

root

Methods

__init__(root: Root) None
create(warehouse: WarehouseModel, *, mode: CreateMode = CreateMode.error_if_exists) WarehouseResource

Create a warehouse in Snowflake.

Parameters:
  • warehouse – an instance of Warehouse.

  • mode

    One of the following 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.

Example

Create a warehouse on Snowflake server and get the reference to it:

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

Iterate over the list of warehouses in Snowflake, filtering on any optional like pattern.

Parameters:

like – A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).

Example

Create a warehouse on Snowflake server and get the reference to it:

>>> from snowflake.core.warehouse import Warehouse
>>> # Show all warehouses that you have access to see.
>>> warehouses = warehouse_collection.iter()
>>> # Show information of the exact warehouse you want to see.
>>> warehouses = warehouse_collection.iter(like="your-warehouse-name")
>>> # Show warehouses starting with 'your-warehouse-name-'.
>>> warehouses = warehouse_collection.iter(like="your-warehouse-name-%")
>>> # Use for loop to retrieve information from iterator.
>>> for warehouse in warehouses:
>>>     print(warehouse.name, warehouse.warehouse_size)
Copy
keys() KeysView[str]
values() ValuesView[T]