3. Python API

Usually you just need to import main class from the module.

from pdc_client import PDCClient

3.2. Module pdc_client

exception pdc_client.NoResultsError(response)

Exception for getting all pages of data Raise this NoResultsError if there is an unexpected data returned when get all pages of data by results() function.

Data members:
  • response – response object
__init__(response)

Create a NoResultsError

class pdc_client.PDCClient(server, token=None, develop=None, ssl_verify=None, page_size=None)

BeanBag wrapper specialized for PDC access.

This class wraps general BeanBag.v1 objects, but provides easy-to-use interface that can use configuration files for specifying server connections. The authentication token is automatically retrieved (if needed).

# Example: Get per page of release
client = PDCClient(<server>)
client.releases._()
client["releases"]._()
...

# Example: create one release data
client["releases"]._(<dict data>)
...

# Example: Iterate all pages of releases
# Will raise NoResultsError with response when return unexpected result.
try:
    for r in client["releases"].results():
        ...
except NoResultsError as e:
    # handle e.response ...
__getattr__(name)

If the first attribute/endpoint with “-“, just replace with “_” in name.

# Example: get endpoint
client = PDCClient(<server>)
# Get the endpoint base-products/
client.base_products._
# Get the endpoint base-products/test_123/
client.base_products.test_123._
# Get the endpoint products/
client.products._
__init__(server, token=None, develop=None, ssl_verify=None, page_size=None)

Create new pdc client instance.

Once the class is instantiated, use it as you would use a regular BeanBag object. Please look at its documentation for how to use this class to perform requests.

Parameters:
  • server – Server API url or server name from configuration
  • token – An authentication token string of visiting pdc server
  • develop – This is use for dev mode
  • ssl_verify – True for validating SSL certificates with system CA store; False for no validation; path to CA file or directory to use for validation otherwise
  • page_size – This is a number of data which is returned per page. A -1 means that pdc server will return all the data in one request.
Raises:

pdc_client.config.ServerConfigError – on an configuration error

get_paged(res, **kwargs)

This call is equivalent to res(**kwargs), only it retrieves all pages and returns the results joined into a single iterable. The advantage over retrieving everything at once is that the result can be consumed immediately.

Parameters:
  • res – what resource to connect to
  • kwargs – filters to be used
# Example: Iterate over all active releases
for release in client.get_paged(client['releases']._, active=True):
    ...

This function is obsolete and not recommended.

obtain_token()

Try to obtain token from all end-points that were ever used to serve the token. If the request returns 404 NOT FOUND, retry with older version of the URL.

set_comment(comment)

Set PDC Change comment to be stored on the server.

Once you set the comment, it will be sent in all subsequent requests.

Parameters:comment (string) – what comment to send to the server
class pdc_client.PDCClientWithPage(server, token=None, develop=None, ssl_verify=None, page_size=None, page=None)

PDCClient wrapper specialized for setting page in get_paged function.

__init__(server, token=None, develop=None, ssl_verify=None, page_size=None, page=None)

Create new client instance with page prarameter. Other params are all used for base class. :param page: the page number of the data.

get_paged(res, **kwargs)

Re-write the ge_paged here, and add the self.page check. This call is equivalent to res(**kwargs), if there is no self.page parameter,only it retrieves all pages and returns the results joined into a single iterable. The advantage over retrieving everything at once is that the result can be consumed immediately.

Parameters:
  • res – what resource to connect to
  • kwargs – filters to be used
# Example: Iterate over all active releases
for release in client.get_paged(client['releases']._, active=True):
    ...

If there is a self.page parameter here, just return that page’s data with the self.page_size.

exception pdc_client.config.ServerConfigConflictError

Same server defined in multiple config files.

exception pdc_client.config.ServerConfigError

Base class for ServerConfiguration exceptions.

class pdc_client.config.ServerConfigManager(*paths)

Provides configuration for given server name.

Configuration is read from multiple files or directories in order they’re passed to constructor. Files and directories are read lazily when needed and at most once (cached for later access).

get(server)

Returns ServerConfig instance with configuration given server.

Raises:
exception pdc_client.config.ServerConfigMissingUrlError

Server configuration is missing URL.

exception pdc_client.config.ServerConfigNotFoundError

Server configuration is missing.