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 fetch information about a user, as well as perform certain actions on it.

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

>>> user_ref.drop()
Copy

Deleting a user using its reference if it exists:

>>> user_ref.drop(if_exists=True)
Copy
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)
Copy
fetch_async() → PollingOperation[UserModel]¶

An asynchronous version of fetch().

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

get_tags(with_lineage: bool | None = None) → dict[TagResource, TagValue]¶

Get the tag assignments for a user.

Returns all tags assigned to a user. This operation requires an active warehouse.

Parameters:

with_lineage (bool, optional) – Parameter that specifies whether tag assignments inherited by the object from its ancestors in securable object hierarchy should be returned as well: - true: All tags assigned to this object should be returned, inheritance included. - false: Only tags explicitly assigned to this object should be returned.

get_tags_async(with_lineage: bool | None = None) → PollingOperation[dict[TagResource, TagValue]]¶

An asynchronous version of get_tags().

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:
  • 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
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()
Copy
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:
  • 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
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.

set_tags(tags: dict[TagResource, TagValue], if_exists: bool | None = None) → None¶

Set tags on a user.

Parameters:
  • tags (dict[TagResource, TagValue]) – (required)

  • if_exists (bool) – Parameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn’t exist.

set_tags_async(tags: dict[TagResource, TagValue], if_exists: bool | None = None) → PollingOperation[None]¶

An asynchronous version of set_tags().

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

unset_tags(tag_resources: set[TagResource], if_exists: bool | None = None) → None¶

Unset tags from a user.

Parameters:
  • tag_resources (set[TagResource]) – (required)

  • if_exists (bool) – Parameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn’t exist.

unset_tags_async(tag_resources: set[TagResource], if_exists: bool | None = None) → PollingOperation[None]¶

An asynchronous version of unset_tags().

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