snowflake.core.Root¶

class snowflake.core.Root(connection: SnowflakeConnection | Session, root_config: RootConfiguration | None = None)¶

Bases: object

The entry point of the Snowflake Core Python APIs that manage the Snowflake objects.

Parameters:

connection (Union[SnowflakeConnection, Session]) – A SnowflakeConnection or Snowpark Session instance.

Examples

Creating a Root instance:

>>> from snowflake.connector import connect
>>> from snowflake.core import Root
>>> from snowflake.snowpark import Session
>>> CONNECTION_PARAMETERS = {
...    "account": os.environ["snowflake_account_demo"],
...    "user": os.environ["snowflake_user_demo"],
...    "password": os.environ["snowflake_password_demo"],
...    "database": test_database,
...    "warehouse": test_warehouse,
...    "schema": test_schema,
... }
>>> # create from a Snowflake Connection
>>> connection = connect(**CONNECTION_PARAMETERS)
>>> root = Root(connection)
>>> # or create from a Snowpark Session
>>> session = Session.builder.config(CONNECTION_PARAMETERS).create()
>>> root = Root(session)
Copy

Using the Root instance to access resource management APIs:

>>> tasks = root.databases["mydb"].schemas["myschema"].tasks
>>> mytask = tasks["mytask"]
>>> mytask.resume()
>>> compute_pools = root.compute_pools
>>> my_computepool = compute_pools["mycomputepool"]
>>> my_computepool.delete()
Copy

Attributes

accounts¶

Returns the AccountCollection that represents the visible accounts.

Examples

Getting a specific account resource:

>>> root = Root(session)
>>> my_account = root.accounts["my_account"]
Copy
catalog_integrations¶

Returns the CatalogIntegrationCollection that represents the visible catalog integrations.

Examples

Getting a specific catalog integration resource:

>>> root = Root(session)
>>> my_catalog_integration = root.catalog_integrations["my_catalog_integration"]
Copy
compute_pools¶

Returns the ComputePoolCollection that represents the visible compute pools.

Examples

Getting a specific compute pool resource:

>>> root = Root(session)
>>> my_cp = root.compute_pools["my_cp"]
Copy
connection¶

Return the connection in use.

This is the connection used to create this Root instance, or the Snowpark session’s connection if this root is created from a session.

cortex_chat_service¶

Returns the CortexChatService that represents the cortex chat service.

Examples

To get the cortex chat service resource, you can do the following:

>>> root = Root(session)
>>> my_cortex_chat_service = root.cortex_chat_service
Copy
cortex_inference_service¶

Returns the CortexInferenceService that represents the cortex inference service.

Examples

Getting the cortex inference service resource:

>>> root = Root(session)
>>> my_cortex_inference_service = root.cortex_inference_service
Copy
databases¶

Returns the DatabaseCollection that represents the visible databases.

Examples

Getting a specific database resource:

>>> root = Root(session)
>>> my_db = root.databases["my_db"]
Copy
external_volumes¶

Returns the ExternalVolumeCollection that represents the visible external volumes.

Examples

Getting a specific external volume resource:

>>> root = Root(session)
>>> my_external_volume = root.external_volumes["my_external_volume"]
Copy
grants¶

Returns the visible Grants in Snowflake.

Examples

Using the Grants object to grant a privilege to a role:

>>> grants.grant(
...    Grant(
...        grantee=Grantees.role(name="public"),
...        securable=Securables.database("invaliddb123"),
...        privileges=[Privileges.create_database],
...        grant_option=False,
...    )
... )
Copy
managed_accounts¶

Returns the ManagedAccountCollection that represents the visible accounts.

Examples

Getting a specific managed account resource:

>>> root = Root(session)
>>> my_managed_account = root.managed_accounts["my_managed_account"]
Copy
network_policies¶

Returns the NetworkPolicyCollection that represents the visible network policies.

Examples

Getting a specific network policy resource:

>>> root = Root(session)
>>> my_network_policy = root.network_policies["my_network_policy"]
Copy
notification_integrations¶

Returns the NotificationIntegrationCollection that represents the visible notification integrations.

Examples

Listing all available Notification Integrations:

>>> root = Root(session)
>>> my_nis = list(root.notification_integrations.iter())
Copy
roles¶

Returns the RoleCollection that represents the visible roles.

Examples

Getting a specific role resource:

>>> root = Root(session)
>>> my_role = root.roles["my_role"]
Copy
root_config¶

Return the root configuration object.

session¶

Returns the session that is used to create this Root instance.

users¶

Returns the UserCollection that represents the visible users.

Examples

Getting a specific user resource:

>>> root = Root(session)
>>> my_user = root.users["my_user"]
Copy
warehouses¶

Returns the WarehouseCollection that represents the visible warehouses.

Examples

Getting a specific warehouse resource:

>>> root = Root(session)
>>> my_wh = root.warehouses["my_wh"]
Copy

Methods

parameters(refresh: bool = False) → SnowApiParameters¶