Registry / data / webp
library0.4.0pypypi✓ verified 87d ago

The `webp` library provides Python bindings for `libwebp`, enabling encoding, decoding, reading, and saving of WebP images. It integrates seamlessly with Pillow (PIL) for image manipulation, making it easy to convert between various image formats and WebP. The library is actively maintained with regular updates, typically bundling the latest `libwebp` version to ensure security and performance. Current version is 0.4.0.

pip install webp
INSTALL
IMPORT
SIG · WEBP
W
webp
datapythonv0.4.0
Install
4.7s avg
Import
—
Disk
111MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 111.2MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 4.7s · import 0.000s · 108MB
111MB installed
● package 111MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Image
✓ from webp import Image
✗ from webp import imencode

This example demonstrates how to create a simple Pillow image, encode it into WebP format bytes, and then decode those bytes back into a Pillow image using the `webp` library's `imencode` and `imdecode` functions.

from PIL import Image import webp import io # Create a dummy image using Pillow img = Image.new('RGB', (100, 100), color = 'red') # Encode image to WebP bytes with quality 80 webp_bytes = webp.imencode(img, quality=80) print(f"Encoded WebP image size: {len(webp_bytes)} bytes") # Decode WebP bytes back into a Pillow Image decoded_img = webp.imdecode(webp_bytes) print(f"Decoded image mode: {decoded_img.mode}, size: {decoded_img.size}") # Optionally save to a file (replace 'output.webp' with desired path) # webp.imsave('output.webp', decoded_img, quality=80) # Example of reading directly from a file (if you had one) # loaded_img = webp.imread('path/to/image.webp')
Debug
Known issues
gotchaWhen compressing images using the `target_size` option, you must set `passes` to a value greater than 1 (e.g., `passes=2`). If `passes` is not specified or set to 1, `target_size` will be ignored, resulting in a potentially larger output file than intended.
fix
Ensure `passes` is set to a value like `2` or higher when using `target_size`: `webp.imencode(img, target_size=100_000, passes=2)`.
affects: 0.4.0 onwards
breakingVersions of `webp` prior to 0.3.0 bundled `libwebp 1.0.3`, which has a known vulnerability (CVE-2023-4863) related to heap buffer overflow. While the Python API remains compatible, not upgrading poses a significant security risk.
fix
Upgrade to `webp>=0.3.0` immediately to patch the `libwebp` vulnerability: `pip install --upgrade webp`.
affects: <0.3.0
gotchaIn version 0.4.0, the internal `_webp` module was nested within the `webp` package. Any direct imports like `from webp._webp import ...` will fail, as this module is not part of the public API and its path changed.
fix
Always use the public API functions directly from the `webp` package (e.g., `from webp import imencode, imdecode, imread, imsave`).
affects: >=0.4.0
Upgrade
Version history
0.4.0latest on PyPI · released Jun 9, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
24
OpenAI (training)
1
Resources
webp — pip install webp · libregistry