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 is None, which is equivalent to False.

  • 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")
Copy
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")
Copy
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 is False.

Examples

Deleting a notebook using its reference:

>>> notebook_reference.drop()
Copy

Using a notebook reference to delete a notebook if it exists:

>>> notebook_reference.drop(if_exists=True)
Copy
execute() β†’ NoneΒΆ

Execute this notebook.

Examples

Executing a notebook using its reference:

>>> notebook_reference.execute()
Copy
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)
Copy
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 to False.

Examples

Renaming this notebook using its reference:

>>> notebook_reference.rename("my_other_notebook")
Copy

Renaming this notebook if it exists:

>>> notebook_reference.rename("my_other_notebook", if_exists = True)
Copy