snowflake.core.user.UserResource

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

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)
Copy
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:

>>> user_ref.drop()
Copy

Deleting a user using its reference if it exists:

>>> user_ref.drop(if_exists=True)
Copy
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)
Copy
grant_role(role_type: str, role: Securable) None

Grant a role to this user.

Parameters:
  • role_type (str) – The type of role which would be granted.

  • role (Securable) – The role which would be granted.

Examples

Using a user reference to grant a role to it:

>>> user_reference.grant_role("role", Securable(name="test_role"))
Copy
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()
Copy
revoke_role(role_type: str, role: Securable) None

Revoke a role from this user.

Parameters:
  • role_type (str) – The type of role which would be revoked.

  • role (Securable) – The role which would be revoked.

Examples

Using a user reference to revoke a role from it:

>>> user_reference.revoke_role("role", Securable(name="test_role"))
Copy
Language: English