Skip to main content

Client library for interacting with Gerrit's REST API

Project description

https://img.shields.io/pypi/v/pygerrit2.png https://img.shields.io/pypi/l/pygerrit2.png

Pygerrit2 provides a simple interface for clients to interact with Gerrit Code Review via the REST API.

Prerequisites

Pygerrit2 is compatible with Python 2.6 and Python 2.7. Support for Python 3 is experimental.

Pygerrit2 depends on the requests library.

Installation

To install pygerrit2, simply:

$ pip install pygerrit2

Usage

This simple example shows how to get the user’s open changes. Authentication to Gerrit is done via HTTP Basic authentication, using an explicitly given username and password:

>>> from requests.auth import HTTPBasicAuth
>>> from pygerrit2.rest import GerritRestAPI
>>> auth = HTTPBasicAuth('username', 'password')
>>> rest = GerritRestAPI(url='http://review.example.net', auth=auth)
>>> changes = rest.get("/changes/?q=owner:self%20status:open")

Note that is is not necessary to add the /a/ prefix on the endpoint URLs. This is automatically added when the API is instantiated with an authentication object.

If the user’s HTTP username and password are defined in the .netrc file:

machine review.example.net login MyUsername password MyPassword

then it is possible to authenticate with those credentials:

>>> from pygerrit2.rest import GerritRestAPI
>>> from pygerrit2.rest.auth import HTTPBasicAuthFromNetrc
>>> url = 'http://review.example.net'
>>> auth = HTTPBasicAuthFromNetrc(url=url)
>>> rest = GerritRestAPI(url=url, auth=auth)
>>> changes = rest.get("/changes/?q=owner:self%20status:open")

Note that the HTTP password is not the same as the SSH password. For instructions on how to obtain the HTTP password, refer to Gerrit’s HTTP upload settings documentation.

Also note that in Gerrit version 2.14, support for HTTP Digest authentication was removed and only HTTP Basic authentication is supported. When using pygerrit2 against an earlier Gerrit version, it may be necessary to replace the HTTPBasic… classes with the corresponding HTTPDigest… versions.

Refer to the example script for a full working example.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygerrit2-2.0.4.tar.gz (19.8 kB view details)

Uploaded Source

File details

Details for the file pygerrit2-2.0.4.tar.gz.

File metadata

  • Download URL: pygerrit2-2.0.4.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pygerrit2-2.0.4.tar.gz
Algorithm Hash digest
SHA256 d9834be5a9d55c47a28983f7f9953dead5b620c9ff8819d490556df604f498cd
MD5 bf36bb6675fd2325c65f52adaa217c8f
BLAKE2b-256 1bec49da5cc9662cbe88e947293d699760d9668194fc4a04886feb41cf3adcd0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page