Skip to main content

Python (2.6+/3.1+) bindings for the TagLib audio metadata library

Project description


pytaglib is a package of Python (2.6+/3.1+) bindings for
Taglib. It provides a full-featured audio metadata (“tag”) library supporting
all current versions of Python.
The package gives you complete freedom over the tag names – you are not limited to common tags like
ARTIST, ALBUM etc.; instead you may use any string as key as long as the underlying metadata
format supports it (most of them do, including mp3, ogg, and FLAC). Moreover, you can even
use multiple values of the same tag, in order to e.g. store two artists, several genres, and so on.


pytaglib uses Taglib features that have been added in version 1.8-BETA, so you need at least that
version along with development headers to compile pytaglib. The recent releases of all linux
flavours nowadays ship taglib ≥ 1.8.
The use of taglib ≥ 1.9 is recommended, since that release fixes some bugs that may affect
pytaglib in less common circumstances.
In theory, pytaglib should also compile and run on Windows, though I did not succeed when I last
tried. Any help with that issue is appreciated!


Linux / Unix

Debian sid and Ubuntu trusty have binary packages for the Python 3 version, called python3-taglib.
At time of writing they are outdated, but should work nevertheless. For Arch users, there is a
package in the user repository (AUR).
If your distribution does not ship pytaglib, it can easily be installed by one of the following
  • Install from PyPI using pip:

    sudo pip install pytaglib
    Be careful to call pip for the correct Python version; you might need
    something like
    sudo pip3 pytaglib
    to build the package for Python 3 (the exact command depends on your distribution). The command
    can also be run with the --user option (and without sudo) which will install everything
    into your home directory.
  • Alternatively, you can download the source tarball and compile manually:

    python build
    python test  # optional
    sudo python install

    Again, replace python by the interpreter executable of the desired Python version.

The compiler must be able to find headers and dynamic library of TagLib. Usually, they should be
installed at standard places. If not, you can manually specify include and lib directories, e.g.:
python build_ext --include-dirs /usr/local/include --library-dirs /usr/local/lib
Note: The taglib Python extension is built from the file taglib.cpp which in turn is
auto-generated by Cython from taglib.pyx. To re-cythonize this file
instead of using the shipped taglib.cpp, invoke with the --cython option.


Install binary distribution

When you are using a 64-bit Python 3.5 on Windows, a simple pip install pytaglib should pull and install the library.

Manual installation

Note: Windows installation was tested for Python 3.5 and Win64 only. In theory, pytaglib
is compatible with any Python version and architecture, but compilation might not be
straightforward (see e.g. this
  1. Install Microsoft Visual Studio 2015 Community Edition. In the installation process, be sure to enable C/C++ support.
  2. Download and build taglib:
    1. Download the current taglib release and extract it somewhere on your computer.
    2. Start the VS2015 x64 Native Tools Command Prompt. On Windows 8/10, it might not appear in your start menu, but you can find it here: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015\Visual Studio Tools\Windows Desktop Command Prompts
    3. Navigate to the extracted taglib folder and type: cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=".\install to generate the Visual Studio project files.
    4. Type msbuild INSTALL.vcxproj /p:Configuration=Release which will “install” taglib into the install subdirectory.
  3. Still in the VS2015 command prompt, navigat to the pytaglib directory.
  4. Tell pytaglib where to find taglib: set TAGLIB_HOME="C:\Path\To\Taglib\install"
  5. Build pytaglib: python build and install: python install


The use of the library is pretty straightforward:

  1. Load the library: import taglib
  2. Open a file: f = taglib.File("/path/to/file.mp3")
  3. Read tags from the dict f.tags which maps uppercase tag names to lists of tag values (note that even single values are stored as list in order to be consistent).
  4. Some other information about the file is available as well: f.length, f.sampleRate, f.channels, f.bitrate, and f.readOnly.
  5. Alter the tags by manipulating the dictionary f.tags. You should always use uppercase tag names and lists of strings for the values.
  6. Store your changes: retval =
  7. If some tags could not be saved because they are not supported by the underlying format, those will be contained in the list returned from
The following snippet should show the most relevant features. For a complete
reference confer the online help via help(taglib.File).
$ python
Python 3.3.0 (default, Sep 29 2012, 15:50:43)
[GCC 4.7.1 20120721 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import taglib
>>> f = taglib.File("x.flac")
>>> f
>>> f.tags
{'ARTIST': ['piman', 'jzig'], 'ALBUM': ['Quod Libet Test Data'], 'TITLE': ['Silence'], 'GENRE': ['Silence'], 'TRACKNUMBER': ['02/10'], 'DATE': ['2004']}
>>> f.tags["ALBUM"] = ["Always use lists even for single values"]
>>> del f.tags["GENRE"]
>>> f.tags["ARTIST"].remove("jzig")
>>> retval =
>>> retval
Note: As pytaglib was designed mainly for Python 3, all string values returned are unicode
strings (type str in Python 3 and unicode in Python 2). On the input side, however, the library
is rather permissive and supports both byte- and unicode-strings. Internally, pytaglib converts
all strings to UTF-8 before storing them in the files.


This package also installs the small script pyprinttags. It takes one or more files as
command-line parameters and will display all known metadata of that files on the terminal.
If unsupported tags (a.k.a. non-textual information) are found, they can optionally be removed
from the file.


For bug reports or feature requests, please use the
issue tracker on GitHub. For anything else, contact
me by email.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytaglib, version 1.2.0
Filename, size File type Python version Upload date Hashes
Filename, size pytaglib-1.2.0-cp35-cp35m-win_amd64.whl (278.1 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size pytaglib-1.2.0.tar.gz (88.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page