connect.users

connect.users

User resources.

Classes

Name Description
User
UserGroups
Users Users resource.

User

connect.users.User(self, ctx, /, **kwargs)

Attributes

Name Description
content
groups Retrieve the groups to which the user belongs.

Classes

Name Description
UpdateUser Update user request.
UpdateUser
connect.users.User.UpdateUser()

Update user request.

Attributes
Name Description
email
first_name
last_name
user_role
username

Methods

Name Description
lock Lock the user account.
unlock Unlock the user account.
update Update the user’s attributes.
lock
connect.users.User.lock(force=False)

Lock the user account.

You cannot unlock your own account unless you have administrative privileges. Once an account is locked, only an admin can unlock it.

Parameters
Name Type Description Default
force bool If True, overrides lock protection allowing a user to lock their own account. Default is False. False
Returns
Name Type Description
None
Examples

Lock another user’s account:

>>> user.lock()

Attempt to lock your own account (will raise RuntimeError unless force is set to True):

>>> user.lock(force=True)
See Also
  • https://docs.posit.co/connect/api/#post-/v1/users/-guid-/lock
unlock
connect.users.User.unlock()

Unlock the user account.

This method unlocks the specified user’s account. You must have administrative privileges to unlock accounts other than your own.

Returns
Name Type Description
None
Examples

Unlock a user’s account:

>>> user.unlock()
See Also
  • https://docs.posit.co/connect/api/#post-/v1/users/-guid-/lock
update
connect.users.User.update(**kwargs)

Update the user’s attributes.

Parameters
Name Type Description Default
email (str, not required) The new email address for the user. Default is None. required
username (str, not required) The new username for the user. Default is None. required
first_name (str, not required) The new first name for the user. Default is None. required
last_name (str, not required) The new last name for the user. Default is None. required
user_role (Literal['administrator', 'publisher', 'viewer'], not required) The new role for the user. Options are 'administrator', 'publisher', 'viewer'. Default is None. required
Returns
Name Type Description
None
Examples

Update the user’s email and role:

>>> user.update(email="newemail@example.com", user_role="publisher")

Update the user’s first and last name:

>>> user.update(first_name="Jane", last_name="Smith")
See Also
  • https://docs.posit.co/connect/api/#put-/v1/users/-guid-

UserGroups

connect.users.UserGroups(self, ctx, user_guid)

Methods

Name Description
add Add the user to the specified group.
delete Remove the user from the specified group.
find Retrieve the groups to which the user belongs.
add
connect.users.UserGroups.add(group)

Add the user to the specified group.

Parameters
Name Type Description Default
group str | Group The group guid or Group object to which the user will be added. required
Examples
from posit.connect import Client

client = Client("https://posit.example.com", "API_KEY")

group = client.groups.get("GROUP_GUID_HERE")
user = client.users.get("USER_GUID_HERE")

# Add the user to the group
user.groups.add(group)

# Add the user to multiple groups
groups = [
    client.groups.get("GROUP_GUID_1"),
    client.groups.get("GROUP_GUID_2"),
]
for group in groups:
    user.groups.add(group)

# Add the user to a group by GUID
user.groups.add("GROUP_GUID_HERE")
See Also
  • https://docs.posit.co/connect/api/#post-/v1/groups/-group_guid-/members
delete
connect.users.UserGroups.delete(group)

Remove the user from the specified group.

Parameters
Name Type Description Default
group str | Group The group to which the user will be added. required
Examples
from posit.connect import Client

client = Client("https://posit.example.com", "API_KEY")

group = client.groups.get("GROUP_GUID_HERE")
user = client.users.get("USER_GUID_HERE")

# Remove the user from the group
user.groups.delete(group)

# Remove the user from multiple groups
groups = [
    client.groups.get("GROUP_GUID_1"),
    client.groups.get("GROUP_GUID_2"),
]
for group in groups:
    user.groups.delete(group)

# Remove the user from a group by GUID
user.groups.delete("GROUP_GUID_HERE")
See Also
  • https://docs.posit.co/connect/api/#delete-/v1/groups/-group_guid-/members/-user_guid-
find
connect.users.UserGroups.find()

Retrieve the groups to which the user belongs.

Returns
Name Type Description
List[Group] A list of groups to which the user belongs.
Examples
from posit.connect import Client

client = Client("https://posit.example.com", "API_KEY")

user = client.users.get("USER_GUID_HERE")
groups = user.groups.find()
See Also
  • https://docs.posit.co/connect/api/#get-/v1/groups/-group_guid-/members

Users

connect.users.Users(self, ctx)

Users resource.

Classes

Name Description
CreateUser Create user request.
FindUser Find user request.
CreateUser
connect.users.Users.CreateUser()

Create user request.

Attributes
Name Description
email
first_name
last_name
password
unique_id
user_must_set_password
user_role
username
FindUser
connect.users.Users.FindUser()

