snip.api.snippets

Interface with snippet related endpoints.

Allows to generate previews, test snippets and upload snippets to a deployment.

Functions

get_font(font, **kwargs)

Get a PIL ImageFont object for the given font and size.

get_snip_preview(dict, token, **kwargs)

Generate a preview image for the given snippet as dict /json.

upload_snip(snippet, token, **kwargs)

Upload a snippet given a token.

Module Functions

snip.api.snippets.get_font(font: str, **kwargs)

Get a PIL ImageFont object for the given font and size.

Parameters:
  • font (str) – The font to use.

  • size (int) – The size of the font.

  • **kwargs (Any) – Additional keyword arguments to pass to the requests.get function.

Returns:

The PIL ImageFont object.

Return type:

ImageFont

snip.api.snippets.get_snip_preview(dict: dict, token: Token, **kwargs) Image

Generate a preview image for the given snippet as dict /json.

This method only checks the validity of the dict on the server side and returns the preview image as a PIL Image object if it is valid.

Parameters:
  • dict (dict) – The snippet as a dictionary.

  • deployment (str, optional) – The deployment to generate the preview for. If None, the default deployment is used.

  • **kwargs (Any) – Additional keyword arguments to pass to the requests.post function.

Returns:

The preview image as a PIL Image object.

Return type:

Image.Image

snip.api.snippets.upload_snip(snippet: dict, token: Token, **kwargs) dict

Upload a snippet given a token.

If the book_id of the snippet and taken first from the token do not match, a ValueError is raised.

Parameters:
  • snippet (dict) – The snippet to upload.

  • token (Token) – The token to use for the upload.

  • **kwargs (Any) – Additional keyword arguments to pass to the requests.post function.