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.
Metadata
Release files for mediapreview 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mediapreview-0.2.5.tar.gz | 5.9 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mediapreview-0.2.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.0 MB
Release files / mediapreview-0.2.5.tar.gz
| Download URL | mediapreview-0.2.5.tar.gz |
|---|---|
| Size | 5.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07fcc97f1ca315ead44e5f65d7e64dd346827ab4d2554508132ce9dc08a0155c
|
|
BLAKE2b-256 checksum How to use checksums |
ffd4043ef107da00018c66b1947b3b000783c2cc74772b4a528718b7b5475522
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / mediapreview-0.2.5-py3-none-any.whl
| Download URL | mediapreview-0.2.5-py3-none-any.whl |
|---|---|
| Size | 34.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
caf2f27adc4891dc26b512edf1ded7262e61de88053741343c3a2a2fcfd30963
|
|
BLAKE2b-256 checksum How to use checksums |
91cb23ae050e1ee6a28aaa5238cb115c1ddbd59ee540fd9ce97f5f7092b2fb25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|