Find user request.

Attributes
Name Description
account_status
prefix
user_role

Methods

Name Description
count Return the total number of users.
create Create a new user with the specified attributes.
find Find users matching the specified conditions.
find_one Find a user matching the specified conditions.
get Retrieve a user by their unique identifier (guid).
count
connect.users.Users.count()

Return the total number of users.

Returns
Name Type Description
int
See Also
  • https://docs.posit.co/connect/api/#get-/v1/users
create
connect.users.Users.create(**attributes)

Create a new user with the specified attributes.

Applies when server setting ‘Authentication.Provider’ is set to ‘ldap’, ‘oauth2’, ‘pam’, ‘password’, ‘proxy’, or ‘saml’.

Parameters
Name Type Description Default
username (str, required) The user’s desired username. required
password (str, not required) Applies when server setting ‘Authentication.Provider=“password”’. Cannot be set when user_must_set_password is True. required
user_must_set_password (bool, not required) If True, the user is prompted to set their password on first login. When False, the password parameter is used. Default is False. Applies when server setting ‘Authentication.Provider=“password”’. required
email (str, not required) The user’s email address. required
first_name (str, not required) The user’s first name. required
last_name (str, not required) The user’s last name. required
user_role (Literal['administrator', 'publisher', 'viewer'], not required) The user role. Options are 'administrator', 'publisher', 'viewer'. Falls back to server setting ‘Authorization.DefaultUserRole’. required
unique_id str, maybe required Required when server is configured with SAML or OAuth2 (non-Google) authentication. Applies when server setting ProxyAuth.UniqueIdHeader is set. required
Returns
Name Type Description
User The newly created user.
Examples

Create a user with a predefined password:

>>> user = client.create(
...     username="jdoe",
...     email="jdoe@example.com",
...     first_name="John",
...     last_name="Doe",
...     password="s3cur3p@ssword",
...     user_role="viewer",
... )

Create a user who must set their own password:

>>> user = client.create(
...     username="jdoe",
...     email="jdoe@example.com",
...     first_name="John",
...     last_name="Doe",
...     user_must_set_password=True,
...     user_role="viewer",
... )
See Also
  • https://docs.posit.co/connect/api/#post-/v1/users
find
connect.users.Users.find(**conditions)

Find users matching the specified conditions.

Parameters
Name Type Description Default
prefix (str, not required) Filter users by prefix (username, first name, or last name). The filter is case-insensitive. required
user_role (Literal['administrator', 'publisher', 'viewer'], not required) Filter by user role. Options are 'administrator', 'publisher', 'viewer'. Use '\|' to represent logical OR (e.g., 'viewer\|publisher'). required
account_status (Literal['locked', 'licensed', 'inactive'], not required) Filter by account status. Options are 'locked', 'licensed', 'inactive'. Use '\|' to represent logical OR. For example, 'locked\|licensed' includes users who are either locked or licensed. required
Returns
Name Type Description
List[User] A list of users matching the specified conditions.
Examples

Find all users with a username, first name, or last name starting with ‘jo’:

>>> users = client.find(prefix="jo")

Find all users who are either viewers or publishers:

>>> users = client.find(user_role="viewer|publisher")

Find all users who are locked or licensed:

>>> users = client.find(account_status="locked|licensed")
See Also
  • https://docs.posit.co/connect/api/#get-/v1/users
find_one
connect.users.Users.find_one(**conditions)

Find a user matching the specified conditions.

Parameters
Name Type Description Default
prefix str Filter users by prefix (username, first name, or last name). The filter is case-insensitive. Default is None. required
user_role Literal['administrator', 'publisher', 'viewer'] Filter by user role. Options are 'administrator', 'publisher', 'viewer'. Use '\|' to represent logical OR (e.g., 'viewer\|publisher'). Default is None. required
account_status Literal['locked', 'licensed', 'inactive'] Filter by account status. Options are 'locked', 'licensed', 'inactive'. Use '\|' to represent logical OR. For example, 'locked\|licensed' includes users who are either locked or licensed. Default is None. required
Returns
Name Type Description
User or None The first user matching the specified conditions, or None if no user is found.
Examples

Find a user with a username, first name, or last name starting with ‘jo’:

>>> user = client.find_one(prefix="jo")

Find a user who is either a viewer or publisher:

>>> user = client.find_one(user_role="viewer|publisher")

Find a user who is locked or licensed:

>>> user = client.find_one(account_status="locked|licensed")
See Also
  • https://docs.posit.co/connect/api/#get-/v1/users
get
connect.users.Users.get(uid)

Retrieve a user by their unique identifier (guid).

Parameters
Name Type Description Default
uid str The unique identifier (guid) of the user to retrieve. required
Returns
Name Type Description
User
Examples
>>> user = client.get("123e4567-e89b-12d3-a456-426614174000")
See Also
  • https://docs.posit.co/connect/api/#get-/v1/users