Skip to main content

riffy

PyPI version Python versions CI Docs License: MIT

Riffy provides a pure Python implementation for working with RIFF format files, with initial support for WAV audio files. The library is designed to have zero external dependencies while providing robust parsing capabilities for reading, modifying, and writing RIFF chunks.

Features

  • Zero Dependencies: Pure Python implementation with no external dependencies
  • WAV File Support: Complete WAV file parsing with format validation
  • RIFF Chunk Management: Access, add, replace, copy, and remove RIFF chunks
  • Chunk Modification & Writing: Modify chunks in memory and write valid WAV files back to disk
  • Recorder Metadata: Decode GUANO, RIFF INFO, Broadcast Wave bext, AudioMoth comments, Wildlife Acoustics WAMD, and iXML — with a unified read_metadata() view and a python -m riffy inspector
  • RF64 / BW64: Read and write 64-bit large files above the 4 GB classic-WAV limit
  • Audio Metadata Extraction: Extract sample rate, channels, bit depth, and duration
  • Format Validation: Automatic validation of file format and integrity
  • Type Safety: Full type hints (PEP 561 py.typed) for better IDE support and static analysis
  • Lightweight: Minimal footprint, perfect for embedded systems or restricted environments

Installation

From PyPI

pip install riffy

From Source

# Clone the repository
git clone https://github.com/jmcmeen/riffy.git
cd riffy

# Install in development mode
pip install -e .

# Or build and install
pip install build
python -m build
pip install dist/riffy-*.whl

For Development

# Install with development dependencies
pip install -e ".[dev]"

Quick Start

Basic WAV File Parsing

from riffy import WAVParser

# Parse a WAV file (parsing happens automatically on initialization)
parser = WAVParser("audio.wav")

# Access format information
info = parser.get_info()
print(f"Sample Rate: {info['format']['sample_rate']} Hz")
print(f"Channels: {info['format']['channels']}")
print(f"Bit Depth: {info['format']['bits_per_sample']} bits")
print(f"Duration: {info['duration_seconds']:.2f} seconds")

Accessing RIFF Chunks

from riffy import WAVParser

# Parsing happens automatically on initialization
parser = WAVParser("audio.wav")

# Access all chunks. Each ID maps to a list of occurrences, so a file may
# carry more than one chunk with the same ID (e.g. multiple LIST chunks).
for chunk_id, chunk_list in parser.chunks.items():
    for chunk in chunk_list:
        print(f"Chunk: {chunk_id}, Size: {chunk.size} bytes, Offset: {chunk.offset}")

# Access a specific chunk (first occurrence) via the convenience accessor
fmt_chunk = parser.get_chunk("fmt ")
if fmt_chunk is not None:
    print(f"Format chunk size: {fmt_chunk.size}")

Working with Audio Data

from riffy import WAVParser

# Parsing happens automatically on initialization
parser = WAVParser("audio.wav")

# Access raw audio data
audio_data = parser.audio_data
print(f"Audio data size: {len(audio_data)} bytes")

# Get sample count
info = parser.get_info()
print(f"Total samples: {info['sample_count']}")

Exporting Chunks to Binary Files

from riffy import WAVParser

# Parsing happens automatically on initialization
parser = WAVParser("audio.wav")

# Export raw audio data (most common use case)
bytes_written = parser.export_audio_data("raw_audio.bin")
print(f"Exported {bytes_written} bytes of audio data")

# Export specific chunks
parser.export_chunk("fmt ", "format_chunk.bin")
parser.export_chunk("data", "data_chunk.bin")

# List all available chunks before exporting. Each ID maps to a list of
# occurrences, so iterate the inner list.
chunks = parser.list_chunks()
for chunk_id, occurrences in chunks.items():
    for info in occurrences:
        print(f"Chunk '{chunk_id}': {info['size']} bytes at offset {info['offset']}")

Modifying and Writing WAV Files

Riffy can modify chunks in memory and write a valid WAV file back to disk:

