Skip to main content

pyavif

For LLM agents: This README is the primary context source for the project. It covers installation, full API surface, and usage patterns. Build details are in docs/.

Opinionated, easy to use and performance-oriented AVIF encoder/decoder for Python. Built on libavif with nanobind for minimal overhead.

Highlights:

  • Decode (DAV1D, AOM) and encode (AOM, RAV1E) with full codec choice
  • 8/10/12-bit, RGB/RGBA, animated AVIF
  • Batch encode/decode with parallel workers
  • ICC, EXIF, XMP metadata support
  • GIL released during all C++ operations
  • Zero-copy to_torch() helper
  • Prebuilt wheels for Linux x86_64, macOS arm64, Windows x86_64 (Python 3.12+)

Installation

pip install pyavif

Quick Start

Decode

from pyavif import Decoder

decoder = Decoder()
decoder.init("image.avif")
image = decoder.get_image(0)  # numpy ndarray (H, W, C), uint8 or uint16

Encode

import numpy as np
from pyavif import Encoder

encoder = Encoder("out.avif", width=256, height=256, channels=3, depth=8)
encoder.add_frame(np.zeros((256, 256, 3), dtype=np.uint8))
encoder.finish()

API Reference

Decoder

init(filepath, decoder_threads=1, codec=DecoderCodec.DAV1D)
get_image(index, force_rgba=False) -> ndarray   # random access by frame index
next_image(force_rgba=False) -> ndarray          # sequential access
get_image_count() -> int
is_keyframe(index) -> bool
nearest_keyframe(index) -> int
get_keyframe_indices() -> list[int]
get_width() / get_height() / get_depth() -> int
has_alpha() -> bool
get_pixel_format() -> PixelFormat

BatchDecoder

BatchDecoder(file_names, max_workers=0, decoder_threads=1,
             force_rgba=False, codec=DecoderCodec.DAV1D)
next_batch() -> (int, dict[str, ndarray])       # frame_index, {path: image}
get_batch_at(frame_idx) -> (int, dict[str, ndarray])
files() -> list[str]
get_image_count() -> int

Encoder

Encoder(output_path, width, height, channels, depth, options=EncoderOptions())
add_frame(ndarray, duration=1, quality_override=None, quality_alpha_override=None)
finish()
set_icc(data: bytes) / set_exif(data: bytes) / set_xmp(data: bytes)
add_advanced_option(key: str, value: str)

BatchEncoder

BatchEncoder(output_paths, options=EncoderOptions())
add_image_batch(images, duration=1, depth=None)  # depth is required for uint16 (10 or 12)
finish_all()
files() -> list[str]

EncoderOptions

Property Type Default
quality int 80
quality_alpha int 100 (lossless)
speed int AVIF_SPEED_DEFAULT
max_threads int 1
codec EncoderCodec AOM
pixel_format PixelFormat YUV444
range Range FULL
timescale int 30
keyframe_interval int 0
repetition_count int infinite
auto_tiling bool True
tile_rows_log2 int 0
tile_cols_log2 int 0
alpha_premultiplied bool False

Enums

  • DecoderCodec: DAV1D, AOM
  • EncoderCodec: RAV1E, AOM
  • PixelFormat: YUV444, YUV422, YUV420, YUV400
  • Range: FULL, LIMITED

to_torch(array, *, layout="channels_last", pin_memory=False)

Zero-copy NumPy-to-PyTorch conversion. layout="chw" returns a CxHxW view.

License

GPLv3. See LICENSE.

Metadata

Release files for pyavif 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pyavif 0.0.4
File Interpreter ABI Platform Actions
pyavif-0.0.4-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for pyavif-0.0.4-cp312-abi3-win_amd64.whl
pyavif-0.0.4-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details for pyavif-0.0.4-cp312-abi3-manylinux_2_28_x86_64.whl
pyavif-0.0.4-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for pyavif-0.0.4-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 16.1 MB

Release files / pyavif-0.0.4-cp312-abi3-win_amd64.whl

Download URL pyavif-0.0.4-cp312-abi3-win_amd64.whl
Size 6.6 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a8250a8825297bbc8f32f9ee09d038cca6c3dc6851e0e2451bb370c6f56c0dbb
BLAKE2b-256 checksum
How to use checksums
7217fbb44f5fdd99071094fd36dff7d46287234d6c5990e6f15873d04b805318
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

Release files / pyavif-0.0.4-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL pyavif-0.0.4-cp312-abi3-manylinux_2_28_x86_64.whl
Size 5.6 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
1b2fe568e203357456f40ddb8bb752e005f067396b934d184cf061dc1c9c0fac
BLAKE2b-256 checksum
How to use checksums
41fc23619637f97f2ee8e4bc4c22fa88ba56c03ce439566389fff9994abe6ddc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

Release files / pyavif-0.0.4-cp312-abi3-macosx_11_0_arm64.whl

Download URL pyavif-0.0.4-cp312-abi3-macosx_11_0_arm64.whl
Size 3.9 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9048f96da414a962a7cfdd0a20954b5672a5c9d9864cad59103b373e6244c1c3
BLAKE2b-256 checksum
How to use checksums
cbf9b7b4c9ee014da5feab861c4018c510fd9c14d96f44bf184f75b0fcaf8a0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

Security for pyavif 0.0.4

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.

Full provenance

All 3 files in this release have been uploaded with provenance metadata.

Select from 3 files

Attestation for pyavif-0.0.4-cp312-abi3-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

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.

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