Lightweight unofficial Python bindings for Tencent libpag, focused on encoding WebP frame sequences and embedding audio into PAG files.
Project description
pylibpag
Lightweight unofficial Python bindings for Tencent libpag, focused on encoding WebP frame sequences and embedding audio into PAG files.
This repository is a source fork of the official libpag project. The Python layer is kept in the separate python/
directory so upstream libpag updates can be rebased without modifying its existing source files.
This is an unofficial project and is not affiliated with or endorsed by Tencent.
Features
- Encode one or more already-encoded WebP frames into a bitmap PAG animation
- Preserve WebP alpha data for transparent animations
- Optionally embed AAC audio stored in an MPEG-4 container, normally M4A bytes
- Run independent encode calls concurrently from Python threads without a global conversion lock
- Use one native wheel per platform on both regular CPython 3.14 and free-threaded CPython 3.14t
- Avoid a CPython extension ABI by exposing a small C interface through
ctypes.CDLL
Installation
Install from PyPI:
python -m pip install pylibpag
Python 3.14 or newer is required.
Usage
from pathlib import Path
import pylibpag
frames = [
Path("frame-001.webp").read_bytes(),
Path("frame-002.webp").read_bytes(),
]
pag_bytes = pylibpag.encode_webp_frames(
frames,
width=512,
height=512,
frame_rate=30.0,
)
Path("animation.pag").write_bytes(pag_bytes)
Transparent frames
Pass WebP frames that already contain alpha. pylibpag stores the encoded frame bytes in a PAG bitmap sequence; it does
not decode, resize, or otherwise convert the source images.
Audio
libpag expects composition audio to be AAC in an MPEG-4 container. An M4A file can be passed directly as bytes:
pag_bytes = pylibpag.encode_webp_frames(
frames,
width=512,
height=512,
frame_rate=30.0,
audio=Path("audio.m4a").read_bytes(),
audio_start_frame=0,
)
The native layer embeds audio bytes without transcoding or validating the codec. Convert MP3, WAV, PCM, raw AAC, or other inputs to AAC-in-MP4 in your Python media pipeline first. Embedded audio does not automatically extend the visual frame duration.
Threading
Independent calls can run concurrently:
from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor(max_workers=8) as executor:
pag_files = list(
executor.map(
lambda frame_group: pylibpag.encode_webp_frames(
frame_group,
width=512,
height=512,
),
frame_groups,
)
)
Each call creates its own libpag composition, frame objects, input copies, error state, and output buffer. Do not share or mutate an input buffer while a call is using it.
API
pylibpag.encode_webp_frames(
frames,
*,
width,
height,
frame_rate=30.0,
audio=None,
audio_start_frame=0,
) -> bytes
frames: ordered iterable of encoded WebP bufferswidthandheight: positive composition dimensionsframe_rate: finite positive frames per secondaudio: optional AAC-in-MP4/M4A bufferaudio_start_frame: signed frame offset for the first audio frame
Native encode failures raise pylibpag.PAGEncodeError.
Platform support
Prebuilt wheels are provided for:
- Linux amd64 using the
manylinux_2_28build policy - Linux arm64 using the
manylinux_2_28build policy - macOS arm64 with a macOS 11.0 deployment target
A single wheel per platform supports both regular CPython 3.14 and free-threaded CPython 3.14t, and is tested with both runtimes.
Scope
pylibpag deliberately does not provide media conversion or PAG playback. Convert PNG, video, APNG, or other source
formats to WebP frames in Python, then pass those bytes to this package. This keeps the compiled binding small and the
upstream integration easy to maintain.
Development
For upstream libpag SDK development and platform build instructions, see the official libpag development guide. Python wheel builds and tests are defined in the GitHub Actions workflow.
License
Licensed under the Apache License 2.0. libpag is developed by Tencent. This unofficial Python package preserves the upstream license and attribution.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pylibpag-4.5.81-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pylibpag-4.5.81-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.0 MB
- Tags: Python 3, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24bbf68c9dc41b416ad9712e935082f5ac62bf02661681277b2f0d1f47aa52e9
|
|
| MD5 |
ef549f595110f6fcfd2af77f085114e7
|
|
| BLAKE2b-256 |
e7f51e2b9b4f79e4823b121b9ef64c7205ded0e0d4970ef96231cf4e0b70ece4
|
Provenance
The following attestation bundles were made for pylibpag-4.5.81-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on gordonhwc/pylibpag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pylibpag-4.5.81-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
24bbf68c9dc41b416ad9712e935082f5ac62bf02661681277b2f0d1f47aa52e9 - Sigstore transparency entry: 2223760472
- Sigstore integration time:
-
Permalink:
gordonhwc/pylibpag@a8a08266f96c1c2ab9afaae8660893910d72488b -
Branch / Tag:
refs/tags/pylibpag-v4.5.81 - Owner: https://github.com/gordonhwc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a8a08266f96c1c2ab9afaae8660893910d72488b -
Trigger Event:
release
-
Statement type:
File details
Details for the file pylibpag-4.5.81-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: pylibpag-4.5.81-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 1.5 MB
- Tags: Python 3, manylinux: glibc 2.27+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68e016978faa1341a88d2302666a1857bf4892700e786104053dd7195e4cd6b0
|
|
| MD5 |
639957740eeea32be07c35d711f23449
|
|
| BLAKE2b-256 |
bea3dc411c6f52b27ae13fa0457da8689c2561d76eca3053ce4be26f794c33a9
|
Provenance
The following attestation bundles were made for pylibpag-4.5.81-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
release.yml on gordonhwc/pylibpag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pylibpag-4.5.81-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
68e016978faa1341a88d2302666a1857bf4892700e786104053dd7195e4cd6b0 - Sigstore transparency entry: 2223760380
- Sigstore integration time:
-
Permalink:
gordonhwc/pylibpag@a8a08266f96c1c2ab9afaae8660893910d72488b -
Branch / Tag:
refs/tags/pylibpag-v4.5.81 - Owner: https://github.com/gordonhwc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a8a08266f96c1c2ab9afaae8660893910d72488b -
Trigger Event:
release
-
Statement type:
File details
Details for the file pylibpag-4.5.81-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: pylibpag-4.5.81-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b52d2f7e985654929e519127f8d9361ed9b8923c16440016844c48b67390a78f
|
|
| MD5 |
32ae5d13d778a623d83e12bf0802bc1b
|
|
| BLAKE2b-256 |
17f3a49112a4dbfa7dd6c6efc37c5f9aacecfca154b3954fde858b478564319c
|
Provenance
The following attestation bundles were made for pylibpag-4.5.81-py3-none-macosx_11_0_arm64.whl:
Publisher:
release.yml on gordonhwc/pylibpag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pylibpag-4.5.81-py3-none-macosx_11_0_arm64.whl -
Subject digest:
b52d2f7e985654929e519127f8d9361ed9b8923c16440016844c48b67390a78f - Sigstore transparency entry: 2223760224
- Sigstore integration time:
-
Permalink:
gordonhwc/pylibpag@a8a08266f96c1c2ab9afaae8660893910d72488b -
Branch / Tag:
refs/tags/pylibpag-v4.5.81 - Owner: https://github.com/gordonhwc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a8a08266f96c1c2ab9afaae8660893910d72488b -
Trigger Event:
release
-
Statement type: