snowflake.core.role.RoleCollection

class snowflake.core.role.RoleCollection(root: Root)

Bases: AccountObjectCollectionParent[RoleResource]

Represents the collection operations on the Snowflake Role resource.

With this collection, you can create role or update or fetch all roles that you have access to.

Parameters:

root – A Root instance.

Example

Create a RoleCollection instance: >>> role_collection = root.roles >>> role_collection.create(new_role)

Attributes

root

Methods

__init__(root: Root) None
create(role: RoleModel, *, mode: CreateMode = CreateMode.error_if_exists) RoleResource

Create a role in Snowflake.

Parameters:
  • role – an instance of Role.

  • mode

    One of the following enum values.

    CreateMode.error_if_exists: Throw an snowflake.core.exceptions.ConflictError if the

    role already exists in Snowflake. Equivalent to SQL create role <name> ....

    CreateMode.or_replace: Replace if the role already exists in Snowflake. Equivalent to SQL

    create or replace role <name> ....

    CreateMode.if_not_exists: Do nothing if the role already exists in Snowflake. Equivalent to SQL

    create role <name> if not exists...

    Default value is CreateMode.error_if_exists.

Example

Create a role on Snowflake and get the reference to it: >>> from snowflake.core.role import Role >>> role = Role( … name=”test-role”, … comment=”samplecomment” ) >>> # Use role collection created before to create a reference to role resource in Snowflake server. >>> role_ref = root.roles.create(role)

items() ItemsView[str, T]
iter(*, like: str | None = None, limit: int | None = None, starts_with: str | None = None, from_name: str | None = None) Iterator[RoleModel]

List roles available in an account.

Args:
like: Filter the output by resource name. Uses case-insensitive pattern matching, with support for SQL

wildcard characters.

limit: Limit the maximum number of rows returned.

starts_with: filter the output based on the string of

characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.

from_name: Enable fetching roles only following the first role whose name matches the specified

string. Case-sensitive and does not have to be the full name.

Example

>>> roles = root.iter(like, starts_with, show_limit, from_name)
Copy
keys() KeysView[str]
values() ValuesView[T]