snowflake.core.stage.StageCollection¶

class snowflake.core.stage.StageCollection(schema: SchemaResource)¶

Bases: SchemaObjectCollectionParent[StageResource]

Represents the collection operations on the Snowflake Stage resource.

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

Examples

Creating a stage instance:

>>> stages = root.databases["my_db"].schemas["my_schema"].stages
>>> new_stage = Stage(
...     name="my_stage",
...     comment="This is a stage",
... )
>>> stages.create(new_stage)
Copy

Attributes

database¶

The DatabaseResource this collection belongs to.

root¶

The Root object this collection belongs to.

Methods

create(stage: Stage, *, mode: CreateMode = CreateMode.error_if_exists) → StageResource¶

Create a stage in Snowflake.

Parameters:
  • stage (Stage) – The Stage object, together with the Stage’s properties: name; kind, url, endpoint, storage_integration, comment, crendentials, encryption, directory_table are optional.

  • mode (CreateMode, optional) –

    One of the following enum values.

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

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

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

    Default is CreateMode.error_if_exists.

Examples

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

>>> stages = root.databases["my_db"].schemas["my_schema"].stages
>>> new_stage = Stage(
...     name="my_stage",
...     comment="This is a stage",
... )
>>> stages.create(new_stage, mode=CreateMode.or_replace)
Copy
create_async(stage: Stage, *, mode: CreateMode = CreateMode.error_if_exists) → PollingOperation[StageResource]¶

An asynchronous version of create().

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

items() → ItemsView[str, T]¶
iter(*, like: str | None = None) → Iterator[Stage]¶

Iterate through Stage 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 _).

Examples

Showing all stages that you have access to see:

>>> stages = stage_collection.iter()
Copy

Showing information of the exact stage you want to see:

>>> stages = stage_collection.iter(like="your-stage-name")
Copy

Showing stages starting with ‘your-stage-name-‘:

>>> stages = stage_collection.iter(like="your-stage-name-%")
Copy

Using a for loop to retrieve information from iterator:

>>> for stage in stages:
...     print(stage.name)
Copy
iter_async(*, like: str | None = None) → PollingOperation[Iterator[Stage]]¶

An asynchronous version of iter().

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

keys() → KeysView[str]¶
values() → ValuesView[T]¶