The Gitlab API exposes user-related method that can be manipulated by admins only.
The currently logged-in user is also exposed.
- v4 API:
gitlab.v4.objects.User
gitlab.v4.objects.UserManager
- :attr:gitlab.Gitlab.users
- v3 API:
gitlab.v3.objects.User
gitlab.v3.objects.UserManager
- :attr:gitlab.Gitlab.users
- GitLab API: https://docs.gitlab.com/ce/api/users.html
Get the list of users:
users.py
Search users whose username match the given string:
users.py
Get a single user:
users.py
Create a user:
users.py
Update a user:
users.py
Delete a user:
users.py
Block/Unblock a user:
users.py
- v4 API:
gitlab.v4.objects.UserCustomAttribute
gitlab.v4.objects.UserCustomAttributeManager
- :attr:gitlab.v4.objects.User.customattributes
- GitLab API: https://docs.gitlab.com/ce/api/custom_attributes.html
List custom attributes for a user:
attrs = user.customattributes.list()
Get a custom attribute for a user:
attr = user.customattributes.get(attr_key)
Set (create or update) a custom attribute for a user:
attr = user.customattributes.set(attr_key, attr_value)
Delete a custom attribute for a user:
attr.delete()
# or
user.customattributes.delete(attr_key)
Search users by custom attribute:
user.customattributes.set('role': 'QA')
gl.users.list(custom_attributes={'role': 'QA'})
- v4 API:
gitlab.v4.objects.UserImpersonationToken
gitlab.v4.objects.UserImpersonationTokenManager
- :attr:gitlab.v4.objects.User.impersonationtokens
- GitLab API: https://docs.gitlab.com/ce/api/users.html#get-all-impersonation-tokens-of-a-user
List impersonation tokens for a user:
users.py
Get an impersonation token for a user:
users.py
Create and use an impersonation token for a user:
users.py
Revoke (delete) an impersonation token for a user:
users.py
- v4 API:
gitlab.v4.objects.CurrentUser
gitlab.v4.objects.CurrentUserManager
- :attr:gitlab.Gitlab.user
- v3 API:
gitlab.v3.objects.CurrentUser
gitlab.v3.objects.CurrentUserManager
- :attr:gitlab.Gitlab.user
- GitLab API: https://docs.gitlab.com/ce/api/users.html
Get the current user:
users.py
You can manipulate GPG keys for the current user and for the other users if you are admin.
- v4 API:
gitlab.v4.objects.CurrentUserGPGKey
gitlab.v4.objects.CurrentUserGPGKeyManager
- :attr:gitlab.v4.objects.CurrentUser.gpgkeys
gitlab.v4.objects.UserGPGKey
gitlab.v4.objects.UserGPGKeyManager
- :attr:gitlab.v4.objects.User.gpgkeys
- GitLab API: https://docs.gitlab.com/ce/api/users.html#list-all-gpg-keys
List GPG keys for a user:
users.py
Get a GPG gpgkey for a user:
users.py
Create a GPG gpgkey for a user:
users.py
Delete a GPG gpgkey for a user:
users.py
You can manipulate SSH keys for the current user and for the other users if you are admin.
- v4 API:
gitlab.v4.objects.CurrentUserKey
gitlab.v4.objects.CurrentUserKeyManager
- :attr:gitlab.v4.objects.CurrentUser.keys
gitlab.v4.objects.UserKey
gitlab.v4.objects.UserKeyManager
- :attr:gitlab.v4.objects.User.keys
- v3 API:
gitlab.v3.objects.CurrentUserKey
gitlab.v3.objects.CurrentUserKeyManager
- :attr:gitlab.v3.objects.CurrentUser.keys
- :attr:gitlab.Gitlab.user.keys
gitlab.v3.objects.UserKey
gitlab.v3.objects.UserKeyManager
- :attr:gitlab.v3.objects.User.keys
- :attr:gitlab.Gitlab.user_keys
- GitLab API: https://docs.gitlab.com/ce/api/users.html#list-ssh-keys
List SSH keys for a user:
users.py
Get an SSH key for a user:
users.py
Create an SSH key for a user:
users.py
Delete an SSH key for a user:
users.py
You can manipulate emails for the current user and for the other users if you are admin.
- v4 API:
gitlab.v4.objects.CurrentUserEmail
gitlab.v4.objects.CurrentUserEmailManager
- :attr:gitlab.v4.objects.CurrentUser.emails
gitlab.v4.objects.UserEmail
gitlab.v4.objects.UserEmailManager
- :attr:gitlab.v4.objects.User.emails
- v3 API:
gitlab.v3.objects.CurrentUserEmail
gitlab.v3.objects.CurrentUserEmailManager
- :attr:gitlab.v3.objects.CurrentUser.emails
- :attr:gitlab.Gitlab.user.emails
gitlab.v3.objects.UserEmail
gitlab.v3.objects.UserEmailManager
- :attr:gitlab.v3.objects.User.emails
- :attr:gitlab.Gitlab.user_emails
- GitLab API: https://docs.gitlab.com/ce/api/users.html#list-emails
List emails for a user:
users.py
Get an email for a user:
users.py
Create an email for a user:
users.py
Delete an email for a user:
users.py
- v4 only
- admin only
- v4 API:
gitlab.v4.objects.UserActivities
gitlab.v4.objects.UserActivitiesManager
- :attr:gitlab.Gitlab.user_activities
- GitLab API: https://docs.gitlab.com/ce/api/users.html#get-user-activities-admin-only
Get the users activities:
activities = gl.user_activities.list(all=True, as_list=False)