Registry / devops / python-gitlab

python-gitlab

JSON →
library8.5.0pypypi✓ verified 27d ago

python-gitlab is a Python package that provides a comprehensive wrapper for the GitLab REST and GraphQL APIs. It allows developers to interact with GitLab resources in a Pythonic way, offering both synchronous and asynchronous clients, along with a CLI tool. The library maintains a regular release cadence, typically releasing new versions monthly, ensuring up-to-date support for GitLab API features.

pip install python-gitlab
INSTALL
IMPORT
SIG · PYTHON-GITLAB
P
python-gitlab
devopspythonv8.5.0
Install
2.3s avg
Import
425ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.436s · 23.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.3s · import 0.414s · 24MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Gitlab
from gitlab import Gitlab
import gitlab

This quickstart demonstrates how to connect to a GitLab instance using a personal access token and then fetch a list of projects owned by the authenticated user. It highlights setting the GitLab URL and private token via environment variables for security and explicitly uses API v4.

import os import gitlab # Configure GitLab connection using environment variables GITLAB_URL = os.environ.get('GITLAB_URL', 'https://gitlab.com') GITLAB_PRIVATE_TOKEN = os.environ.get('GITLAB_PRIVATE_TOKEN', 'your_private_token_here') # Initialize the Gitlab API client # Ensure you use 'https://' if your GitLab instance redirects from http try: gl = gitlab.Gitlab( url=GITLAB_URL, private_token=GITLAB_PRIVATE_TOKEN, api_version='4' # Explicitly set API version, often '4' ) # Optional: Validate the token by getting the current authenticated user gl.auth() user = gl.user.get() print(f"Connected to GitLab as: {user.username}") # List current user's projects print("\nListing your projects:") projects = gl.projects.list(owned=True, all=True) if projects: for project in projects: print(f" - {project.name} (ID: {project.id})") else: print(" No projects found.") except gitlab.exceptions.GitlabError as e: print(f"GitLab API error: {e}") except Exception as e: print(f"An unexpected error occurred: {e}")
gitlab --version
Debug
Known issues
breakingpython-gitlab v7.0.0 and later require Python 3.10 or higher. Python 3.9 and older are no longer supported.
fix
Upgrade your Python environment to 3.10 or newer. Ensure your `pyproject.toml` or `requirements.txt` specifies `python_requires='>=3.10'` for compatibility.
affects: >=7.0.0
breakingIn python-gitlab v8.0.0, the GraphQL API client's `GraphQL.execute()` method no longer accepts `graphql.Source` objects directly.
fix
Review the GraphQL client usage and adapt to the updated `GraphQL.execute()` signature, likely by passing the query string directly or using `gql` package objects.
affects: >=8.0.0
gotchaPassword-based authentication (username/password) is deprecated and largely removed from GitLab API v10.2 onwards. It is highly recommended to use Personal Access Tokens or OAuth tokens.
fix
Switch to Personal Access Tokens, Project Access Tokens, or OAuth tokens for authentication. Avoid using direct username/password pairs.
affects: All versions
gotchaIf your GitLab instance redirects HTTP requests to HTTPS (e.g., `http://gitlab.example.com` to `https://gitlab.example.com`), you must specify the final HTTPS URL in the `Gitlab` object constructor to avoid `RedirectionError` or malformed requests.
fix
Always use the canonical (final) URL of your GitLab instance, typically starting with `https://`, when initializing the `Gitlab` object.
affects: All versions
gotchaBy default, python-gitlab handles rate limiting by sleeping and retrying based on `Retry-After` headers or exponential backoff. It also does *not* retry transient HTTP errors (5xx codes) by default.
fix
To customize rate limiting behavior (e.g., disable waiting), use `obey_rate_limit=False` or `max_retries`. To enable automatic retries for transient errors, set `retry_transient_errors=True` during `Gitlab` object initialization or on individual API calls.
affects: All versions
Upgrade
Version history
8.5.0latest on PyPI · released Jul 28, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.10 or higher.
Agent activity
11 hits · last 30 days
node
8
Resources
python-gitlab — pip install python-gitlab · libregistry