from riffy import WAVParser

parser = WAVParser("audio.wav")

# Replace the audio data with new bytes
parser.replace_chunk("data", new_audio_bytes)

# Add a custom metadata chunk (IDs must be exactly 4 ASCII characters)
parser.add_chunk("INFO", b"Artist: Example\x00")

# set_chunk adds the chunk if missing, or replaces it if present
parser.set_chunk("NOTE", b"recorded 2026\x00")

# Copy a chunk from another file
other = WAVParser("other.wav")
parser.copy_chunk_from_parser("data", other)

# Write the modified file (overwrite=False refuses to clobber the source)
bytes_written = parser.write_wav("modified.wav")
print(f"Wrote {bytes_written} bytes")

Note: write_wav keeps the file's chunk order and puts chunks you added after the existing ones, in the order you added them. An unedited parse/write round-trip of a well-formed classic WAV (correct sizes, padded, nothing after the last chunk) is byte-for-byte identical. See Limitations.

Reading Recorder Metadata

Field recorders embed rich metadata inside the WAV container. One call surfaces whichever standards a file contains:

from riffy import read_metadata

meta = read_metadata("recording.wav")
print(meta.sources)  # e.g. ('guano',) or ('info', 'audiomoth')

if meta.guano is not None:
    print(meta.guano.timestamp)  # timezone-aware datetime
    print(meta.guano.loc_position)  # (lat, lon)
    print(meta.guano.make, meta.guano.model)

if meta.audiomoth is not None:
    print(meta.audiomoth.device_id, meta.audiomoth.gain)

Or drive riffy from the command line (standard library only). Installing the package puts a riffy command on your PATH; python -m riffy … is equivalent.

# Read commands
riffy recording.wav                 # inspect metadata (human-readable; the default)
riffy inspect recording.wav --json  # JSON-serializable dump
riffy diff a.wav b.wav              # chunk + metadata differences (--json, --all)
riffy chunks recording.wav          # list every chunk with size and offset
riffy info recording.wav            # audio format and file details
riffy export recording.wav --audio out.raw           # export raw audio
riffy export recording.wav --chunk guan guan.bin     # export a chunk by ID

# Write commands — a DRY RUN by default; add --apply to write.
# Writes are atomic; --backup keeps a .bak, --force-rf64 emits the large-file form.
riffy set recording.wav --guano 'Make=Riffy' --guano 'WA|Prefix=SITE7' --apply
riffy set recording.wav --info 'IART=Field Team' --remove-info ICMT --apply
riffy set recording.wav --bext 'description=Dawn chorus' --bext 'version=2' --apply
riffy set recording.wav --wamd 'GPS=10.318 -84.074' --apply   # Wildlife Acoustics WAMD
riffy chunk add recording.wav NOTE note.bin --apply --backup
riffy chunk copy recording.wav guan --from other.wav --apply
riffy chunk remove recording.wav guan --apply

riffy decodes GUANO, RIFF INFO, Broadcast Wave bext, AudioMoth comments, Wildlife Acoustics WAMD, and iXML. See the Recorder Metadata guide for typed read/write examples and the device-support matrix, and the CLI reference for every subcommand.

Getting Detailed File Information

from riffy import WAVParser
import json

# Parsing happens automatically on initialization
parser = WAVParser("audio.wav")
info = parser.get_info()

# Pretty print all information
print(json.dumps(info, indent=2))

Output example:

{
  "file_path": "/path/to/audio.wav",
  "file_size": 1234567,
  "format": {
    "audio_format": 1,
    "channels": 2,
    "sample_rate": 44100,
    "byte_rate": 176400,
    "block_align": 4,
    "bits_per_sample": 16,
    "is_pcm": true
  },
  "duration_seconds": 3.5,
  "audio_data_size": 617400,
  "sample_count": 154350,
  "chunks": {
    "fmt ": [16],
    "data": [617400]
  }
}

Supported Formats

