WebP Python bindings
Installation
pip install webp
On Windows you may encounter the following error during installation:
conans.errors.ConanException: 'settings.compiler' value not defined
This means that you need to install a C compiler and configure Conan so that it knows which compiler to use. See https://github.com/anibali/pywebp/issues/20 for more details.
Requirements
- Python 3.8+
Usage
import webp
Simple API
# Save an image
webp.save_image(img, 'image.webp', quality=80)
# Load an image
img = webp.load_image('image.webp', 'RGBA')
# Save an animation
webp.save_images(imgs, 'anim.webp', fps=10, lossless=True)
# Load an animation
imgs = webp.load_images('anim.webp', 'RGB', fps=10)
If you prefer working with numpy arrays, use the functions imwrite, imread, mimwrite,
and mimread instead.
Advanced API
# Encode a PIL image to WebP in memory, with encoder hints
pic = webp.WebPPicture.from_pil(img)
config = WebPConfig.new(preset=webp.WebPPreset.PHOTO, quality=70)
buf = pic.encode(config).buffer()
# Read a WebP file and decode to a BGR numpy array
with open('image.webp', 'rb') as f:
webp_data = webp.WebPData.from_buffer(f.read())
arr = webp_data.decode(color_mode=WebPColorMode.BGR)
# Save an animation
enc = webp.WebPAnimEncoder.new(width, height)
timestamp_ms = 0
for img in imgs:
pic = webp.WebPPicture.from_pil(img)
enc.encode_frame(pic, timestamp_ms)
timestamp_ms += 250
anim_data = enc.assemble(timestamp_ms)
with open('anim.webp', 'wb') as f:
f.write(anim_data.buffer())
# Load an animation
with open('anim.webp', 'rb') as f:
webp_data = webp.WebPData.from_buffer(f.read())
dec = webp.WebPAnimDecoder.new(webp_data)
for arr, timestamp_ms in dec.frames():
# `arr` contains decoded pixels for the frame
# `timestamp_ms` contains the _end_ time of the frame
pass
Features
- Picture encoding/decoding
- Animation encoding/decoding
- Automatic memory management
- Simple API for working with
PIL.Imageobjects
Not implemented
- Encoding/decoding still images in YUV color mode
- Advanced muxing/demuxing (color profiles, etc.)
- Expose all useful fields
Developer notes
Setting up
- Install
mambaandconda-lock. The easiest way to do this is by installing Mambaforge and then runningmamba install conda-lock. - Create and activate the Conda environment:
$ conda-lock install -n webp $ mamba activate webp
- Install PyPI dependencies:
$ pdm install -G:all
Running tests
$ pytest tests/
Cutting a new release
- Ensure that tests are passing and everything is ready for release.
- Create and push a Git tag:
$ git tag v0.1.6 $ git push --tags
- Download the artifacts from GitHub Actions, which will include the source distribution tarball and binary wheels.
- Create a new release on GitHub from the tagged commit and upload the packages as attachments to the release.
- Also upload the packages to PyPI using Twine:
$ twine upload webp-*.tar.gz webp-*.whl
- Bump the version number in
pyproject.tomland create a commit, signalling the start of development on the next version.
These files should also be added to a GitHub release.
Known issues
- An animation where all frames are identical will "collapse" in on itself,
resulting in a single frame. Unfortunately, WebP seems to discard timestamp
information in this case, which breaks
webp.load_imageswhen the FPS is specified. - There are currently no 32-bit binaries of libwebp uploaded to Conan Center. If you are running 32-bit Python, libwebp will be built from source.
Metadata
Release files for webp 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| webp-0.4.0.tar.gz | 20.1 kB | Without provenance | Details for webp-0.4.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| webp-0.4.0-cp38-abi3-win_arm64.whl | CPython 3.8 | abi3 | Windows ARM64 | Details for webp-0.4.0-cp38-abi3-win_arm64.whl |
| webp-0.4.0-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details for webp-0.4.0-cp38-abi3-win_amd64.whl |
| webp-0.4.0-cp38-abi3-musllinux_1_1_x86_64.whl | CPython 3.8 | abi3 | Linux musl 1.1+ x86-64 | Details for webp-0.4.0-cp38-abi3-musllinux_1_1_x86_64.whl |
| webp-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ x86-64 | Details for webp-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| webp-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ ARM64 | Details for webp-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
| webp-0.4.0-cp38-abi3-macosx_10_9_universal2.whl | CPython 3.8 | abi3 | macOS 10.9+ universal2 (ARM64, x86-64) | Details for webp-0.4.0-cp38-abi3-macosx_10_9_universal2.whl |
Total release size: 2.2 MB
Release files / webp-0.4.0.tar.gz
| Download URL | webp-0.4.0.tar.gz |
|---|---|
| Size | 20.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9265565839ac938327705c5fbfa3d8ceeeb9b5a2c1c3367231caa0bad29464c7
|
|
BLAKE2b-256 checksum How to use checksums |
07aa2a64b903367eb3be5e0b5f89e6e6e54162281712d3a0512dbdfaf03ea97f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.17
|
Release files / webp-0.4.0-cp38-abi3-win_arm64.whl
| Download URL | webp-0.4.0-cp38-abi3-win_arm64.whl |
|---|---|
| Size | 189.7 kB |
| Tags | CPython 3.8 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
ed479890ca954404925e99c245fb8e456903ab5e17884081304f64d4434763e2
|
|
BLAKE2b-256 checksum How to use checksums |
a3ffe7e4245e8cdeee42a7e666bd80e0e48b255405508ae87997640f73b13384
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.17
|
Release files / webp-0.4.0-cp38-abi3-win_amd64.whl
| Download URL | webp-0.4.0-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 218.2 kB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
3c5f7718a3e9e19018ed31765273ff323bdf5820d8255d0001d66ea9c3489d0a
|
|
BLAKE2b-256 checksum How to use checksums |
638d9a79d73249c63e0d216c832697d76072c9f2b0cb09792618972ba9fe3133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.17
|
Release files / webp-0.4.0-cp38-abi3-musllinux_1_1_x86_64.whl
| Download URL | webp-0.4.0-cp38-abi3-musllinux_1_1_x86_64.whl |
|---|---|
| Size | 412.2 kB |
| Tags | CPython 3.8 Linux musl 1.1+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
016bbea5bc61708708873ecd75dbb29552d28e6bd9180b4e1352d3b1d6811f01
|
|
BLAKE2b-256 checksum How to use checksums |
c07178751690f32c8bf80d19d2809b4faca5e51c13bcee0a3139941692cd858e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.17
|
Release files / webp-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | webp-0.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 405.1 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ca6aa8cdff582794146dfecd24aeb2b7986559cca5a1d12b504ffca6d87417d4
|
|
BLAKE2b-256 checksum How to use checksums |
ceb335269831a40129b52091e4f8837d6a07c0063221e92805203ac16b9426ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.17
|
Release files / webp-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | webp-0.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 356.9 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
5a58a04d74c3323a760cf1b581f5c0ea36f8df426065f434c5fb4c7eb06d2e26
|
|
BLAKE2b-256 checksum How to use checksums |
f75ca99e30271160a1a5eaa9a886c882cf8a8f4db178b63e878523e768dc364d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.17
|
Release files / webp-0.4.0-cp38-abi3-macosx_10_9_universal2.whl
| Download URL | webp-0.4.0-cp38-abi3-macosx_10_9_universal2.whl |
|---|---|
| Size | 605.5 kB |
| Tags | CPython 3.8 abi3 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
697f5180df0f6ea70659872f835d4727009492e5d9550772a562e559fc06fc75
|
|
BLAKE2b-256 checksum How to use checksums |
81b45772851d64a5be2ea711d3fca988742d5f9ce28cf6c13fb8e4ed8a4909d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.17
|
Security for webp 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.