/postcard_creator_wrapper

A python wrapper around the Rest API of the Swiss Postcard creator

Primary LanguagePythonApache License 2.0Apache-2.0

Postcard Creator

PyPI version Build Status codecov Codacy Badge PyPI version License

A python wrapper around the Rest API of the Swiss Postcard creator.

Installation

# requires python 3.6 or later
$ pip install postcard-creator

Setup / API Usage

from postcard_creator.postcard_creator import PostcardCreator

w = PostcardCreator(token)
w.get_quota()
w.get_user_info()
w.get_billing_saldo()
w.has_free_postcard()
w.send_free_card(postcard=)

Usage

from postcard_creator.postcard_creator import PostcardCreator, Postcard, Token, Recipient, Sender

token = Token()
token.fetch_token(username='', password='')
token.has_valid_credentials(username='', password='')
recipient = Recipient(prename='', lastname='', street='', place='', zip_code=0000)
sender = Sender(prename='', lastname='', street='', place='', zip_code=0000)
card = Postcard(message='', recipient=recipient, sender=sender, picture_stream=open('./my-photo.jpg', 'rb'))

w = PostcardCreator(token)
w.send_free_card(postcard=card, mock_send=False, image_export=False)

Advanced configuration

The following keyword arguments are available for advanced configuration.

PostcardCreator#send_free_card():

  • image_export=False: Export postcard image to current directory (os.getcwd)
  • mock_send=False: Do not submit order (testing)

Logging

import logging

logger = logging.getLogger('postcard_creator')

# log levels
# 5: trace
# 10: debug
# 20: info
# 30: warning

Example

  • Postcards is a commandline interface built around this library.
  • See tests for more usage examples.

Test

pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -e .
pytest

Related

Release notes

v2.0, 2021-02

  • support of new swissid authentication (access_token with code/ code_verifier)
  • support of new endpoints at https://pccweb.api.post.ch/secure/api/mobile/v1
  • class PostcardCreator is a proxy which instantiates an endpoint wrapper compatible with authentication method of token, underlying wrappers are: PostcardCreatorSwissId, PostcardCreatorLegacy
  • migration to v2.0
    • with authentication method swissid: if you rely on get_billing_saldo(), get_user_info(): these endpoints return data in different format
    • customizations image_target_width, image_target_height, image_quality_factor no longer compatible with authentication method swissid
  • require python 3.6 or later

v1.1, 2020-01-30

  • support for swissid authentication
  • Method Token#has_valid_credentials and Token#fetch_token introduce a parameter method which can be set to one of these vals: ['mixed', 'legacy', 'swissid']. 'mixed' is default and tries both authentication procedures

v0.0.8, 2018-03-28

  • Migrate to postcardcreator API 2.2

v0.0.7, 2017-12-28

  • Fix issues with PNG images #6

v0.0.6, 2017-11-22

  • internal changes
  • do not use requirements.txt in setup.py anymore. set all requirements in install_requires without explicit version numbers

Author

Andrin Bertschi
https://twitter.com/andrinbertschi

License

Apache License 2.0

<3