Skip to main content

chemz

chemz Logo

CI PyPI version Python versions License: MIT Typed: PEP 561

chemz is a strictly-typed Python library for reading, updating, and managing audio metadata (tags) and embedded cover art across MP3 (ID3v2) and FLAC (Vorbis Comments) files.


Installation

# uv
uv add chemz

# pip
pip install chemz

Usage

1. AudioFile Interface

AudioFile provides an object-oriented wrapper with property getters and setters for all common metadata fields, read-only stream technical properties, and context manager support for automatic persistence:

from pathlib import Path
from chemz import AudioFile

# Context manager automatically saves changes on exit
with AudioFile("track.mp3") as audio:
    audio.artist = "Burial"
    audio.title = "Chemz"
    audio.album = "Chemz / Dolphinz"
    audio.year = 2021
    audio.genre = "Atmospheric Breaks/Breakbeat/Big Beat"
    audio.bpm = 146
    audio.track_number = 1
    audio.track_total = 2
    audio.isrc = "GBLZC2000101"
    
    # Assign cover from Path or str (automatically detects MIME type)
    audio.cover = "cover.jpg"

Manual save and reload:

audio = AudioFile("track.flac")
audio.title = "Spill"
audio.artist = "acloudyskye"
audio.save()  # Writes changes to disk

audio.title = "Temporary Title"
audio.reload()  # Discards unsaved changes

2. Audio Stream Properties

Technical stream attributes are extracted directly from the audio header and exposed as read-only properties:

audio = AudioFile("recording.flac")

duration: float = audio.duration_sec  # Length in seconds (e.g. 248.5)
bitrate: int = audio.bitrate_kbps  # Bitrate in kbps (e.g. 320 or FLAC stream rate)
sample_rate: int = audio.sample_rate  # Sampling rate in Hz (e.g. 44100, 48000)
channels: int = audio.channels  # Channel count (1 for mono, 2 for stereo)
fmt: str = audio.fmt  # Format identifier ("MP3" or "FLAC")

3. Cover Art Management

Cover art can be read, updated, or removed using the cover property or dedicated methods:

audio = AudioFile("track.mp3")

# Read cover art as raw bytes (returns None if no cover exists)
cover_bytes: bytes | None = audio.cover

# Assign cover from raw bytes, Path, or string path
audio.cover = Path("artwork.png")  # Inferred MIME: image/png
audio.cover = "artwork.webp"  # Inferred MIME: image/webp
audio.cover = b"..."  # Explicit bytes (default MIME: image/jpeg)

# Delete cover art
del audio.cover
# or: audio.cover = None
# or: audio.delete_cover()

audio.save()

4. Functional API

For procedural scripts, chemz provides direct stateless facade functions:

from chemz import (
    read_track,
    write_track_tags,
    read_cover_bytes,
    write_cover_bytes,
    delete_cover,
)

# Read metadata snapshot into a TrackRecord dataclass
record = read_track("track.mp3")
print(record.artist, record.title, record.duration_sec)

# Write dictionary of tags
write_track_tags(
    "track.mp3",
    {
        "artist": "Burial",
        "title": "Chemz",
        "bpm": "146",
    },
)

# Cover operations
cover = read_cover_bytes("track.mp3")
write_cover_bytes("track.flac", cover, mime="image/jpeg")
delete_cover("track.mp3")

Supported Formats & Fields

Format Extension Metadata Engine Cover Art Implementation
MP3 .mp3 ID3v2.3 / ID3v2.4 APIC frame
FLAC .flac Vorbis Comments METADATA_BLOCK_PICTURE

Tag Mapping Reference

Field MP3 (ID3v2 Frame) FLAC (Vorbis Comment)
title TIT2 TITLE
artist TPE1 ARTIST
album TALB ALBUM
album_artist TPE2 ALBUMARTIST
year TDRC / TYER DATE / YEAR
genre TCON GENRE
track_number / track_total TRCK (n/total) TRACKNUMBER / TRACKTOTAL
disc_number / disc_total TPOS (n/total) DISCNUMBER / DISCTOTAL
bpm TBPM BPM
initial_key TKEY INITIALKEY / KEY
comment COMM COMMENT / DESCRIPTION
isrc TSRC ISRC
publisher TPUB ORGANIZATION / PUBLISHER
copyright_text (rights) TCOP COPYRIGHT / RIGHTS
composer TCOM COMPOSER
conductor TPE3 CONDUCTOR
remixer TPE4 REMIXER / MIXARTIST
original_artist TOPE ORIGINALARTIST
subtitle TIT3 SUBTITLE
group_description TIT1 GROUPING
lyrics USLT LYRICS / UNSYNCEDLYRICS
url WXXX:URL / WOAR URL / WEBSITE
encoder TSSE ENCODER / ENCODED-BY

Development

Setup

git clone https://github.com/L4zzur/chemz.git
cd chemz
uv sync

Running Checks

# Test suite
uv run pytest

# Static type checking
uv run ty check

# Linting and formatting
uv run ruff check .
uv run ruff format --check .

License

chemz is licensed under the MIT License.

Metadata

Release files for chemz 0.1.0

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

Source distribution (sdist)

Source distribution for chemz 0.1.0
File Size Uploaded
chemz-0.1.0.tar.gz 15.3 kB Details

Built distribution (wheel)

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

Total release size: 34.9 kB

Release files / chemz-0.1.0.tar.gz

Download URL chemz-0.1.0.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
53986a9d56adce080ddbcd7681933fd9d58b345cb675c60f98d3b3deffa54ffe
BLAKE2b-256 checksum
How to use checksums
b4cf188ecd1e816bc935f80bbaa58075c2cf5ca90c7f6fa0c68c2fe0042b566a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 27, 2026.

Transparency log

Release files / chemz-0.1.0-py3-none-any.whl

Download URL chemz-0.1.0-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b775173d06ae4b684f1992c39b74f3db772a14d290656d51d961fe3324a5acce
BLAKE2b-256 checksum
How to use checksums
35958eecb3605755c7ce924cadb2b4f885f498acebf17a2bdf67e58e004ea1cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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