{"id":6833,"library":"python-gerrit-api","title":"Python Gerrit API Client","description":"python-gerrit-api is a Python wrapper for the Gerrit REST API, enabling programmatic interaction with Gerrit Code Review. It is currently at version 3.1.0 and is actively maintained, with frequent releases often including dependency updates and minor enhancements.","status":"active","version":"3.1.0","language":"en","source_language":"en","source_url":"https://github.com/shijl0925/python-gerrit-api","tags":["gerrit","api","rest","code review","version control"],"install":[{"cmd":"pip install python-gerrit-api","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for making HTTP requests to the Gerrit REST API.","package":"requests","optional":false}],"imports":[{"note":"While older examples or the GitHub README might show 'from gerrit import Gerrit', 'GerritClient' is the consistently used class in current documentation and examples for initializing the client.","wrong":"from gerrit import Gerrit","symbol":"GerritClient","correct":"from gerrit import GerritClient"}],"quickstart":{"code":"import os\nfrom gerrit import GerritClient\n\nGERRIT_HOST = os.environ.get('GERRIT_HOST', 'http://review.example.com')\nGERRIT_USERNAME = os.environ.get('GERRIT_USERNAME', 'your_username')\nGERRIT_PASSWORD = os.environ.get('GERRIT_PASSWORD', 'your_http_password')\n\ntry:\n    # Initialize the Gerrit client with HTTP Basic Authentication\n    client = GerritClient(\n        base_url=GERRIT_HOST,\n        username=GERRIT_USERNAME,\n        password=GERRIT_PASSWORD\n    )\n\n    # Example: List projects\n    projects = client.projects.list(limit=5)\n    print(f\"Successfully connected to Gerrit. Found {len(projects)} projects:\")\n    for project in projects:\n        print(f\"- {project['name']}\")\n\n    # Example: Get a specific change (replace with a real change ID/number)\n    # Note: Gerrit REST API often expects the 'id' of a change, not just the change number.\n    # You might need to fetch a list of changes first to get an ID.\n    # change = client.changes.get('12345') # Example change number\n    # print(f\"Change {change['id']}: {change['subject']}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure GERRIT_HOST, GERRIT_USERNAME, and GERRIT_PASSWORD are set correctly.\")","lang":"python","description":"This quickstart demonstrates how to initialize the `GerritClient` and perform a basic operation, such as listing projects. It uses environment variables for authentication credentials, which is recommended for security. Ensure your Gerrit instance uses HTTP Basic Authentication and you have an HTTP password configured (not an SSH password)."},"warnings":[{"fix":"Ensure your project is running on Python 3.8+ and update your dependencies. Older versions of the library (2.x) might support Python 2.7, but are not actively maintained.","message":"Python 2.x support has been dropped. Versions of python-gerrit-api 3.x and above require Python 3.8 or newer.","severity":"breaking","affected_versions":"3.x.x and later"},{"fix":"Ensure you are using the correct HTTP password for your Gerrit user, which can often be generated or found in your Gerrit user settings. The library typically adds the '/a/' prefix for authenticated requests automatically.","message":"Gerrit REST API authentication requires an HTTP password, which is distinct from an SSH password. Authenticated calls also typically require prefixing the endpoint URL with '/a/' (e.g., /a/projects/). The library handles the '/a/' prefix automatically when `username` and `password` are provided to `GerritClient`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the specific release notes or the latest documentation on GitHub/ReadTheDocs when upgrading major versions. Test your code thoroughly after major version upgrades to catch any API changes.","message":"The API structure and available methods within `GerritClient` may have evolved between major versions (e.g., from 2.x to 3.x). While not explicitly documented as breaking changes for the client library, internal Gerrit server API changes (like those in Gerrit 3.0.x) can necessitate updates to the client library and its usage patterns.","severity":"gotcha","affected_versions":"2.x.x to 3.x.x migration"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}