snowflake.core.notebook.NotebookCollection¶
- class snowflake.core.notebook.NotebookCollection(schema: SchemaResource)¶
Bases:
SchemaObjectCollectionParent
[NotebookResource
]Represents the collection operations of the Snowflake Notebook resource.
With this collection, you can create, iterate through, and search for notebooks that you have access to in the current context.
Examples
Creating a notebook instance:
>>> notebooks = root.databases["my_db"].schemas["my_schema"].notebooks >>> new_notebook = Notebook( ... name="my_notebook", ... comment="This is a notebook" ... ) >>> notebooks.create(new_notebook)
Attributes
- database¶
- root¶
Methods
- create(notebook: Notebook, *, mode: CreateMode = CreateMode.error_if_exists) NotebookResource ¶
Create a notebook in Snowflake.
- Parameters:
notebook (Notebook) – The
Notebook
object that you want to create in Snowflake.mode (CreateMode, optional) –
One of the following strings.
CreateMode.error_if_exists
: Throw ansnowflake.core.exceptions.ConflictError
if the notebook already exists in Snowflake. Equivalent to SQLcreate notebook <name> ...
.CreateMode.or_replace
: Replace if the notebook already exists in Snowflake. Equivalent to SQLcreate or replace notebook <name> ...
.CreateMode.if_not_exists
: Do nothing if the notebook already exists in Snowflake. Equivalent to SQLcreate notebook <name> if not exists...
Default value is
CreateMode.error_if_exists
.
Examples
Creating a notebook in Snowflake and getting the reference to it:
>>> notebook = Notebook( ... name="my_notebook", ... version="notebook_ver1", ... comment="This is a notebook" ... ) >>> # Use the notebook collection created before to create a reference to the notebook resource >>> # in Snowflake. >>> notebook_reference = notebook_collection.create(notebook)
- items() ItemsView[str, T] ¶
- iter(*, like: str | 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[Notebook] ¶
Iterate through
Notebook
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 _).
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 notebooks that you have access to see:
>>> notebooks = notebook_collection.iter()
Showing information of the exact notebook you want to see:
>>> notebooks = notebook_collection.iter(like="your-notebook-name")
Showing notebooks starting with ‘your-notebook-name’:
>>> notebooks = notebook_collection.iter(like="your-notebook-name%")
Using a for-loop to retrieve information from iterator:
>>> for notebook in notebooks: ... print(notebook.name, notebook.version, notebook.user_packages)
- keys() KeysView[str] ¶
- values() ValuesView[T] ¶