{"library":"pygerrit2","title":"Pygerrit2","description":"Pygerrit2 is a Python client library, version 2.0.15, for interacting with Gerrit Code Review's REST API. It is actively maintained and provides a simpler interface compared to its predecessor, `pygerrit`, by focusing solely on the REST API and omitting SSH functionality. The library is released as needed, with the latest stable version from June 2021.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pygerrit2"],"cli":null},"imports":["from pygerrit2 import GerritRestAPI","from pygerrit2 import HTTPBasicAuth","from pygerrit2 import HTTPBasicAuthFromNetrc"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom pygerrit2 import GerritRestAPI, HTTPBasicAuth\n\nGERRIT_URL = os.environ.get('GERRIT_URL', 'http://localhost:8080')\nGERRIT_USERNAME = os.environ.get('GERRIT_USERNAME', 'admin')\nGERRIT_HTTP_PASSWORD = os.environ.get('GERRIT_HTTP_PASSWORD', 'secret') # This is NOT your SSH password\n\nif not all([GERRIT_URL, GERRIT_USERNAME, GERRIT_HTTP_PASSWORD]):\n    print(\"Please set GERRIT_URL, GERRIT_USERNAME, and GERRIT_HTTP_PASSWORD environment variables.\")\n    exit(1)\n\ntry:\n    auth = HTTPBasicAuth(GERRIT_USERNAME, GERRIT_HTTP_PASSWORD)\n    rest = GerritRestAPI(url=GERRIT_URL, auth=auth)\n\n    # Get open changes owned by the authenticated user\n    changes = rest.get(\"/changes/?q=owner:self+status:open\")\n    print(f\"Found {len(changes)} open changes for {GERRIT_USERNAME}:\")\n    for change in changes:\n        print(f\"  Change ID: {change['id']}, Subject: {change['subject']}\")\n\n    # Example of getting a specific project\n    project_name = \"All-Projects\"\n    project_info = rest.get(f\"/projects/{project_name}\")\n    print(f\"\\nProject '{project_name}': {project_info['description']}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This example demonstrates how to initialize `GerritRestAPI` with `HTTPBasicAuth` using credentials from environment variables and fetch a list of open changes. It also shows how to retrieve information about a specific project. Remember that the HTTP password is distinct from the SSH password.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}