PHPackages                             calliostro/lastfm-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. calliostro/lastfm-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

calliostro/lastfm-client
========================

Lightweight Last.fm API client for PHP 8.1+ with modern developer comfort — Clean parameter API and minimal dependencies

v2.0.0(5mo ago)1909↓25%1MITPHPPHP ^8.1CI passing

Since Aug 29Pushed 5mo agoCompare

[ Source](https://github.com/calliostro/lastfm-client)[ Packagist](https://packagist.org/packages/calliostro/lastfm-client)[ Docs](https://github.com/calliostro/lastfm-client)[ RSS](/packages/calliostro-lastfm-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (1)

⚡ Last.fm API Client for PHP 8.1+ – Lightweight with Maximum Developer Comfort
==============================================================================

[](#-lastfm-api-client-for-php-81--lightweight-with-maximum-developer-comfort)

[![Package Version](https://camo.githubusercontent.com/dc37c27c00cc5c439ac5ee321b6cce4d54ab73e9fd397cc68f8b048b4c6ae3ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63616c6c696f7374726f2f6c617374666d2d636c69656e742e737667)](https://packagist.org/packages/calliostro/lastfm-client)[![Total Downloads](https://camo.githubusercontent.com/dae0b0d9a6fb7b3472e70046978ab89b36268a44577e0766b83b7fbb18d3ff22/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63616c6c696f7374726f2f6c617374666d2d636c69656e742e737667)](https://packagist.org/packages/calliostro/lastfm-client)[![License](https://camo.githubusercontent.com/1d3d5e38e4588b435648586d63e9add2f90101846897da1c584059ec9bfce187/68747470733a2f2f706f7365722e707567782e6f72672f63616c6c696f7374726f2f6c617374666d2d636c69656e742f6c6963656e7365)](https://packagist.org/packages/calliostro/lastfm-client)[![PHP Version](https://camo.githubusercontent.com/acffb6ae1962992d26e4466782832787e79504a6250f80d732c4283458b9f497/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75652e737667)](https://php.net)[![Guzzle](https://camo.githubusercontent.com/6a93cb104bf92d53d8f69d987b59934c07ed2b2dba8d5f6801e340ea930f1774/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f67757a7a6c652d253545362e35253743253545372e302d6f72616e67652e737667)](https://docs.guzzlephp.org/)[![CI](https://github.com/calliostro/lastfm-client/actions/workflows/ci.yml/badge.svg)](https://github.com/calliostro/lastfm-client/actions/workflows/ci.yml)[![Code Coverage](https://camo.githubusercontent.com/3b286ef6d3ca355b577ec00e6bb428039ec3cef16f61bbbf15d68b560bb0175e/68747470733a2f2f636f6465636f762e696f2f67682f63616c6c696f7374726f2f6c617374666d2d636c69656e742f67726170682f62616467652e7376673f746f6b656e3d30535634495845395631)](https://codecov.io/gh/calliostro/lastfm-client)[![PHPStan Level](https://camo.githubusercontent.com/d117944b58da8146f96b4ef7403807610a20eeb3fbcaaaf95157bbcdad1686eb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230382d627269676874677265656e2e737667)](https://phpstan.org/)[![Code Style](https://camo.githubusercontent.com/5eddc7dd141d0fac72d1558d0950b5f45c014cbbc953b722a79cf21661f73ab6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d50535231322d627269676874677265656e2e737667)](https://github.com/FriendsOfPHP/PHP-CS-Fixer)

> **🚀 MINIMAL YET POWERFUL!** Focused, lightweight Last.fm API client — as compact as possible while maintaining modern PHP comfort and clean APIs.

📦 Installation
--------------

[](#-installation)

```
composer require calliostro/lastfm-client
```

### Do You Need to Register?

[](#do-you-need-to-register)

**For ALL API calls:** Registration required

- [Register your application](https://www.last.fm/api/account/create) at Last.fm to get credentials
- **API Key needed for:** ALL methods (artist info, search, charts, etc.)

**For write operations:** Session authentication required

- **Session Key needed for:** scrobbling, loving tracks, personal collections, tagging

🚀 Quick Start
-------------

[](#-quick-start)

**Read-only data (API key required for all methods):**

```
$lastfm = LastFmClientFactory::createWithApiKey('your-api-key', 'your-secret');

$artist = $lastfm->getArtistInfo('Billie Eilish');          // Get artist info
$release = $lastfm->getAlbumInfo('The Weeknd', 'Dawn FM');  // Album info
$charts = $lastfm->getTopArtistsChart();                    // Global charts
```

**Search with API credentials:**

```
$lastfm = LastFmClientFactory::createWithApiKey('your-api-key', 'your-secret');

// Positional parameters (traditional)
$results = $lastfm->searchArtists('Taylor Swift', 20);
$tracks = $lastfm->searchTracks('Anti-Hero', 'Taylor Swift');

// Named parameters (PHP 8.0+, recommended for clarity)
$results = $lastfm->searchArtists(artist: 'Taylor Swift', limit: 20);
$tracks = $lastfm->searchTracks(track: 'Anti-Hero', artist: 'Taylor Swift');
```

**Your scrobbles (session authentication):**

```
$lastfm = LastFmClientFactory::createWithSession('your-api-key', 'your-secret', 'your-session-key');

$collection = $lastfm->getUserRecentTracks('your-username');
$loved = $lastfm->getUserLovedTracks('your-username');

// Scrobble and love tracks with named parameters
$lastfm->scrobbleTrack(
    artist: 'Bad Bunny',
    track: 'Un Verano Sin Ti',
    timestamp: time()
);
```

**Multi-user apps (mobile auth):**

```
$lastfm = LastFmClientFactory::createWithMobileAuth('your-api-key', 'your-secret', 'your-username', 'your-password');

$identity = $lastfm->getUserInfo();
```

✨ Key Features
--------------

[](#-key-features)

- **Simple Setup** – Works immediately with an API key, easy authentication for advanced features
- **Complete API Coverage** – All 55+ Last.fm API endpoints supported
- **Clean Parameter API** – Natural method calls: `getArtistInfo('Billie Eilish')` with named parameter support
- **Lightweight Focus** – Minimal codebase with only essential dependencies
- **Modern PHP Comfort** – Full IDE support, type safety, PHPStan Level 8 without bloat
- **Secure Authentication** – Full session and mobile authentication support
- **Well Tested** – 100% test coverage, PSR-12 compliant
- **Future-Ready** – PHP 8.1–8.5 compatible (beta/dev testing)
- **Pure Guzzle** – Modern HTTP client, no custom transport layers

🎵 All Last.fm API Methods as Direct Calls
-----------------------------------------

[](#-all-lastfm-api-methods-as-direct-calls)

- **Album Methods** – getAlbumInfo(), searchAlbums(), getAlbumTopTags(), addAlbumTags(), removeAlbumTag(), getAlbumTags()
- **Artist Methods** – getArtistInfo(), getArtistTopTracks(), getSimilarArtists(), searchArtists(), getArtistTopAlbums(), getArtistCorrection(), addArtistTags(), removeArtistTag(), getArtistTags(), getArtistTopTags()
- **Track Methods** – getTrackInfo(), searchTracks(), getSimilarTracks(), scrobbleTrack(), updateNowPlaying(), loveTrack(), unloveTrack(), getTrackCorrection(), addTrackTags(), removeTrackTag(), getTrackTags(), getTrackTopTags()
- **User Methods** – getUserInfo(), getUserRecentTracks(), getUserLovedTracks(), getUserTopArtists(), getUserTopTracks(), getUserTopAlbums(), getUserFriends(), getUserArtistTracks(), getUserPersonalTags(), getUserTopTags()
- **Chart Methods** – getTopArtistsChart(), getTopTracksChart(), getTopTagsChart()
- **Geography Methods** – getTopArtistsByCountry(), getTopTracksByCountry()
- **Tag Methods** – getTagInfo(), getSimilarTags(), getTagTopArtists(), getTagTopTracks(), getTagTopAlbums(), getTopTags(), getTagWeeklyChartList()
- **Authentication Methods** – getToken(), getSession(), getMobileSession()
- **Library Methods** – getLibraryArtists()
- **User Charts** – getUserWeeklyArtistChart(), getUserWeeklyAlbumChart(), getUserWeeklyTrackChart(), getUserWeeklyChartList()

*All Last.fm API endpoints are supported with clean documentation — see [Last.fm API Documentation](https://www.last.fm/api/) for complete method reference*

> 💡 **Note:** Some endpoints require authentication (scrobbling, user libraries) or specific permissions.

📋 Requirements
--------------

[](#-requirements)

- **php** ^8.1
- **guzzlehttp/guzzle** ^6.5 || ^7.0

⚙️ Configuration
----------------

[](#️-configuration)

### Configuration

[](#configuration)

**Simple (works out of the box):**

```
use Calliostro\LastFm\LastFmClientFactory;

$lastfm = LastFmClientFactory::createWithApiKey('your-api-key', 'your-secret');
```

**Advanced (middleware, custom options, etc.):**

```
use Calliostro\LastFm\LastFmClientFactory;
use GuzzleHttp\{HandlerStack, Middleware};

$handler = HandlerStack::create();
$handler->push(Middleware::retry(
    fn ($retries, $request, $response) => $retries < 3 && $response?->getStatusCode() === 429,
    fn ($retries) => 1000 * 2 ** ($retries + 1) // Rate limit handling
));

$lastfm = LastFmClientFactory::createWithApiKey('your-api-key', 'your-secret', [
    'timeout' => 30,
    'handler' => $handler,
    'headers' => [
        'User-Agent' => 'MyApp/1.0 (+https://myapp.com)',
    ]
]);
```

> 💡 **Note:** By default, the client uses `LastFmClient/2.0.0 +https://github.com/calliostro/lastfm-client` as User-Agent. You can override this by setting custom headers as shown above.

🔐 Authentication
----------------

[](#-authentication)

Get credentials at [Last.fm API Registration](https://www.last.fm/api/account/create).

### Quick Reference

[](#quick-reference)

What you want to doMethodWhat you needGet artist/track/chart info`createWithApiKey()`API key + secretSearch the database`createWithApiKey()`API key + secretScrobble tracks`createWithSession()`API key + secret + sessionAccess user collections`createWithSession()`API key + secret + sessionMobile app`createWithMobileAuth()`API key + secret + user/pass### Complete Session Flow Example

[](#complete-session-flow-example)

**Step 1: authorize.php** – Redirect user to Last.fm

```
