Skip to main content

thumbrella-client

Python client for Thumbrella, a fast thumbnail server for images, video, documents, and more.

PyPI version Python License

The client git repository also has packages for other languages and environments. See Typescript, Rust, and more coming soon.

Features

  • Client defaults to synchronous requests with requests
  • Async support via thumbrella-client[async] using aiohttp
  • The batch() call processes multiple URLs in parallel
  • In-memory LRU cache takes full advantage of HTTP cache headers
  • Binary thumbnail data loads easily into PIL, Qt, Pygame, or any other image library
  • The client and server always provide placeholder images, even when disconnected or misconfigured
  • Optional verify() methods promote failed results into exceptions
  • Media classification and lightweight metadata provided with every result
  • Thumbrella server supports hundreds of formats

Quickstart

Install with your package manager of choice using thumbrella-client or thumbrella-client[async].

uv add thumbrella-client
pip install thumbrella-client
import thumbrella

# Client() reads $TBR_CONNECT from the environment.
# verify() checks the server is reachable and auth is valid.
tbr = thumbrella.Client().verify()

# Single URL — returns a Result with the thumbnail JPEG.
result = tbr.thumb("https://www.pygame.org/docs/_images/pygame_lofi.png")
if result.is_success():
    print(len(result.media.thumbnail), "bytes")

# Batch many URLs at once.
results = tbr.batch([
    "https://www.python.org/static/img/python-logo-large.png",
    "https://web.mit.edu/18.417/doc/pydocs/ref.pdf",
])
for r in results:
    print(r.url, r.status, r.media.kind)

# Stream results as the server completes each thumbnail (requires aiohttp).
import asyncio

async def stream_example():
    tbr = thumbrella.Client()
    async for r in tbr.stream([
        "https://www.python.org/static/img/python-logo-large.png",
        "https://web.mit.edu/18.417/doc/pydocs/ref.pdf",
    ]):
        print(r.url, r.status)

asyncio.run(stream_example())

How It Works

Create a Client with server configuration and optional caches. Call verify() to confirm connectivity. Then use thumb(), batch(), or stream() to generate thumbnails.

Every URL gets a Result — even failures produce a result with a placeholder image and an error message. Use result.verify() to raise an exception on failure, or check result.is_success() for inline handling.

Connect Strings

The client reads $TBR_CONNECT by default. Pass a connect string to override:

# Local dev server (no auth)
thumbrella.Client("http://localhost:3114")

# Cloud service with auth token
thumbrella.Client("tbr_e_3QnzBcWx7KpRmYT2000example")

The connect string can also define custom headers. Thumbrella servers can define an additional handshake token to prevent unwanted users. The documentation describes these in more detail at, https://thumbrella.dev/docs/client/#connect

The Client object defines a requests.Session attribute which can be further customized for proxies, TLS certificates, cookies, or other HTTP-level configuration.

Result

result.url         # str — the requested URL
result.status      # "success" | "failed" | "overloaded" | "intermediate" | ...
result.source      # "render" | "cache" | "fallback" | "placeholder" | ...
result.media       # Media | None — None when thumbnail could not be generated
result.duration    # float — server processing time (ms)
result.message     # str — error or informational message

result.is_success()  # True for SUCCESS or INTERMEDIATE
result.is_fresh()    # True when the server freshly rendered (not from cache)
result.verify()      # returns self on success, raises ThumbError on failure

All the result properties are documented at, https://thumbrella.dev/docs/client/#result

Media

media.url          # str — the original media URL
media.mime         # "image/jpeg" | "application/pdf" | ...
media.kind         # "image" | "video" | "document" | "vector" | "geometry" | ...
media.file_size    # int — original file size in bytes
media.thumbnail    # EncodedJpeg — the thumbnail JPEG bytes

All the result properties are documented at, https://thumbrella.dev/docs/client/#media

EncodedJpeg

jpeg.bytes         # bytes — decoded JPEG bytes (lazy, cached)
jpeg.io            # _BytesIO — file-like object, compatible with PIL and numpy
len(jpeg)          # int — byte count
jpeg.key           # str — content hash, useful for deduplication

PIL integration:

from PIL import Image
img = Image.open(result.media.thumbnail.io)

The source comes with several starting point examples. See the client documentation for more details and examples.

Servers

This client works with any self-hosted Thumbrella server and also the online Thumbrella Cloud service. Both are configured using the $TBR_CONNECT environment variable. Alternatively, a connect string can be passed to the Client constructor.

Thumbrella provides a demo gallery and server that can be used for free with no account and no signup.

License

Apache-2.0. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thumbrella_client-1.4.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thumbrella_client-1.4.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file thumbrella_client-1.4.0.tar.gz.

File metadata

  • Download URL: thumbrella_client-1.4.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for thumbrella_client-1.4.0.tar.gz
Algorithm Hash digest
SHA256 fde181e695c42db2ad1ae87390e8a1d76ae0f0ec8439e80a59d139bfd33c1753
MD5 478db099f0eb58f7a14e6965b49feb12
BLAKE2b-256 c89f98e8b6f162bfed8fc7889a7e15e6052de53b90f8c04638ff62becfb1141f

See more details on using hashes here.

Provenance

The following attestation bundles were made for thumbrella_client-1.4.0.tar.gz:

Publisher: pypi.yaml on thumbrella-dev/clients

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thumbrella_client-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for thumbrella_client-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00437ef9627e4f740d7f7aa9f955d80935e01c2e928573959adc9363938408b3
MD5 59daa539cef862be8cccf8afc065cc79
BLAKE2b-256 c804cb28f46f2f085885e07d3ff56dc206d0b55384d2c2ae9e71b364eaf3021d

See more details on using hashes here.

Provenance

The following attestation bundles were made for thumbrella_client-1.4.0-py3-none-any.whl:

Publisher: pypi.yaml on thumbrella-dev/clients

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 files

1.2.0

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.5.1

2 files

0.5.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page