PreferredPictures Python Client

This Python module allows easy use of the PreferredPictures API.

PreferredPictures’ goal is to choose the best option from many different choices. You can use it to decide between different images of the same product to show to a customer. For example, you’re showing a jacket that comes in multiple colors. You have one photo of the coat in red, one in blue, and one in dark gray, but you can only show one of them. PreferredPictures’ choice is the one option that it believes is most likely to result in a click or other action that you want to track.

View the entire PreferredPictures API.

To get started all you need to do is run:

pip install preferred_pictures

Client

class preferred_pictures.Client(identity: str, secret_key: str, max_choices=35, endpoint='https://api.preferred-pictures.com')[source]

This class is a PreferredPictures client

Parameters
  • identity (str) – The PreferredPictures identity to use when creating requests.

  • secret_key (str) – The secret key associated with the passed identity

Returns

A new PreferredPictures client instance

Return type

PreferredPictures.Client

Example

>>> import preferred_pictures
>>> pp_client = preferred_pictures.Client(identity, secret_key)
create_choose_url(choices: Iterable[str], tournament: str, ttl=600, expiration_ttl=3600, choices_prefix: str = '', choices_suffix: str = '', destinations: Iterable[str] = [], destinations_prefix: str = '', destinations_suffix: str = '', go: bool = False, json: bool = False, uid: str = '') → str[source]

Build a URL that calls the PreferredPictures API to select one choice from the list of choices available.

Parameters
  • choices (Iterable[str]) – A interable that returns the choices that should be sent to the api

  • tournament (str) – The tournament in which this request participates.

  • ttl (int, optional) – The time to live for an action to be recorded from this choice. Specified in seconds. Default: 600

  • expiration_ttl (int, optional) – The time to live for the request signature. Specified in seconds. Default: 3600

  • choices_prefix (str) – A prefix to apply to all of the choices

  • choices_suffix (str) – A suffix to apply to all of the choices

  • destinations (Iterable[Str]) – An optional iterable that return the destination URLs that will be paired with the choices.

  • destinations_prefix (str) – A prefix to apply to all of the destination URLS

  • destinations_suffix (str) – A suffix to apply to all of the destination URLS

  • uid (str) – An optional unique identifier that is used to correlate choices and actions. If it is not specified a UUID v4 will be generated.

Returns

A signed URL that contains all of the specified parameters.

Return type

str

Examples

>>> # The simpliest example of choosing between
>>> # three URLs.
>>> #
>>> import preferred_pictures
>>> pp_client = preferred_pictures.Client(identity, secret_key)
>>> url = pp_client.create_choose_url(
>>>     choices=[
>>>         'https://example.com/color-red.jpg',
>>>         'https://example.com/color-green.jpg',
>>>         'https://example.com/color-blue.jpg',
>>>     ],
>>>     tournament: 'test-tournament',
>>> )
"https://api.preferred-pictures.com/...."
>>> # Different Example using prefix and suffix for choices.
>>> url = pp_client.create_choose_url(
>>>     choices=['red', 'green', 'blue'],
>>>     tournament: 'test-tournament',
>>>     choices_prefix: 'https://example.com/color-',
>>>     choices_suffix: '.jpg',
>>> )
"https://api.preferred-pictures.com/...."