Skip to main content

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

Installation

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 setup.py 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 setup.py 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.

Running

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

$ lastmatch.py mysterious_music.mp3

This will show metadata matches from Last.fm’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. Last.fm 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 Last.fm’s API TOS.

To-Do

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

0.6

Use audioread instead of the included pygst and pymad decoders.

0.5

Handle empty responses from the API. setup.py now searches the Homebrew user-local prefix.

0.4

Fix cleanup bug in gstdec that was causing files to remain open.

0.3

Fix typo in handling of HTTP errors. Handle cases when HTTP status line is malformed.

0.2

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.

0.1

Initial release.

Credits

This library is by Adrian Sampson. It includes the fplib source code, which is by Last.fm. 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.

Metadata

Release files for pylastfp 0.6

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

Source distribution (sdist)

Source distribution for pylastfp 0.6
File Size Uploaded Provenance Actions
pylastfp-0.6.tar.gz 47.2 kB Without provenance Details for pylastfp-0.6.tar.gz

Release files / pylastfp-0.6.tar.gz

Download URL pylastfp-0.6.tar.gz
Size 47.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5f9a32e532ab62e5663298b4b3b1db86f5466404f111ccaa9030c23ffee140f7
BLAKE2b-256 checksum
How to use checksums
d15cb373ec5171cc19ed88c5c18633dd1c34043a29699f747e3704b830a96854
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pylastfp 0.6

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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