discid API

Python binding of Libdiscid

Libdiscid is a library to calculate MusicBrainz Disc IDs. This module provides a python-like API for that functionality.

The user is expected to create a DiscId object, feed it with some type of TOC and extract the generated information.

Importing this module will open libdiscid at the same time and will raise OSError when libdiscid is not found.

At the module level there are these constants available:


The default device to use for DiscId.read() on this platform given as a unicode or str object.


The supported features for the platform as a list of strings. The full set currently is ['read', 'MCN', 'ISRC']. Some Functions can raise NotImplementedError when a feature is not available.

DiscId object

The user is expected to create a DiscId object, feed it with some type of TOC and extract the generated information.

class discid.DiscId

The main class of this module.

The initialization will reserve some memory for internal data structures.

You should use read() or put() before getting any data from an object of this class:


Reads the TOC from the device given as string.

That string can be either of: str, unicode or bytes. However, it should in no case contain non-ASCII characters.

A DiscError exception is raised when the reading fails, and NotImplementedError when libdiscid doesn’t support reading discs on the current platform.

put(first, last, offsets)

Creates a TOC based on the offsets given.

Takes the first and last audio tracks as int and offsets is supposed to be the same as track_offsets. That is: offsets[0] are the total number of sectors and the following are the offsets of each track.

When the a TOC was successfully populated, you can access the informational attributes:


This is the MusicBrainz Disc ID.

It is set after a the TOC was populated or None. If set, this is a unicode or str object.


With this url you can submit the current TOC as a new MusicBrainz Disc ID.

If there is no populated TOC the url is None. Otherwise this is a unicode or str object.


Number of the first track


Number of the last track


Total sector count


A list of all track offsets.

The first element is the leadout track and contains the total number of sectors on the disc. The following elements are the offsets for all audio tracks. track_offsets[i] is the offset for the i-th track (as int).

After you are done with the object, you should free the memory allocated for it:


This will free the internal allocated memory for the object. You can’t use this object anymore afterwards.

Please consider using the with statement for the object, which will take care of this destruction automatically.

The discid module includes a custom exception to handle specific problems:

exception discid.DiscError

Bases: exceptions.IOError

DiscId.read() will raise this exception when an error occured. An error string (unicode/str) is provided.

Table Of Contents

Previous topic


Next topic


This Page