Skip to main content

mediapreview

Generate compact AVIF preview images from images, videos, PDFs and office documents.

mediapreview is a small library of low-level converters. Give it a file path and it returns AVIF bytes plus a response object telling you which backend handled it and whether it succeeded.

Install

uv add mediapreview[standard]

[standard] pulls in every backend and the optional worker pool. Use the feature-specific extras to avoid dependencies not needed for your application.

Quick start

from pathlib import Path
from mediapreview import dispatch

avif_bytes, resp = dispatch(
    Path("photo.jpg"),
    quality=60,
    maxsize=512,
    maxzoom=2.0,
)

if resp.ok:
    Path("preview.avif").write_bytes(avif_bytes)
else:
    print(resp.error)

dispatch picks the backend from the file extension or mimetype. You can also call the backend functions directly:

from mediapreview import process_image, process_pdf, process_video

avif, resp = process_image(Path("photo.jpg"), maxsize=512, quality=60)
avif, resp = process_pdf(Path("doc.pdf"), maxsize=512, quality=60, page_number=0)
avif, resp = process_video(Path("clip.mp4"), maxsize=512, quality=60)

Worker pool (optional)

Heavy native dependencies and crashes stay out of your async loop by running previews in a pool of persistent subprocess workers.

from mediapreview.pool import (
    start_preview_workers,
    shutdown_preview_workers,
    run_preview,
)

await start_preview_workers()
try:
    avif, resp = await run_preview(Path("doc.pdf"))
finally:
    await shutdown_preview_workers()

Add the worker extra to use the pool.

CLI

mediapreview photo.jpg -o preview.avif
mediapreview doc.pdf -q 70 --maxsize 1024
mediapreview oosetup    # build + run the bundled OnlyOffice container

OnlyOffice setup

Office previews need an OnlyOffice Document Server. A patched Docker image ships inside the package and can be started with:

mediapreview oosetup [name] [port]

oosetup logs to stderr and prints one line on stdout:

ONLYOFFICE_JWT_SECRET=<token>

Set ONLYOFFICE_JWT_SECRET yourself to reuse an existing secret; otherwise a random one is generated.

Download files

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

Source Distribution

mediapreview-0.2.0.tar.gz (5.9 MB view details)

Uploaded Source

Built Distribution

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

mediapreview-0.2.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file mediapreview-0.2.0.tar.gz.

File metadata

  • Download URL: mediapreview-0.2.0.tar.gz
  • Upload date:
  • Size: 5.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mediapreview-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7e431afb16ec2f73282623c9e48b62e68853c94cdc7be5091d3928977dd8f19e
MD5 225189db1d962f0ac9c9a0f56dcf2488
BLAKE2b-256 1dab61cceb7d3e8a40e4a1c3f365b0f7b68e7ff10cdb7255d29c94522a3bec6f

See more details on using hashes here.

File details

Details for the file mediapreview-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mediapreview-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mediapreview-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7692ce059c77db2e8d95538cd84330f755119db018468ff52b3efa0b5fd91fc7
MD5 d31b73b5d21724e8ce3c9bcacbb2ad42
BLAKE2b-256 cf6df4656a4a123606b2f867b7b02434064339c1c3d50ad35acbc7e0d6ec958c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page