chindit/plex-api

A simple API library to interact with a Plex server

Maintainers

Package info

github.com/chindit/plex-api

pkg:composer/chindit/plex-api

Transparency log

Statistics

Installs: 276

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

3.0.0 2026-08-29 13:39 UTC

This package is auto-updated.

Last update: 2026-08-29 13:50:05 UTC


README

Installation

composer require chindit/plex-api

Usage

Create an account with a Plex token. The account can discover the Plex servers available to that token:

use Chindit\PlexApi\Account;

$account = new Account('MyPlexToken');
$servers = $account->getServerList();
$plexServer = $account->getServer();

When several servers are available, pass the server identifier:

$server = $servers->first();
$plexServer = $account->getServer($server->identifier);

getServer() selects a reachable connection and uses the server-specific access token returned by Plex.

It is also possible to connect directly to a known server:

$account = new Account('MyPlexToken', 'https://path.to.my.plex', 32400);
$plexServer = $account->getServer();

The port defaults to 32400. To find a Plex token, see the Plex documentation.

Available methods

Once $plexServer has been created:

  • sessionsCount(): int returns the number of active streaming sessions.
  • libraries(): array<Library> returns the libraries available to the account.
  • library(int $libraryId, bool $unwatchedOnly = false): array returns the media in a library.
  • getTracksForAlbum(int $albumId): array returns the tracks in an album.
  • getFromKey(int|string $ratingKey): ?Movie returns a movie by its rating key.
  • refreshMovie(Movie $movie): ?Movie refreshes a movie from Plex.
  • getThumb(string $thumb): string downloads a thumbnail.

Example:

$libraries = $plexServer->libraries();
$library = $libraries[0];
$media = $plexServer->library($library->getId());

Need help?

For a missing call or a bug, open an issue in the repository.