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-gitlabVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Python environment to 3.10 or newer. Ensure your `pyproject.toml` or `requirements.txt` specifies `python_requires='>=3.10'` for compatibility.
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.
Switch to Personal Access Tokens, Project Access Tokens, or OAuth tokens for authentication. Avoid using direct username/password pairs.
Always use the canonical (final) URL of your GitLab instance, typically starting with `https://`, when initializing the `Gitlab` object.
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.