snowflake.core.notebook.NotebookResourceΒΆ
- class snowflake.core.notebook.NotebookResource(name: str, collection: NotebookCollection)ΒΆ
Bases:
SchemaObjectReferenceMixin
[NotebookCollection
]Represents a reference to a Snowflake notebook.
With this notebook reference, you can fetch information about notebooks, as well as perform certain actions on them: renaming, executing, committing, and managing versions.
Attributes
- databaseΒΆ
- fully_qualified_nameΒΆ
- rootΒΆ
Methods
- add_live_version(from_last: bool | None = None, comment: str | None = None) None ΒΆ
Add a LIVE version to the notebook.
The LIVE version is the version that runs when the notebook is executed.
- Parameters:
from_last (bool, optional) β If
True
, the LIVE version is set to the LAST version of the notebook. The default isNone
, which is equivalent toFalse
.comment (str, optional) β An optional comment to for the version of the notebook.
Examples
Adding a LIVE version to this notebook using its reference:
>>> notebook_reference.add_live_version(from_last=True, ... comment="new live version")
- commit(version: str | None = None, comment: str | None = None) None ΒΆ
Commit the LIVE version of the notebook to the Git.
If a Git connection is set up for the notebook, commits the LIVE version of the notebook to the Git repository.
If no Git repository is set up for the notebook, running this command sets the LIVE version to null and increments the auto-generated version alias.
- Parameters:
version (str, optional) β The alias of the version of the notebook that you want to commit. The default is
None
, which is equivalent to"LIVE"
.comment (str, optional) β An optional comment to add to the commit.
Examples
Committing a notebook using its reference:
>>> notebook_reference.commit(version="prod-1.1.0", ... comment="prod release 1.1.0")
- drop(if_exists: bool = False) None ΒΆ
Drop this notebook.
- Parameters:
if_exists (bool, optional) β If
True
, does not throw an exception if the notebook does not exist. The default isFalse
.
Examples
Deleting a notebook using its reference:
>>> notebook_reference.drop()
Using a notebook reference to delete a notebook if it exists:
>>> notebook_reference.drop(if_exists=True)
- execute() None ΒΆ
Execute this notebook.
Examples
Executing a notebook using its reference:
>>> notebook_reference.execute()
- fetch() Notebook ΒΆ
Fetch the details of a notebook resource.
Examples
Fetching a notebook using its reference:
>>> notebook = notebook_reference.fetch() >>> print(notebook.name, notebook.comment)
- rename(target_name: str, target_database: str | None = None, target_schema: str | None = None, if_exists: bool | None = None) None ΒΆ
Rename this notebook.
- Parameters:
target_name (str) β The new name of the notebook
target_database (str, optional) β The new database name of the notebook. If not provided, the current database name is used. The default is
None
.target_schema (str, optional) β The new schema name of the notebook. If not provided, the current schema name is used. The default is
None
.if_exists (bool, optional) β Whether to check for the existence of notebook before renaming. The default is
None
, which is equivalent toFalse
.
Examples
Renaming this notebook using its reference:
>>> notebook_reference.rename("my_other_notebook")
Renaming this notebook if it exists:
>>> notebook_reference.rename("my_other_notebook", if_exists = True)