snowflake.core.Root | Snowflake Documentation (original) (raw)

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)

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()

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"]

api_integrations

Returns the ApiIntegrationCollection that represents the visible API integrations.

Examples

Getting a specific API integration resource:

root = Root(session) my_api_int = root.api_integrations["my_api_int"]

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"]

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"]

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_agent_service

Returns the CortexAgentService that represents the cortex lite Agent service.

Examples

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

root = Root(session) my_cortex_agent_service = root.cortex_agent_service

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

cortex_embed_service

Returns the CortexEmbedService that represents the cortex embed service.

Examples

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

root = Root(session) my_cortex_embed_service = root.cortex_embed_service

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

databases

Returns the DatabaseCollection that represents the visible databases.

Examples

Getting a specific database resource:

root = Root(session) my_db = root.databases["my_db"]

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"]

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, ... ) ... )

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"]

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"]

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())

roles

Returns the RoleCollection that represents the visible roles.

Examples

Getting a specific role resource:

root = Root(session) my_role = root.roles["my_role"]

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"]

warehouses

Returns the WarehouseCollection that represents the visible warehouses.

Examples

Getting a specific warehouse resource:

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

Methods

parameters(refresh: bool = False) → SnowApiParameters