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, iterate through, and search for roles that you have access to in the current context.

Examples

Creating a role instance:

>>> role_collection = root.roles
>>> role_collection.create(Role(
...     name="test-role",
...     comment="samplecomment"
... ))
Copy

Attributes

rootΒΆ

Methods

create(role: RoleModel, *, mode: CreateMode = CreateMode.error_if_exists) β†’ RoleResourceΒΆ

Create a role in Snowflake.

Parameters:
  • role (Role) – The Role object, together with the Role’s properties: name ; comment is optional

  • mode (CreateMode, optional) –

    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 is CreateMode.error_if_exists.

Examples

Creating a role, replacing any existing role with the same name:

>>> role = Role(
...     name="test-role",
...     comment="samplecomment"
... )
>>> role_ref = root.roles.create(role, mode=CreateMode.or_replace)
Copy
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]ΒΆ

Iterate through Role objects from Snowflake, filtering on any optional β€˜like’ pattern.

Parameters:
  • like (str, optional) – A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).

  • starts_with (str, optional) – String used to filter the command output based on the string of characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.

  • show_limit (int, optional) – Limit of the maximum number of rows returned by iter(). The default is None, which behaves equivalently to show_limit=10000. This value must be between 1 and 10000.

  • from_name (str, optional) – Fetch rows only following the first row whose object name matches the specified string. This is case-sensitive and does not have to be the full name.

Examples

Showing all roles that you have access to see:

>>> roles = role_collection.iter()
Copy

Showing information of the exact role you want to see:

>>> roles = role_collection.iter(like="your-role-name")
Copy

Showing roles starting with β€˜your-role-name-β€˜:

>>> roles = role_collection.iter(like="your-role-name-%")
>>> roles = role_collection.iter(starts_with="your-role-name")
Copy

Using a for loop to retrieve information from iterator:

>>> for role in roles:
...    print(role.name, role.comment)
Copy
keys() β†’ KeysView[str]ΒΆ
values() β†’ ValuesView[T]ΒΆ