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)