postmen package

Module contents

API and PostmenError classes are intended for SDK users.

class postmen.API(api_key, region=None, endpoint=None, version='v3', x_agent='python-sdk-0.1', retries=4, raw=False, safe=False, time=False, proxy=None, retry=True)[source]

Bases: object

API calls handler.

Parameters:
  • api_key (str or unicode) – Postmen API key
  • region (str or unicode) – avalible regions: sandbox, us-west, ap-southeast. Part of API endpoint
  • endpoint (str or unicode) – raw API endpoint string, overwrite region setting
  • version (str or unicode) – API version, use to create endpoint
  • x_agent (str or unicode) – HTTP header x-postmen-agent tag value
  • retries (int) – number of calls retries in case of retriable errors
  • raw (bool) – True to exclude parsing of response JSON strings
  • safe (bool) – True to suppress exceptions on API calls (only). Use getError() instead
  • time (bool) – True to convert ISO time strings to datetime.datetime
  • proxy (str or unicode) – Proxy for HTTP calls
  • retry (bool) – True to retry calls in case of retriable errors
Raises:
  • PostmenError – if API is missed
  • PostmenError – if region or endpoint is missed
  • PostmenError – if version is missed
DELETE(path, **kwargs)[source]

Create, perform HTTP DELETE call to Postmen API, parse and return result.

Parameters:
  • path (str or unicode) – URL path
  • **kwargs

    query, raw, safe, time, proxy, retry params from API.call()

Returns:

same as API.call()

GET(path, **kwargs)[source]

Create, perform HTTP GET call to Postmen API, parse and return result.

Parameters:
  • path (str or unicode) – URL path
  • **kwargs

    query, raw, safe, time, proxy, retry params from API.call()

Returns:

same as API.call()

POST(path, body, **kwargs)[source]

Create, perform HTTP POST call to Postmen API, parse and return result.

Parameters:
  • path (str or unicode) – URL path
  • body (dict or list or str or unicode) – API call payload
  • **kwargs

    query, raw, safe, time, proxy, retry params from API.call()

Returns:

same as API.call()

PUT(path, body, **kwargs)[source]

Create, perform HTTP PUT call to Postmen API, parse and return result.

Parameters:
  • path (str or unicode) – URL path
  • body (dict or list or str or unicode) – API call payload
  • **kwargs

    query, raw, safe, time, proxy, retry params from API.call()

Returns:

same as API.call()

call(method, path, body, query=None, raw=None, safe=None, time=None, proxy=None, retry=None)[source]

Create, perform HTTP call to Postmen API, parse and return result.

Parameters:
  • method (str or unicode) – HTTP method
  • path (str or unicode) – URL path
  • body (dict or list or str or unicode) – API call payload
  • query (dict or str or unicode) – URL query
  • raw (bool) – True to exclude parsing of response JSON strings (overwrite constructor value)
  • safe (bool) – True to suppress exceptions. Use getError() instead (overwrite constructor value)
  • time (bool) – True to convert ISO time strings to datetime.datetime (overwrite constructor value)
  • proxy (str or unicode) – Proxy for HTTP calls (overwrite constructor value)
  • retry (bool) – True to retry calls in case of retriable errors (overwrite constructor value)
Returns:

API data response

Return type:

dict or list or str or unicode

Raises PostmenError:
 

all errors and exceptions

cancel(resource, id_, **kwargs)[source]

Delete/cancel particular resource (e.g. label)

Parameters:
  • resource (str or unicode) – resource type (e.g. labels)
  • id (str or unicode) – resource id
Returns:

same as API.call()

create(resource, payload, **kwargs)[source]

Create resource object (e.g. label)

Parameters:
  • resource (str or unicode) – resource type (e.g. labels)
  • payload (dict or list or str or unicode) – API call payload
Returns:

same as API.call()

get(resource, id_=None, **kwargs)[source]

List all or retrieve particular resource (e.g. /labels, /labels/:id)

Parameters:
  • resource (str or unicode) – resource type (e.g. labels)
  • id (str or unicode) – resource id, None to list all resources
Returns:

same as API.call()

getError()[source]

If safe == True, return last PostmenError

exception postmen.PostmenError(message=None, **kwarg)[source]

Bases: exceptions.Exception

Include errors reported by API, related to API (e.g. rate limit) and other exceptions during API calls (e.g. HTTP connectivity issue).

code()[source]
Returns:API error code
Return type:int or None
data()[source]
Returns:API call data (if any)
Return type:dict
details()[source]
Returns:API error details
Return type:list
message()[source]
Returns:API error human readable message
Return type:str or unicode
retryable()[source]
Returns:indicate if API call is retryable
Return type:bool
traceback()[source]
Returns:error’s traceback object. Traceback must be passed explicitly thru constructor method
Return type:traceback object