The python-gitlab library provides a command-line interface (CLI) and Python bindings to interact with the GitLab API. While the CLI offers various functionalities, it does not directly support filtering users based on their profile visibility (i.e., private profiles).
However, using the Python bindings of python-gitlab, you can achieve this by leveraging the private_profile attribute available in the GitLab API. This attribute indicates whether a user's profile is private. To access this information, you need administrative privileges, as the private_profile attribute is accessible only to administrators.
Here's how you can retrieve all users with private profiles using python-gitlab:
python
import gitlab
# Initialize the GitLab connection with administrator access
gl = gitlab.Gitlab('https://gitlab.example.com', private_token='your_admin_private_token')
# Retrieve all users
all_users = gl.users.list(all=True)
# Filter users with private profiles
private_users = [user for user in all_users if user.private_profile]
# Output the usernames of users with private profiles
for user in private_users:
print(user.username)
In this script:
A connection to the GitLab instance is established using an administrator's private token.
All users are retrieved.
Users with the private_profile attribute set to True are filtered.
The usernames of these users are printed.
Ensure you have the necessary administrative privileges to access the private_profile attribute. For more details on user attributes and the GitLab API, refer to the GitLab Users API documentation.