snowflake.core.user.UserResource | Snowflake Documentation (original) (raw)

class snowflake.core.user.UserResource(name: str, collection: UserCollection)

Bases: ObjectReferenceMixin[UserCollection]

Represents a reference to a Snowflake user.

With this user reference, you can create or alter, delete and fetch information about users, as well as perform certain actions on them.

Attributes

root

The Root object this reference belongs to.

Methods

create_or_alter(user: UserModel) → None

Create a user in Snowflake or alter one if it already exists.

Parameters:

user (User) – The User object, together with the User’s properties: name; password, login_name, display_name, first_name, middle_name, last_name, email, must_change_password, disabled, days_to_expiry, mins_to_unlock, default_warehouse, default_namespace, default_role, default_secondary_roles, mins_to_bypass_mfa, rsa_public_key, rsa_public_key_fp, rsa_public_key_2, rsa_public_key_2_fp, comment, type, enable_unredacted_query_syntax_error, network_policy are optional

Examples

Creating a user or altering one if it already exists:

user_parameters = User( ... name="User1", ... first_name="Snowy", ... last_name="User", ... must_change_password=False ...) user_reference.create_or_alter(user_parameters)

create_or_alter_async(user: UserModel) → PollingOperation[None]

An asynchronous version of create_or_alter().

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

delete() → None

The delete method is deprecated; use drop instead.

drop(if_exists: bool | None = None) → None

Drop this user.

Parameters:

if_exists (bool , optional) – Check the existence of this user before dropping it. Default is None, which is equivalent to False.

Examples

Deleting a user using its reference:

Deleting a user using its reference if it exists:

user_ref.drop(if_exists=True)

drop_async(if_exists: bool | None = None) → PollingOperation[None]

An asynchronous version of drop().

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

fetch() → UserModel

Fetch the details of a user.

Examples

Fetching a reference to a user to print its informations:

user_ref = root.users["test_user"].fetch() print(user_ref.name, user_ref.first_name)

fetch_async() → PollingOperation[UserModel]

An asynchronous version of fetch().

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

grant_role(role_type: str, role: Securable) → None

Grant a role to this user.

Parameters:

Examples

Using a user reference to grant a role to it:

user_reference.grant_role("role", Securable(name="test_role"))

grant_role_async(role_type: str, role: Securable) → PollingOperation[None]

An asynchronous version of grant_role().

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

iter_grants_to() → Iterator[Grant]

List grants to this user.

Lists all roles granted to the user.

Examples

Using a user reference to list grants to it:

user_reference.iter_grants_to()

iter_grants_to_async() → PollingOperation[Iterator[Grant]]

An asynchronous version of iter_grants_to().

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

revoke_role(role_type: str, role: Securable) → None

Revoke a role from this user.

Parameters:

Examples

Using a user reference to revoke a role from it:

user_reference.revoke_role("role", Securable(name="test_role"))

revoke_role_async(role_type: str, role: Securable) → PollingOperation[None]

An asynchronous version of revoke_role().

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