Python bindings for's "fplib" acoustic fingerprinting library
C++ Python C
Latest commit a8c2f6c Jun 27, 2012 @sampsyo sampsyo fix compilation under clang 3.1 (fixes #5)
GCC, bizarrely, does not seem to compile methods in templates that go unused.
The getError method of the FloatingAverage<T> template class has an obvious
coding mistake, but compiling it with GCC never revealed this because getError
is never called in the library. Clang 3.1, however, seems to be somewhat more
conservative about this; it flags an error anyway. Because this method is
unused, I just removed it.
Failed to load latest commit information.
.hgignore ignore egg info Sep 16, 2010
COPYING.txt add LGPL license and associated comments Aug 28, 2010
fplib.pyx fix memory leak by explicitly freeing fingerprinter Sep 23, 2010 trick to prevent importing of wrong lastfp package Aug 30, 2010


This is a Python interface to's acoustic fingerprinting library (called fplib) and its related API services. It performs fingerprint extraction, fingerprint ID lookup, and track metadata lookup.


To install, you will need a compiler and the dependencies required by fplib itself: fftw (compiled for single-precision floats) and libsamplerate. (On Debian/Ubuntu, the packages are libfftw3-dev and libsamplerate0-dev.)

Once you have these, you can easily install from PyPI using pip:

$ pip install pylastfp

Or, if you don't have pip (or easy_install), head to the download page. The normal install command should work:

$ python install

To build from the version control source (i.e., not from a release tarball), you will also need Cython. (The source distributions include the generated C++ file, avoiding the need for Cython. This package's plays tricks to detect whether you have Cython installed.)

This library also depends on audioread to decode audio, although this dependency is technically optional. If you already have a mechanism for decoding audio files, there is no need to install audioread.


You can run the included fingerprinter/lookup script,, to test your installation:

$ mysterious_music.mp3

This will show metadata matches from's database. The script uses audioread to decode music, so it should transparently use a media library available on your system (GStreamer, FFmpeg, MAD, or Core Audio on Mac OS X).

Using in Your Code

The script exhibits the usual way to use pylastfp, which is this:

>>> import lastfp
>>> xml = lastfp.match_file(apikey, path)
>>> matches = lastfp.parse_metadata(xml)
>>> print matches[0]['artist'], '-', matches[0]['title']
The National - Fake Emprire

This example uses the match_file convenience function, which uses audioread to decode audio data. The function imports the audioread module when called, so if you don't want to depend on that, just don't call this function.

If you have your own way of decoding audio, you can use the lower-level interface:

>>> xml = lastfp.match(apikey, pcmdata, samplerate, time_in_secs)

Of course, you'll need a PCM stream for the audio you want to fingerprint. The pcmdata parameter must be an iterable of Python str or buffer objects containing PCM data as arrays of C short (16-bit integer) values.

Both functions (match and match_file) accept an additional optional parameter called metadata. It should be a dict containing your current guess at the file's metadata. might use this information to improve their database. The dict should use these keys (all of which are optional): "artist", "album", and "track".

The module internally performs thread-safe API limiting to 5 queries per second, in accordance with's API TOS.


The fingerprinting library allows for an optimization that skips decoding a few milliseconds at the beginning of every file. (See FingerprintExtractor::getToSkipMs(), as demonstrated by the example client.) Taking advantage of this will complicate the module's interface a bit because the decoding source will need to know the amount of time to skip.

Version History

Use audioread instead of the included pygst and pymad decoders. Fix compilation under clang 3.1.
Handle empty responses from the API. now searches the Homebrew user-local prefix.
Fix cleanup bug in gstdec that was causing files to remain open.
Fix typo in handling of HTTP errors. Handle cases when HTTP status line is malformed.
Fix a horrible memory leak. Fail safely when file is too short. Safely handle malformed XML returned from the API. Handle and expose HTTP failures.
Initial release.


This library is by Adrian Sampson. It includes the fplib source code, which is by fplib is licensed under the LGPLv3, so pylastfp uses the same license. pylastfp was written to be used with beets, which you should probably check out.