Currently, Riffy supports:

  • WAV Files: integer PCM (8–32 bit) and IEEE float (32/64 bit), plain or WAVE_FORMAT_EXTENSIBLE (24-bit and multichannel recorder files)
  • RF64 / BW64: 64-bit large files (above 4 GB) via the ds64 chunk, read and write
  • RIFF Chunks: Standard chunk parsing, modification, and writing for WAV files
  • Recorder Metadata: GUANO, RIFF INFO, Broadcast Wave bext, Wildlife Acoustics WAMD (read/write), AudioMoth comments (read-only), and iXML (read-only)

Planned Support

  • AVI files
  • WebP images
  • Additional WAV compression formats

Limitations

  • Uncompressed only: compressed WAV formats (ADPCM, A-law, mu-law, MP3-in-WAV, …), and extensible files with any other subformat, are rejected with UnsupportedFormatError.
  • Memory: by default the whole file, audio included, is read into memory. Pass read_audio=False to WAVParser to read only the headers and stream the audio when writing or exporting; the metadata readers and CLI do this.
  • Multiple chunks per ID: chunks maps each chunk ID to a list of every occurrence in file order, so files containing multiple chunks with the same ID (e.g. several LIST chunks) preserve all of them. Use get_chunk(id) for the common single-occurrence case.
  • Chunk ordering on write: write_wav keeps the file's chunk order, with added chunks after the existing ones. It does move fmt ahead of data if a file has them the other way round, recomputes sizes and padding, and drops bytes after the last chunk, so a malformed file isn't reproduced byte for byte. The RF64/BW64 form is used only when a size crosses the 4 GB limit (or with force_rf64); a leading JUNK chunk sized for ds64 is then replaced by it.
  • AudioMoth parsing is best-effort: the comment format is undocumented and firmware-dependent. riffy decodes each field independently (partial extraction) and always keeps the raw comment string; newer firmware may leave some fields unparsed.

Requirements

  • Python 3.10 or higher
  • No external dependencies!

Development

# Install with development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=riffy --cov-report=html

# Lint and format with Ruff
ruff check .
ruff format .

# Type-check with mypy
mypy

See CONTRIBUTING.md for the full contributor guide.

Building the Docs

pip install -e ".[docs]"
mkdocs serve   # preview locally at http://127.0.0.1:8000

Contributing

Contributions are welcome! Please read CONTRIBUTING.md before opening a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See CHANGELOG.md for the full release history.

References

Support

For bugs, feature requests, or questions, please open an issue.

Metadata

Release files for riffy 0.3.10

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

Source distribution (sdist)

Source distribution for riffy 0.3.10
File Size Uploaded Provenance Actions
riffy-0.3.10.tar.gz 57.4 kB With provenance Details for riffy-0.3.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for riffy 0.3.10
File Interpreter ABI Platform Actions
riffy-0.3.10-py3-none-any.whl Python 3 none any Details for riffy-0.3.10-py3-none-any.whl

Total release size: 115.2 kB

Release files / riffy-0.3.10.tar.gz

Download URL riffy-0.3.10.tar.gz
Size 57.4 kB
Tags Source
SHA-256 checksum
How to use checksums
09417431bf5be3787f08436c148cbf5521c9db177495ed39cf2e4467610e7025
BLAKE2b-256 checksum
How to use checksums
e31818c3e4144aff353516c8b2661dcbf27c14b0549dcc9c3bc0c11dfebaefce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 31, 2026.

Transparency log

Release files / riffy-0.3.10-py3-none-any.whl

Download URL riffy-0.3.10-py3-none-any.whl
Size 57.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62ca3cb5c2dc56f698a658bbfb79bb848e14edefb97ae024e35713b97deb89b3
BLAKE2b-256 checksum
How to use checksums
bbe7dc4ad2d2e16b353c1495842e197b164be0c828ac6d3608441ae0ad4ba3fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 31, 2026.

Transparency log

Security for riffy 0.3.10

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for riffy-0.3.10.tar.gz

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 Oct 31, 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