Skip to main content
NoteThe API detects each image’s format from its bytes.

typesafe_sdk.Asset

module-attribute An asset referenced from request content; currently only images are supported.

typesafe_sdk.Image

dataclass An image asset backed by image file bytes, or a path to an image file.
Reusing imagesAn Image is loaded once, on first use, and reused by every request that sends the same Image object.
Working with Buffer objectsImage also accepts Buffer objects: anything exposing its memory through the buffer protocol, such as bytearray, memoryview, mmap, or NumPy arrays. Buffers other than bytes are copied into memory once, on first use, so the original can change or be closed afterwards.
Examples: From a file path:
From bytes in memory:
From base64 text, such as an upload:
From a Pillow image (requires the pil extra):
From a slice of a larger buffer, without copying it into bytes first:
From a memory-mapped file:

data

instance-attribute Image contents, represented as one of:

from_base64

classmethod Create an Image instance from a base64-encoded image bytes. Parameters:
  • data (str | Buffer) – The image file bytes, base64-encoded, as text or an ASCII buffer. Whitespace, such as the line breaks of wrapped base64, is ignored.
Raises:

from_pil

classmethod Create an Image instance from a Pillow image.
Encoder settingsThe image is saved with Pillow’s default encoder settings, except that JPEG uses quality 95. JPEG can’t store transparency or palettes, so pass format="png" for RGBA or P mode images. Encode it yourself if different settings are needed.
Parameters:
  • image (PIL.Image.Image) – The Pillow image to encode.
  • format (str, default: 'jpeg' ) – The image format to save as, by its Pillow name.
Raises:
  • TypeSafeError – Pillow can’t encode the image in this format.