snowflake.core.role.RoleCollection | Snowflake Documentation (original) (raw)

DeveloperSnowflake Python APIsSnowflake Python APIs referencerolerole.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" ... ))

Attributes

root

The Root object this collection belongs to.

Methods

create(role: RoleModel, *, mode: CreateMode = CreateMode.error_if_exists) → RoleResource

Create a role in Snowflake.

Parameters:

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)

create_async(role: RoleModel, *, mode: CreateMode = CreateMode.error_if_exists) → PollingOperation[RoleResource]

An asynchronous version of create().

Refer to PollingOperation for more information on asynchronous execution and the return type.

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:

Examples

Showing all roles that you have access to see:

roles = role_collection.iter()

Showing information of the exact role you want to see:

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

Showing roles starting with ‘your-role-name-‘:

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

Using a for loop to retrieve information from iterator:

for role in roles: ... print(role.name, role.comment)

iter_async(*, like: str | None = None, limit: int | None = None, starts_with: str | None = None, from_name: str | None = None) → PollingOperation[Iterator[RoleModel]]

An asynchronous version of iter().

Refer to PollingOperation for more information on asynchronous execution and the return type.

keys() → KeysView[str]

values() → ValuesView[T]