snowflake.core.stream.StreamCollection | Snowflake Documentation (original) (raw)

class snowflake.core.stream.StreamCollection(schema: SchemaResource)

Bases: SchemaObjectCollectionParent[StreamResource]

Represents the collection operations on the Snowflake Stream resource.

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

Attributes

database

The DatabaseResource this collection belongs to.

root

The Root object this collection belongs to.

Methods

create(stream: str, *, clone_stream: str | Clone, mode: CreateMode = CreateMode.error_if_exists, copy_grants: bool | None = False) → StreamResource

create(stream: Stream, *, mode: CreateMode = CreateMode.error_if_exists, copy_grants: bool | None = False) → StreamResource

Create a stream in Snowflake.

There are two ways to create a stream: by cloning or by building from scratch.

Cloning an existing stream

Parameters:

Examples

Cloning a Stream instance:

streams = schema.streams streams.create( ... "new_stream_name", ... clone_stream="stream_name_to_be_cloned", ... mode=CreateMode.if_not_exists, ... copy_grants=True ... )

Cloning a Stream instance in a different database and schema

streams = schema.streams streams.create( ... "new_stream_name", ... clone_stream="stream_database_name.stream_schema_name.stream_name_to_be_cloned", ... mode=CreateMode.if_not_exists, ... copy_grants=True ... )

Creating a stream from scratch

Parameters:

Examples

Creating a stream instance by source table:

streams.create( ... Stream( ... name = "new_stream_name", ... stream_source = StreamSourceTable( ... point_of_time = PointOfTimeOffset(reference="before", offset="1"), ... name = "my_source_table_name" ... append_only = True, ... show_initial_rows = False, ... comment = "create stream by table" ... ) ... ), ... mode=CreateMode.if_not_exists, ... copy_grants=True ... )

Creating a stream instance by source view:

streams.create( ... Stream( ... name = "new_stream_name", ... stream_source = StreamSourceView( ... point_of_time = PointOfTimeOffset(reference="before", offset="1"), ... name = "my_source_view_name" ... ) ... ), ... mode=CreateMode.if_not_exists, ... copy_grants=True ... )

Creating a stream instance by source directory table:

streams.create( ... Stream( ... name = "new_stream_name", ... stream_source = StreamSourceStage( ... point_of_time = PointOfTimeOffset(reference="before", offset="1"), ... name = "my_source_directory_table_name" ... ) ... ), ... mode=CreateMode.if_not_exists, ... copy_grants=True ... )

create_async(stream: str, *, clone_stream: str | Clone, mode: CreateMode = CreateMode.error_if_exists, copy_grants: bool | None = False) → PollingOperation['StreamResource']

create_async(stream: Stream, *, mode: CreateMode = CreateMode.error_if_exists, copy_grants: bool | None = False) → PollingOperation['StreamResource']

An asynchronous version of create().

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

items() → ItemsView[str, T]

iter(*, like: Annotated[str, Strict(strict=True)] | None = None, starts_with: Annotated[str, Strict(strict=True)] | None = None, show_limit: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=1), Le(le=10000)])] | None = None, from_name: Annotated[str, Strict(strict=True)] | None = None) → Iterator[Stream]

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

Parameters:

Examples

Showing all streams that you have access to see:

streams = stream_collection.iter()

Showing information of the exact stream you want to see:

streams = stream_collection.iter(like="your-stream-name")

Showing streams starting with ‘your-stream-name-‘:

streams = stream_collection.iter(like="your-stream-name-%")

Using a for loop to retrieve information from iterator:

for stream in streams: ... print(stream.name)

iter_async(*, like: Annotated[str, Strict(strict=True)] | None = None, starts_with: Annotated[str, Strict(strict=True)] | None = None, show_limit: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=1), Le(le=10000)])] | None = None, from_name: Annotated[str, Strict(strict=True)] | None = None) → PollingOperation[Iterator[Stream]]

An asynchronous version of iter().

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

keys() → KeysView[str]

values() → ValuesView[T]