chindit / plex-api
A simple API library to interact with a Plex server
3.0.0
2026-08-29 13:39 UTC
Requires
- php: ^8.4
- ext-simplexml: *
- chindit/collection: ^1.0
- symfony/http-client: ^8.1
Requires (Dev)
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^13.3
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(): intreturns the number of active streaming sessions.libraries(): array<Library>returns the libraries available to the account.library(int $libraryId, bool $unwatchedOnly = false): arrayreturns the media in a library.getTracksForAlbum(int $albumId): arrayreturns the tracks in an album.getFromKey(int|string $ratingKey): ?Moviereturns a movie by its rating key.refreshMovie(Movie $movie): ?Movierefreshes a movie from Plex.getThumb(string $thumb): stringdownloads 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.