Library plexapi.library

class plexapi.library.Library(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a PlexServer library. This contains all sections of media defined in your Plex server including video, shows and audio.

Variables:
  • key (str) – ‘/library’

  • identifier (str) – Unknown (‘com.plexapp.plugins.library’).

  • mediaTagVersion (str) – Unknown (/system/bundle/media/flags/)

  • server (PlexServer) – PlexServer this client is connected to.

  • title1 (str) – ‘Plex Library’ (not sure how useful this is).

  • title2 (str) – Second title (this is blank on my setup).

sections()[source]

Returns a list of all media sections in this library. Library sections may be any of MovieSection, ShowSection, MusicSection, PhotoSection.

section(title)[source]

Returns the LibrarySection that matches the specified title.

Parameters:

title (str) – Title of the section to return.

sectionByID(sectionID)[source]

Returns the LibrarySection that matches the specified sectionID.

Parameters:

sectionID (int) – ID of the section to return.

Raises:

NotFound – The library section ID is not found on the server.

hubs(sectionID=None, identifier=None, **kwargs)[source]

Returns a list of Hub across all library sections.

Parameters:
  • sectionID (int or str or list, optional) – IDs of the sections to limit results or “playlists”.

  • identifier (str or list, optional) – Names of identifiers to limit results. Available on Hub instances as the hubIdentifier attribute. Examples: ‘home.continue’ or ‘home.ondeck’

all(**kwargs)[source]

Returns a list of all media from all library sections. This may be a very large dataset to retrieve.

onDeck()[source]

Returns a list of all media items on deck.

recentlyAdded()[source]

Returns a list of all media items recently added.

search(title=None, libtype=None, **kwargs)[source]

Searching within a library section is much more powerful. It seems certain attributes on the media objects can be targeted to filter this search down a bit, but I haven’t found the documentation for it.

Example: “studio=Comedy%20Central” or “year=1999” “title=Kung Fu” all work. Other items such as actor=<id> seem to work, but require you already know the id of the actor. TLDR: This is untested but seems to work. Use library section search when you can.

cleanBundles()[source]

Poster images and other metadata for items in your library are kept in “bundle” packages. When you remove items from your library, these bundles aren’t immediately removed. Removing these old bundles can reduce the size of your install. By default, your server will automatically clean up old bundles once a week as part of Scheduled Tasks.

emptyTrash()[source]

If a library has items in the Library Trash, use this option to empty the Trash.

optimize()[source]

The Optimize option cleans up the server database from unused or fragmented data. For example, if you have deleted or added an entire library or many items in a library, you may like to optimize the database.

update()[source]

Scan this library for new items.

cancelUpdate()[source]

Cancel a library update.

refresh()[source]

Forces a download of fresh media information from the internet. This can take a long time. Any locked fields are not modified.

deleteMediaPreviews()[source]

Delete the preview thumbnails for the all sections. This cannot be undone. Recreating media preview files can take hours or even days.

add(name='', type='', agent='', scanner='', location='', language='en', *args, **kwargs)[source]

Simplified add for the most common options.

Parameters:
  • name (str) – Name of the library

  • agent (str) – Example com.plexapp.agents.imdb

  • type (str) – movie, show, # check me

  • location (str or list) – /path/to/files, [“/path/to/files”, “/path/to/morefiles”]

  • language (str) – Two letter language fx en

  • kwargs (dict) – Advanced options should be passed as a dict. where the id is the key.

Photo Preferences

  • agent (str): com.plexapp.agents.none

  • enableAutoPhotoTags (bool): Tag photos. Default value false.

  • enableBIFGeneration (bool): Enable video preview thumbnails. Default value true.

  • includeInGlobal (bool): Include in dashboard. Default value true.

  • scanner (str): Plex Photo Scanner

Movie Preferences

  • agent (str): com.plexapp.agents.none, com.plexapp.agents.imdb, tv.plex.agents.movie, com.plexapp.agents.themoviedb

  • enableBIFGeneration (bool): Enable video preview thumbnails. Default value true.

  • enableCinemaTrailers (bool): Enable Cinema Trailers. Default value true.

  • includeInGlobal (bool): Include in dashboard. Default value true.

  • scanner (str): Plex Movie, Plex Movie Scanner, Plex Video Files Scanner, Plex Video Files

IMDB Movie Options (com.plexapp.agents.imdb)

  • title (bool): Localized titles. Default value false.

  • extras (bool): Find trailers and extras automatically (Plex Pass required). Default value true.

  • only_trailers (bool): Skip extras which aren’t trailers. Default value false.

  • redband (bool): Use red band (restricted audiences) trailers when available. Default value false.

  • native_subs (bool): Include extras with subtitles in Library language. Default value false.

  • cast_list (int): Cast List Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database.

  • ratings (int): Ratings Source, Default value 0 Possible options: 0:Rotten Tomatoes, 1:IMDb, 2:The Movie Database.

  • summary (int): Plot Summary Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database.

  • country (int): Default value 46 Possible options 0:Argentina, 1:Australia, 2:Austria, 3:Belgium, 4:Belize, 5:Bolivia, 6:Brazil, 7:Canada, 8:Chile, 9:Colombia, 10:Costa Rica, 11:Czech Republic, 12:Denmark, 13:Dominican Republic, 14:Ecuador, 15:El Salvador, 16:France, 17:Germany, 18:Guatemala, 19:Honduras, 20:Hong Kong SAR, 21:Ireland, 22:Italy, 23:Jamaica, 24:Korea, 25:Liechtenstein, 26:Luxembourg, 27:Mexico, 28:Netherlands, 29:New Zealand, 30:Nicaragua, 31:Panama, 32:Paraguay, 33:Peru, 34:Portugal, 35:Peoples Republic of China, 36:Puerto Rico, 37:Russia, 38:Singapore, 39:South Africa, 40:Spain, 41:Sweden, 42:Switzerland, 43:Taiwan, 44:Trinidad, 45:United Kingdom, 46:United States, 47:Uruguay, 48:Venezuela.

  • collections (bool): Use collection info from The Movie Database. Default value false.

  • localart (bool): Prefer artwork based on library language. Default value true.

  • adult (bool): Include adult content. Default value false.

  • usage (bool): Send anonymous usage data to Plex. Default value true.

TheMovieDB Movie Options (com.plexapp.agents.themoviedb)

  • collections (bool): Use collection info from The Movie Database. Default value false.

  • localart (bool): Prefer artwork based on library language. Default value true.

  • adult (bool): Include adult content. Default value false.

  • country (int): Country (used for release date and content rating). Default value 47 Possible options 0:, 1:Argentina, 2:Australia, 3:Austria, 4:Belgium, 5:Belize, 6:Bolivia, 7:Brazil, 8:Canada, 9:Chile, 10:Colombia, 11:Costa Rica, 12:Czech Republic, 13:Denmark, 14:Dominican Republic, 15:Ecuador, 16:El Salvador, 17:France, 18:Germany, 19:Guatemala, 20:Honduras, 21:Hong Kong SAR, 22:Ireland, 23:Italy, 24:Jamaica, 25:Korea, 26:Liechtenstein, 27:Luxembourg, 28:Mexico, 29:Netherlands, 30:New Zealand, 31:Nicaragua, 32:Panama, 33:Paraguay, 34:Peru, 35:Portugal, 36:Peoples Republic of China, 37:Puerto Rico, 38:Russia, 39:Singapore, 40:South Africa, 41:Spain, 42:Sweden, 43:Switzerland, 44:Taiwan, 45:Trinidad, 46:United Kingdom, 47:United States, 48:Uruguay, 49:Venezuela.

Show Preferences

  • agent (str): com.plexapp.agents.none, com.plexapp.agents.thetvdb, com.plexapp.agents.themoviedb, tv.plex.agents.series

  • enableBIFGeneration (bool): Enable video preview thumbnails. Default value true.

  • episodeSort (int): Episode order. Default -1 Possible options: 0:Oldest first, 1:Newest first.

  • flattenSeasons (int): Seasons. Default value 0 Possible options: 0:Show,1:Hide.

  • includeInGlobal (bool): Include in dashboard. Default value true.

  • scanner (str): Plex TV Series, Plex Series Scanner

TheTVDB Show Options (com.plexapp.agents.thetvdb)

  • extras (bool): Find trailers and extras automatically (Plex Pass required). Default value true.

  • native_subs (bool): Include extras with subtitles in Library language. Default value false.

TheMovieDB Show Options (com.plexapp.agents.themoviedb)

  • collections (bool): Use collection info from The Movie Database. Default value false.

  • localart (bool): Prefer artwork based on library language. Default value true.

  • adult (bool): Include adult content. Default value false.

  • country (int): Country (used for release date and content rating). Default value 47 options 0:, 1:Argentina, 2:Australia, 3:Austria, 4:Belgium, 5:Belize, 6:Bolivia, 7:Brazil, 8:Canada, 9:Chile, 10:Colombia, 11:Costa Rica, 12:Czech Republic, 13:Denmark, 14:Dominican Republic, 15:Ecuador, 16:El Salvador, 17:France, 18:Germany, 19:Guatemala, 20:Honduras, 21:Hong Kong SAR, 22:Ireland, 23:Italy, 24:Jamaica, 25:Korea, 26:Liechtenstein, 27:Luxembourg, 28:Mexico, 29:Netherlands, 30:New Zealand, 31:Nicaragua, 32:Panama, 33:Paraguay, 34:Peru, 35:Portugal, 36:Peoples Republic of China, 37:Puerto Rico, 38:Russia, 39:Singapore, 40:South Africa, 41:Spain, 42:Sweden, 43:Switzerland, 44:Taiwan, 45:Trinidad, 46:United Kingdom, 47:United States, 48:Uruguay, 49:Venezuela.

Other Video Preferences

  • agent (str): com.plexapp.agents.none, com.plexapp.agents.imdb, com.plexapp.agents.themoviedb

  • enableBIFGeneration (bool): Enable video preview thumbnails. Default value true.

  • enableCinemaTrailers (bool): Enable Cinema Trailers. Default value true.

  • includeInGlobal (bool): Include in dashboard. Default value true.

  • scanner (str): Plex Movie Scanner, Plex Video Files Scanner

IMDB Other Video Options (com.plexapp.agents.imdb)

  • title (bool): Localized titles. Default value false.

  • extras (bool): Find trailers and extras automatically (Plex Pass required). Default value true.

  • only_trailers (bool): Skip extras which aren’t trailers. Default value false.

  • redband (bool): Use red band (restricted audiences) trailers when available. Default value false.

  • native_subs (bool): Include extras with subtitles in Library language. Default value false.

  • cast_list (int): Cast List Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database.

  • ratings (int): Ratings Source Default value 0 Possible options: 0:Rotten Tomatoes,1:IMDb,2:The Movie Database.

  • summary (int): Plot Summary Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database.

  • country (int): Country: Default value 46 Possible options: 0:Argentina, 1:Australia, 2:Austria, 3:Belgium, 4:Belize, 5:Bolivia, 6:Brazil, 7:Canada, 8:Chile, 9:Colombia, 10:Costa Rica, 11:Czech Republic, 12:Denmark, 13:Dominican Republic, 14:Ecuador, 15:El Salvador, 16:France, 17:Germany, 18:Guatemala, 19:Honduras, 20:Hong Kong SAR, 21:Ireland, 22:Italy, 23:Jamaica, 24:Korea, 25:Liechtenstein, 26:Luxembourg, 27:Mexico, 28:Netherlands, 29:New Zealand, 30:Nicaragua, 31:Panama, 32:Paraguay, 33:Peru, 34:Portugal, 35:Peoples Republic of China, 36:Puerto Rico, 37:Russia, 38:Singapore, 39:South Africa, 40:Spain, 41:Sweden, 42:Switzerland, 43:Taiwan, 44:Trinidad, 45:United Kingdom, 46:United States, 47:Uruguay, 48:Venezuela.

  • collections (bool): Use collection info from The Movie Database. Default value false.

  • localart (bool): Prefer artwork based on library language. Default value true.

  • adult (bool): Include adult content. Default value false.

  • usage (bool): Send anonymous usage data to Plex. Default value true.

TheMovieDB Other Video Options (com.plexapp.agents.themoviedb)

  • collections (bool): Use collection info from The Movie Database. Default value false.

  • localart (bool): Prefer artwork based on library language. Default value true.

  • adult (bool): Include adult content. Default value false.

  • country (int): Country (used for release date and content rating). Default value 47 Possible options 0:, 1:Argentina, 2:Australia, 3:Austria, 4:Belgium, 5:Belize, 6:Bolivia, 7:Brazil, 8:Canada, 9:Chile, 10:Colombia, 11:Costa Rica, 12:Czech Republic, 13:Denmark, 14:Dominican Republic, 15:Ecuador, 16:El Salvador, 17:France, 18:Germany, 19:Guatemala, 20:Honduras, 21:Hong Kong SAR, 22:Ireland, 23:Italy, 24:Jamaica, 25:Korea, 26:Liechtenstein, 27:Luxembourg, 28:Mexico, 29:Netherlands, 30:New Zealand, 31:Nicaragua, 32:Panama, 33:Paraguay, 34:Peru, 35:Portugal, 36:Peoples Republic of China, 37:Puerto Rico, 38:Russia, 39:Singapore, 40:South Africa, 41:Spain, 42:Sweden, 43:Switzerland, 44:Taiwan, 45:Trinidad, 46:United Kingdom, 47:United States, 48:Uruguay, 49:Venezuela.

history(maxresults=None, mindate=None)[source]

Get Play History for all library Sections for the owner. :param maxresults: Only return the specified number of results (optional). :type maxresults: int :param mindate: Min datetime to return results from. :type mindate: datetime

tags(tag)[source]

Returns a list of LibraryMediaTag objects for the specified tag.

Parameters:

tag (str) – Tag name (see TAGTYPES).

class plexapi.library.LibrarySection(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Base class for a single library section.

Variables:
  • agent (str) – The metadata agent used for the library section (com.plexapp.agents.imdb, etc).

  • allowSync (bool) – True if you allow syncing content from the library section.

  • art (str) – Background artwork used to respresent the library section.

  • composite (str) – Composite image used to represent the library section.

  • createdAt (datetime) – Datetime the library section was created.

  • filters (bool) – True if filters are available for the library section.

  • key (int) – Key (or ID) of this library section.

  • language (str) – Language represented in this section (en, xn, etc).

  • locations (List<str>) – List of folder paths added to the library section.

  • refreshing (bool) – True if this section is currently being refreshed.

  • scanner (str) – Internal scanner used to find media (Plex Movie Scanner, Plex Premium Music Scanner, etc.)

  • thumb (str) – Thumbnail image used to represent the library section.

  • title (str) – Name of the library section.

  • type (str) – Type of content section represents (movie, show, artist, photo).

  • updatedAt (datetime) – Datetime the library section was last updated.

  • uuid (str) – Unique id for the section (32258d7c-3e6c-4ac5-98ad-bad7a3b78c63)

property totalSize

Returns the total number of items in the library for the default library type.

property totalDuration

Returns the total duration (in milliseconds) of items in the library.

property totalStorage

Returns the total storage (in bytes) of items in the library.

totalViewSize(libtype=None, includeCollections=True)[source]

Returns the total number of items in the library for a specified libtype. The number of items for the default library type will be returned if no libtype is specified. (e.g. Specify libtype='episode' for the total number of episodes or libtype='albums' for the total number of albums.)

Parameters:
  • libtype (str, optional) – The type of items to return the total number for (movie, show, season, episode, artist, album, track, photoalbum). Default is the main library type.

  • includeCollections (bool, optional) – True or False to include collections in the total number. Default is True.

delete()[source]

Delete a library section.

reload()[source]

Reload the data for the library section.

edit(agent=None, **kwargs)[source]

Edit a library. See Library for example usage.

Parameters:
  • agent (str, optional) – The library agent.

  • kwargs (dict) – Dict of settings to edit.

addLocations(location)[source]

Add a location to a library.

Parameters:

location (str or list) – A single folder path, list of paths.

Example

LibrarySection.addLocations('/path/1')
LibrarySection.addLocations(['/path/1', 'path/2', '/path/3'])
removeLocations(location)[source]

Remove a location from a library.

Parameters:

location (str or list) – A single folder path, list of paths.

Example

LibrarySection.removeLocations('/path/1')
LibrarySection.removeLocations(['/path/1', 'path/2', '/path/3'])
get(title, **kwargs)[source]

Returns the media item with the specified title and kwargs.

Parameters:
  • title (str) – Title of the item to return.

  • kwargs (dict) – Additional search parameters. See search() for more info.

Raises:

NotFound – The title is not found in the library.

getGuid(guid)[source]

Returns the media item with the specified external Plex, IMDB, TMDB, or TVDB ID. Note: Only available for the Plex Movie and Plex TV Series agents.

Parameters:

guid (str) – The external guid of the item to return. Examples: Plex plex://show/5d9c086c46115600200aa2fe IMDB imdb://tt0944947, TMDB tmdb://1399, TVDB tvdb://121361.

Raises:

NotFound – The guid is not found in the library.

Example

result1 = library.getGuid('plex://show/5d9c086c46115600200aa2fe')
result2 = library.getGuid('imdb://tt0944947')
result3 = library.getGuid('tmdb://1399')
result4 = library.getGuid('tvdb://121361')

# Alternatively, create your own guid lookup dictionary for faster performance
guidLookup = {}
for item in library.all():
    guidLookup[item.guid] = item
    guidLookup.update({guid.id: item for guid in item.guids}}

result1 = guidLookup['plex://show/5d9c086c46115600200aa2fe']
result2 = guidLookup['imdb://tt0944947']
result3 = guidLookup['tmdb://1399']
result4 = guidLookup['tvdb://121361']
all(libtype=None, **kwargs)[source]

Returns a list of all items from this library section. See description of search() for details about filtering / sorting.

folders()[source]

Returns a list of available Folder for this library section.

managedHubs()[source]

Returns a list of available ManagedHub for this library section.

resetManagedHubs()[source]

Reset the managed hub customizations for this library section.

hubs()[source]

Returns a list of available Hub for this library section.

agents()[source]

Returns a list of available Agent for this library section.

settings()[source]

Returns a list of all library settings.

editAdvanced(**kwargs)[source]

Edit a library’s advanced settings.

defaultAdvanced()[source]

Edit all of library’s advanced settings to default.

lockAllField(field, libtype=None)[source]

Lock a field for all items in the library.

Parameters:
  • field (str) – The field to lock (e.g. thumb, rating, collection).

  • libtype (str, optional) – The library type to lock (movie, show, season, episode, artist, album, track, photoalbum, photo). Default is the main library type.

unlockAllField(field, libtype=None)[source]

Unlock a field for all items in the library.

Parameters:
  • field (str) – The field to unlock (e.g. thumb, rating, collection).

  • libtype (str, optional) – The library type to lock (movie, show, season, episode, artist, album, track, photoalbum, photo). Default is the main library type.

timeline()[source]

Returns a timeline query for this library section.

onDeck()[source]

Returns a list of media items on deck from this library section.

continueWatching()[source]

Return a list of media items in the library’s Continue Watching hub.

recentlyAdded(maxresults=50, libtype=None)[source]

Returns a list of media items recently added from this library section.

Parameters:
  • maxresults (int) – Max number of items to return (default 50).

  • libtype (str, optional) – The library type to filter (movie, show, season, episode, artist, album, track, photoalbum, photo). Default is the main library type.

analyze()[source]

Run an analysis on all of the items in this library section. See See analyze() for more details.

emptyTrash()[source]

If a section has items in the Trash, use this option to empty the Trash.

update(path=None)[source]

Scan this section for new media.

Parameters:

path (str, optional) – Full path to folder to scan.

cancelUpdate()[source]

Cancel update of this Library Section.

refresh()[source]

Forces a download of fresh media information from the internet. This can take a long time. Any locked fields are not modified.

deleteMediaPreviews()[source]

Delete the preview thumbnails for items in this library. This cannot be undone. Recreating media preview files can take hours or even days.

filterTypes()[source]

Returns a list of available FilteringType for this library section.

getFilterType(libtype=None)[source]

Returns a FilteringType for a specified libtype.

Parameters:

libtype (str, optional) – The library type to filter (movie, show, season, episode, artist, album, track, photoalbum, photo, collection).

Raises:

NotFound – Unknown libtype for this library.

fieldTypes()[source]

Returns a list of available FilteringFieldType for this library section.

getFieldType(fieldType)[source]

Returns a FilteringFieldType for a specified fieldType.

Parameters:

fieldType (str) – The data type for the field (tag, integer, string, boolean, date, subtitleLanguage, audioLanguage, resolution).

Raises:

NotFound – Unknown fieldType for this library.

listFilters(libtype=None)[source]

Returns a list of available FilteringFilter for a specified libtype. This is the list of options in the filter dropdown menu (screenshot).

Parameters:

libtype (str, optional) – The library type to filter (movie, show, season, episode, artist, album, track, photoalbum, photo, collection).

Example

availableFilters = [f.filter for f in library.listFilters()]
print("Available filter fields:", availableFilters)
listSorts(libtype=None)[source]

Returns a list of available FilteringSort for a specified libtype. This is the list of options in the sorting dropdown menu (screenshot).

Parameters:

libtype (str, optional) – The library type to filter (movie, show, season, episode, artist, album, track, photoalbum, photo, collection).

Example

availableSorts = [f.key for f in library.listSorts()]
print("Available sort fields:", availableSorts)
listFields(libtype=None)[source]

Returns a list of available FilteringFields for a specified libtype. This is the list of options in the custom filter dropdown menu (screenshot).

Parameters:

libtype (str, optional) – The library type to filter (movie, show, season, episode, artist, album, track, photoalbum, photo, collection).

Example

availableFields = [f.key.split('.')[-1] for f in library.listFields()]
print("Available fields:", availableFields)
listOperators(fieldType)[source]

Returns a list of available FilteringOperator for a specified fieldType. This is the list of options in the custom filter operator dropdown menu (screenshot).

Parameters:

fieldType (str) – The data type for the field (tag, integer, string, boolean, date, subtitleLanguage, audioLanguage, resolution).

Example

field = 'genre'  # Available filter field from listFields()
filterField = next(f for f in library.listFields() if f.key.endswith(field))
availableOperators = [o.key for o in library.listOperators(filterField.type)]
print(f"Available operators for {field}:", availableOperators)
listFilterChoices(field, libtype=None)[source]

Returns a list of available FilterChoice for a specified FilteringFilter or filter field. This is the list of available values for a custom filter (screenshot).

Parameters:
  • field (str) – FilteringFilter object, or the name of the field (genre, year, contentRating, etc.).

  • libtype (str, optional) – The library type to filter (movie, show, season, episode, artist, album, track, photoalbum, photo, collection).

Raises:

Example

field = 'genre'  # Available filter field from listFilters()
availableChoices = [f.title for f in library.listFilterChoices(field)]
print(f"Available choices for {field}:", availableChoices)
hubSearch(query, mediatype=None, limit=None)[source]

Returns the hub search results for this library. See plexapi.server.PlexServer.search() for details and parameters.

search(title=None, sort=None, maxresults=None, libtype=None, container_start=None, container_size=None, limit=None, filters=None, **kwargs)[source]

Search the library. The http requests will be batched in container_size. If you are only looking for the first <num> results, it would be wise to set the maxresults option to that amount so the search doesn’t iterate over all results on the server.

Parameters:
  • title (str, optional) – General string query to search for. Partial string matches are allowed.

  • sort (FilteringSort or str or list, optional) – A field to sort the results. See the details below for more info.

  • maxresults (int, optional) – Only return the specified number of results.

  • libtype (str, optional) – Return results of a specific type (movie, show, season, episode, artist, album, track, photoalbum, photo, collection) (e.g. libtype='episode' will only return Episode objects)

  • container_start (int, optional) – Default 0.

  • container_size (int, optional) – Default X_PLEX_CONTAINER_SIZE in your config file.

  • limit (int, optional) – Limit the number of results from the filter.

  • filters (dict, optional) – A dictionary of advanced filters. See the details below for more info.

  • **kwargs (dict) – Additional custom filters to apply to the search results. See the details below for more info.

Raises:
  • BadRequest – When the sort or filter is invalid.

  • NotFound – When applying an unknown sort or filter.

Sorting Results

The search results can be sorted by including the sort parameter.

  • See listSorts() to get a list of available sort fields.

The sort parameter can be a FilteringSort object or a sort string in the format field:dir. The sort direction dir can be asc, desc, or nullsLast. Omitting the sort direction or using a FilteringSort object will sort the results in the default direction of the field. Multi-sorting on multiple fields can be achieved by using a comma separated list of sort strings, or a list of FilteringSort object or strings.

Examples

library.search(sort="titleSort:desc")  # Sort title in descending order
library.search(sort="titleSort")  # Sort title in the default order
# Multi-sort by year in descending order, then by audience rating in descending order
library.search(sort="year:desc,audienceRating:desc")
library.search(sort=["year:desc", "audienceRating:desc"])

Using Plex Filters

Any of the available custom filters can be applied to the search results (screenshot).

The following filter fields are just some examples of the possible filters. The list is not exhaustive, and not all filters apply to all library types.

  • actor (MediaTag): Search for the name of an actor.

  • addedAt (datetime): Search for items added before or after a date. See operators below.

  • audioLanguage (str): Search for a specific audio language (3 character code, e.g. jpn).

  • collection (MediaTag): Search for the name of a collection.

  • contentRating (MediaTag): Search for a specific content rating.

  • country (MediaTag): Search for the name of a country.

  • decade (int): Search for a specific decade (e.g. 2000).

  • director (MediaTag): Search for the name of a director.

  • duplicate (bool) Search for duplicate items.

  • genre (MediaTag): Search for a specific genre.

  • hdr (bool): Search for HDR items.

  • inProgress (bool): Search for in progress items.

  • label (MediaTag): Search for a specific label.

  • lastViewedAt (datetime): Search for items watched before or after a date. See operators below.

  • mood (MediaTag): Search for a specific mood.

  • producer (MediaTag): Search for the name of a producer.

  • resolution (str): Search for a specific resolution (e.g. 1080).

  • studio (str): Search for the name of a studio.

  • style (MediaTag): Search for a specific style.

  • subtitleLanguage (str): Search for a specific subtitle language (3 character code, e.g. eng)

  • unmatched (bool): Search for unmatched items.

  • unwatched (bool): Search for unwatched items.

  • userRating (int): Search for items with a specific user rating.

  • writer (MediaTag): Search for the name of a writer.

  • year (int): Search for a specific year.

Tag type filter values can be a FilterChoice object, MediaTag object, the exact name MediaTag.tag (str), or the exact id MediaTag.id (int).

Date type filter values can be a datetime object, a relative date using a one of the available date suffixes (e.g. 30d) (str), or a date in YYYY-MM-DD (str) format.

Relative date suffixes:

  • s: seconds

  • m: minutes

  • h: hours

  • d: days

  • w: weeks

  • mon: months

  • y: years

Multiple values can be OR together by providing a list of values.

Examples

library.search(unwatched=True, year=2020, resolution="4k")
library.search(actor="Arnold Schwarzenegger", decade=1990)
library.search(contentRating="TV-G", genre="animation")
library.search(genre=["animation", "comedy"])  # Genre is animation OR comedy
library.search(studio=["Disney", "Pixar"])  # Studio contains Disney OR Pixar

Using a libtype Prefix

Some filters may be prefixed by the libtype separated by a . (e.g. show.collection, episode.title, artist.style, album.genre, track.userRating, etc.). This should not be confused with the libtype parameter. If no libtype prefix is provided, then the default library type is assumed. For example, in a TV show library viewCount is assumed to be show.viewCount. If you want to filter using episode view count then you must specify episode.viewCount explicitly. In addition, if the filter does not exist for the default library type it will fallback to the most specific libtype available. For example, show.unwatched does not exists so it will fallback to episode.unwatched. The libtype prefix cannot be included directly in the function parameters so the filters must be provided as a filters dictionary.

Examples

library.search(filters={"show.collection": "Documentary", "episode.inProgress": True})
library.search(filters={"artist.genre": "pop", "album.decade": 2000})

# The following three options are identical and will return Episode objects
showLibrary.search(title="Winter is Coming", libtype='episode')
showLibrary.search(libtype='episode', filters={"episode.title": "Winter is Coming"})
showLibrary.searchEpisodes(title="Winter is Coming")

# The following will search for the episode title but return Show objects
showLibrary.search(filters={"episode.title": "Winter is Coming"})

# The following will fallback to episode.unwatched
showLibrary.search(unwatched=True)

Using Plex Operators

Operators can be appended to the filter field to narrow down results with more granularity. The following is a list of possible operators depending on the data type of the filter being applied. A special & operator can also be used to AND together a list of values.

Type: MediaTag or subtitleLanguage or audioLanguage

  • no operator: is

  • !: is not

Type: int

  • no operator: is

  • !: is not

  • >>: is greater than

  • <<: is less than

Type: str

  • no operator: contains

  • !: does not contain

  • =: is

  • !=: is not

  • <: begins with

  • >: ends with

Type: bool

  • no operator: is true

  • !: is false

Type: datetime

  • <<: is before

  • >>: is after

Type: resolution or guid

  • no operator: is

Operators cannot be included directly in the function parameters so the filters must be provided as a filters dictionary.

Examples

# Genre is horror AND thriller
library.search(filters={"genre&": ["horror", "thriller"]})

# Director is not Steven Spielberg
library.search(filters={"director!": "Steven Spielberg"})

# Title starts with Marvel and added before 2021-01-01
library.search(filters={"title<": "Marvel", "addedAt<<": "2021-01-01"})

# Added in the last 30 days using relative dates
library.search(filters={"addedAt>>": "30d"})

# Collection is James Bond and user rating is greater than 8
library.search(filters={"collection": "James Bond", "userRating>>": 8})

Using Advanced Filters

Any of the Plex filters described above can be combined into a single filters dictionary that mimics the advanced filters used in Plex Web with a tree of and/or branches. Each level of the tree must start with and (Match all of the following) or or (Match any of the following) as the dictionary key, and a list of dictionaries with the desired filters as the dictionary value.

The following example matches this advanced filter in Plex Web.

Examples

advancedFilters = {
    'and': [                            # Match all of the following in this list
        {
            'or': [                     # Match any of the following in this list
                {'title': 'elephant'},
                {'title': 'bunny'}
            ]
        },
        {'year>>': 1990},
        {'unwatched': True}
    ]
}
library.search(filters=advancedFilters)

Using PlexAPI Operators

For even more advanced filtering which cannot be achieved in Plex, the PlexAPI operators can be applied to any XML attribute. See plexapi.base.PlexObject.fetchItems() for a list of operators and how they are used. Note that using the Plex filters above will be faster since the filters are applied by the Plex server before the results are returned to PlexAPI. Using the PlexAPI operators requires the Plex server to return all results to allow PlexAPI to do the filtering. The Plex filters and the PlexAPI operators can be used in conjunction with each other.

Examples

library.search(summary__icontains="Christmas")
library.search(duration__gt=7200000)
library.search(audienceRating__lte=6.0, audienceRatingImage__startswith="rottentomatoes://")
library.search(media__videoCodec__exact="h265")
library.search(genre="holiday", viewCount__gte=3)
sync(policy, mediaSettings, client=None, clientId=None, title=None, sort=None, libtype=None, **kwargs)[source]

Add current library section as sync item for specified device. See description of search() for details about filtering / sorting and sync() for possible exceptions.

Parameters:
  • policy (Policy) – policy of syncing the media (how many items to sync and process watched media or not), generated automatically when method called on specific LibrarySection object.

  • mediaSettings (MediaSettings) – Transcoding settings used for the media, generated automatically when method called on specific LibrarySection object.

  • client (MyPlexDevice) – sync destination, see sync().

  • clientId (str) – sync destination, see sync().

  • title (str) – descriptive title for the new SyncItem, if empty the value would be generated from metadata of current media.

  • sort (str) – formatted as column:dir; column can be any of {addedAt, originallyAvailableAt, lastViewedAt, titleSort, rating, mediaHeight, duration}. dir can be asc or desc.

  • libtype (str) – Filter results to a specific libtype (movie, show, episode, artist, album, track).

Returns:

an instance of created syncItem.

Return type:

SyncItem

Raises:
  • BadRequest – When the library is not allowed to sync.

  • BadRequest – When the sort or filter is invalid.

  • NotFound – When applying an unknown sort or filter.

Example

from plexapi import myplex
from plexapi.sync import Policy, MediaSettings, VIDEO_QUALITY_3_MBPS_720p

c = myplex.MyPlexAccount()
target = c.device('Plex Client')
sync_items_wd = c.syncItems(target.clientIdentifier)
srv = c.resource('Server Name').connect()
section = srv.library.section('Movies')
policy = Policy('count', unwatched=True, value=1)
media_settings = MediaSettings.create(VIDEO_QUALITY_3_MBPS_720p)
section.sync(target, policy, media_settings, title='Next best movie', sort='rating:desc')
history(maxresults=None, mindate=None)[source]

Get Play History for this library Section for the owner. :param maxresults: Only return the specified number of results (optional). :type maxresults: int :param mindate: Min datetime to return results from. :type mindate: datetime

createCollection(title, items=None, smart=False, limit=None, libtype=None, sort=None, filters=None, **kwargs)[source]

Alias for createCollection() using this LibrarySection.

collection(title)[source]

Returns the collection with the specified title.

Parameters:

title (str) – Title of the item to return.

Raises:

NotFound – Unable to find collection.

collections(**kwargs)[source]

Returns a list of collections from this library section. See description of search() for details about filtering / sorting.

createPlaylist(title, items=None, smart=False, limit=None, sort=None, filters=None, m3ufilepath=None, **kwargs)[source]

Alias for createPlaylist() using this LibrarySection.

playlist(title)[source]

Returns the playlist with the specified title.

Parameters:

title (str) – Title of the item to return.

Raises:

NotFound – Unable to find playlist.

playlists(sort=None, **kwargs)[source]

Returns a list of playlists from this library section.

getWebURL(base=None, tab=None, key=None)[source]

Returns the Plex Web URL for the library.

Parameters:
  • base (str) – The base URL before the fragment (#!). Default is https://app.plex.tv/desktop.

  • tab (str) – The library tab (recommended, library, collections, playlists, timeline).

  • key (str) – A hub key.

common(items)[source]

Returns a Common object for the specified items.

multiEdit(items, **kwargs)[source]

Edit multiple objects at once. Note: This is a low level method and you need to know all the field/tag keys. See batchMultiEdits instead.

Parameters:
  • items (List) – List of Audio, Video, Photo, or Collection objects to be edited.

  • kwargs (dict) – Dict of settings to edit.

batchMultiEdits(items)[source]

Enable batch multi-editing mode to save API calls. Must call saveMultiEdits() at the end to save all the edits. See EditFieldMixin and EditTagsMixin for individual field and tag editing methods.

Parameters:

items (List) – List of Audio, Video, Photo, or Collection objects to be edited.

Example

movies = MovieSection.all()
items = [movies[0], movies[3], movies[5]]

# Batch multi-editing multiple fields and tags in a single API call
MovieSection.batchMultiEdits(items)
MovieSection.editTitle('A New Title').editSummary('A new summary').editTagline('A new tagline') \
    .addCollection('New Collection').removeGenre('Action').addLabel('Favorite')
MovieSection.saveMultiEdits()
saveMultiEdits()[source]

Save all the batch multi-edits. See batchMultiEdits() for details.

class plexapi.library.MovieSection(server, data, initpath=None, parent=None)[source]

Bases: LibrarySection, MovieEditMixins

Represents a LibrarySection section containing movies.

Variables:
  • TAG (str) – ‘Directory’

  • TYPE (str) – ‘movie’

searchMovies(**kwargs)[source]

Search for a movie. See search() for usage.

recentlyAddedMovies(maxresults=50)[source]

Returns a list of recently added movies from this library section.

Parameters:

maxresults (int) – Max number of items to return (default 50).

sync(videoQuality, limit=None, unwatched=False, **kwargs)[source]

Add current Movie library section as sync item for specified device. See description of search() for details about filtering / sorting and sync() for details on syncing libraries and possible exceptions.

Parameters:
  • videoQuality (int) – idx of quality of the video, one of VIDEO_QUALITY_* values defined in sync module.

  • limit (int) – maximum count of movies to sync, unlimited if None.

  • unwatched (bool) – if True watched videos wouldn’t be synced.

Returns:

an instance of created syncItem.

Return type:

SyncItem

Example

from plexapi import myplex
from plexapi.sync import VIDEO_QUALITY_3_MBPS_720p

c = myplex.MyPlexAccount()
target = c.device('Plex Client')
sync_items_wd = c.syncItems(target.clientIdentifier)
srv = c.resource('Server Name').connect()
section = srv.library.section('Movies')
section.sync(VIDEO_QUALITY_3_MBPS_720p, client=target, limit=1, unwatched=True,
             title='Next best movie', sort='rating:desc')
class plexapi.library.ShowSection(server, data, initpath=None, parent=None)[source]

Bases: LibrarySection, ShowEditMixins, SeasonEditMixins, EpisodeEditMixins

Represents a LibrarySection section containing tv shows.

Variables:
  • TAG (str) – ‘Directory’

  • TYPE (str) – ‘show’

searchShows(**kwargs)[source]

Search for a show. See search() for usage.

searchSeasons(**kwargs)[source]

Search for a season. See search() for usage.

searchEpisodes(**kwargs)[source]

Search for an episode. See search() for usage.

recentlyAddedShows(maxresults=50)[source]

Returns a list of recently added shows from this library section.

Parameters:

maxresults (int) – Max number of items to return (default 50).

recentlyAddedSeasons(maxresults=50)[source]

Returns a list of recently added seasons from this library section.

Parameters:

maxresults (int) – Max number of items to return (default 50).

recentlyAddedEpisodes(maxresults=50)[source]

Returns a list of recently added episodes from this library section.

Parameters:

maxresults (int) – Max number of items to return (default 50).

sync(videoQuality, limit=None, unwatched=False, **kwargs)[source]

Add current Show library section as sync item for specified device. See description of search() for details about filtering / sorting and sync() for details on syncing libraries and possible exceptions.

Parameters:
  • videoQuality (int) – idx of quality of the video, one of VIDEO_QUALITY_* values defined in sync module.

  • limit (int) – maximum count of episodes to sync, unlimited if None.

  • unwatched (bool) – if True watched videos wouldn’t be synced.

Returns:

an instance of created syncItem.

Return type:

SyncItem

Example

from plexapi import myplex
from plexapi.sync import VIDEO_QUALITY_3_MBPS_720p

c = myplex.MyPlexAccount()
target = c.device('Plex Client')
sync_items_wd = c.syncItems(target.clientIdentifier)
srv = c.resource('Server Name').connect()
section = srv.library.section('TV-Shows')
section.sync(VIDEO_QUALITY_3_MBPS_720p, client=target, limit=1, unwatched=True,
             title='Next unwatched episode')
class plexapi.library.MusicSection(server, data, initpath=None, parent=None)[source]

Bases: LibrarySection, ArtistEditMixins, AlbumEditMixins, TrackEditMixins

Represents a LibrarySection section containing music artists.

Variables:
  • TAG (str) – ‘Directory’

  • TYPE (str) – ‘artist’

albums()[source]

Returns a list of Album objects in this section.

stations()[source]

Returns a list of Playlist stations in this section.

searchArtists(**kwargs)[source]

Search for an artist. See search() for usage.

searchAlbums(**kwargs)[source]

Search for an album. See search() for usage.

searchTracks(**kwargs)[source]

Search for a track. See search() for usage.

recentlyAddedArtists(maxresults=50)[source]

Returns a list of recently added artists from this library section.

Parameters:

maxresults (int) – Max number of items to return (default 50).

recentlyAddedAlbums(maxresults=50)[source]

Returns a list of recently added albums from this library section.

Parameters:

maxresults (int) – Max number of items to return (default 50).

recentlyAddedTracks(maxresults=50)[source]

Returns a list of recently added tracks from this library section.

Parameters:

maxresults (int) – Max number of items to return (default 50).

sync(bitrate, limit=None, **kwargs)[source]

Add current Music library section as sync item for specified device. See description of search() for details about filtering / sorting and sync() for details on syncing libraries and possible exceptions.

Parameters:
  • bitrate (int) – maximum bitrate for synchronized music, better use one of MUSIC_BITRATE_* values from the module sync.

  • limit (int) – maximum count of tracks to sync, unlimited if None.

Returns:

an instance of created syncItem.

Return type:

SyncItem

Example

from plexapi import myplex
from plexapi.sync import AUDIO_BITRATE_320_KBPS

c = myplex.MyPlexAccount()
target = c.device('Plex Client')
sync_items_wd = c.syncItems(target.clientIdentifier)
srv = c.resource('Server Name').connect()
section = srv.library.section('Music')
section.sync(AUDIO_BITRATE_320_KBPS, client=target, limit=100, sort='addedAt:desc',
             title='New music')
class plexapi.library.PhotoSection(server, data, initpath=None, parent=None)[source]

Bases: LibrarySection, PhotoalbumEditMixins, PhotoEditMixins

Represents a LibrarySection section containing photos.

Variables:
  • TAG (str) – ‘Directory’

  • TYPE (str) – ‘photo’

all(libtype=None, **kwargs)[source]

Returns a list of all items from this library section. See description of plexapi.library.LibrarySection.search() for details about filtering / sorting.

collections(**kwargs)[source]

Returns a list of collections from this library section. See description of search() for details about filtering / sorting.

searchAlbums(**kwargs)[source]

Search for a photo album. See search() for usage.

searchPhotos(**kwargs)[source]

Search for a photo. See search() for usage.

recentlyAddedAlbums(maxresults=50)[source]

Returns a list of recently added photo albums from this library section.

Parameters:

maxresults (int) – Max number of items to return (default 50).

sync(resolution, limit=None, **kwargs)[source]

Add current Music library section as sync item for specified device. See description of search() for details about filtering / sorting and sync() for details on syncing libraries and possible exceptions.

Parameters:
  • resolution (str) – maximum allowed resolution for synchronized photos, see PHOTO_QUALITY_* values in the module sync.

  • limit (int) – maximum count of tracks to sync, unlimited if None.

Returns:

an instance of created syncItem.

Return type:

SyncItem

Example

from plexapi import myplex
from plexapi.sync import PHOTO_QUALITY_HIGH

c = myplex.MyPlexAccount()
target = c.device('Plex Client')
sync_items_wd = c.syncItems(target.clientIdentifier)
srv = c.resource('Server Name').connect()
section = srv.library.section('Photos')
section.sync(PHOTO_QUALITY_HIGH, client=target, limit=100, sort='addedAt:desc',
             title='Fresh photos')
class plexapi.library.LibraryTimeline(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a LibrarySection timeline.

Variables:
  • TAG (str) – ‘LibraryTimeline’

  • size (int) – Unknown

  • allowSync (bool) – Unknown

  • art (str) – Relative path to art image.

  • content (str) – “secondary”

  • identifier (str) – “com.plexapp.plugins.library”

  • latestEntryTime (int) – Epoch timestamp

  • mediaTagPrefix (str) – “/system/bundle/media/flags/”

  • mediaTagVersion (int) – Unknown

  • thumb (str) – Relative path to library thumb image.

  • title1 (str) – Name of library section.

  • updateQueueSize (int) – Number of items queued to update.

  • viewGroup (str) – “secondary”

  • viewMode (int) – Unknown

class plexapi.library.Location(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single library Location.

Variables:
  • TAG (str) – ‘Location’

  • id (int) – Location path ID.

  • path (str) – Path used for library..

class plexapi.library.Hub(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single Hub (or category) in the PlexServer search.

Variables:
  • TAG (str) – ‘Hub’

  • context (str) – The context of the hub.

  • hubKey (str) – API URL for these specific hub items.

  • hubIdentifier (str) – The identifier of the hub.

  • items (list) – List of items in the hub.

  • key (str) – API URL for the hub.

  • more (bool) – True if there are more items to load (call reload() to fetch all items).

  • size (int) – The number of items in the hub.

  • style (str) – The style of the hub.

  • title (str) – The title of the hub.

  • type (str) – The type of items in the hub.

reload()[source]

Reloads the hub to fetch all items in the hub.

section()[source]

Returns the LibrarySection this hub belongs to.

class plexapi.library.LibraryMediaTag(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Base class of library media tags.

Variables:
  • TAG (str) – ‘Directory’

  • count (int) – The number of items where this tag is found.

  • filter (str) – The URL filter for the tag.

  • id (int) – The id of the tag.

  • key (str) – API URL (/library/section/<librarySectionID>/all?<filter>).

  • librarySectionID (int) – The library section ID where the tag is found.

  • librarySectionKey (str) – API URL for the library section (/library/section/<librarySectionID>)

  • librarySectionTitle (str) – The library title where the tag is found.

  • librarySectionType (int) – The library type where the tag is found.

  • reason (str) – The reason for the search result.

  • reasonID (int) – The reason ID for the search result.

  • reasonTitle (str) – The reason title for the search result.

  • score (float) – The score for the search result.

  • type (str) – The type of search result (tag).

  • tag (str) – The title of the tag.

  • tagKey (str) – The Plex Discover ratingKey (guid) for people.

  • tagType (int) – The type ID of the tag.

  • tagValue (int) – The value of the tag.

  • thumb (str) – The URL for the thumbnail of the tag (if available).

items(*args, **kwargs)[source]

Return the list of items within this tag.

class plexapi.library.Aperture(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Aperture library media tag.

Variables:

TAGTYPE (int) – 202

class plexapi.library.Art(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Art library media tag.

Variables:

TAGTYPE (int) – 313

class plexapi.library.Autotag(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Autotag library media tag.

Variables:

TAGTYPE (int) – 207

class plexapi.library.Chapter(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Chapter library media tag.

Variables:

TAGTYPE (int) – 9

class plexapi.library.Collection(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Collection library media tag.

Variables:

TAGTYPE (int) – 2

class plexapi.library.Concert(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Concert library media tag.

Variables:

TAGTYPE (int) – 306

class plexapi.library.Country(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Country library media tag.

Variables:

TAGTYPE (int) – 8

class plexapi.library.Device(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Device library media tag.

Variables:

TAGTYPE (int) – 206

class plexapi.library.Director(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Director library media tag.

Variables:

TAGTYPE (int) – 4

class plexapi.library.Exposure(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Exposure library media tag.

Variables:

TAGTYPE (int) – 203

class plexapi.library.Format(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Format library media tag.

Variables:

TAGTYPE (int) – 302

class plexapi.library.Genre(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Genre library media tag.

Variables:

TAGTYPE (int) – 1

class plexapi.library.Guid(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Guid library media tag.

Variables:

TAGTYPE (int) – 314

class plexapi.library.ISO(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single ISO library media tag.

Variables:

TAGTYPE (int) – 204

class plexapi.library.Label(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Label library media tag.

Variables:

TAGTYPE (int) – 11

class plexapi.library.Lens(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Lens library media tag.

Variables:

TAGTYPE (int) – 205

class plexapi.library.Make(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Make library media tag.

Variables:

TAGTYPE (int) – 200

class plexapi.library.Marker(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Marker library media tag.

Variables:

TAGTYPE (int) – 12

class plexapi.library.MediaProcessingTarget(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single MediaProcessingTarget library media tag.

Variables:
  • TAG (str) – ‘Tag’

  • TAGTYPE (int) – 42

class plexapi.library.Model(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Model library media tag.

Variables:

TAGTYPE (int) – 201

class plexapi.library.Mood(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Mood library media tag.

Variables:

TAGTYPE (int) – 300

class plexapi.library.Network(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Network library media tag.

Variables:

TAGTYPE (int) – 319

class plexapi.library.Place(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Place library media tag.

Variables:

TAGTYPE (int) – 400

class plexapi.library.Poster(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Poster library media tag.

Variables:

TAGTYPE (int) – 312

class plexapi.library.Producer(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Producer library media tag.

Variables:

TAGTYPE (int) – 7

class plexapi.library.RatingImage(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single RatingImage library media tag.

Variables:

TAGTYPE (int) – 316

class plexapi.library.Review(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Review library media tag.

Variables:

TAGTYPE (int) – 10

class plexapi.library.Role(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Role library media tag.

Variables:

TAGTYPE (int) – 6

class plexapi.library.Similar(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Similar library media tag.

Variables:

TAGTYPE (int) – 305

class plexapi.library.Studio(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Studio library media tag.

Variables:

TAGTYPE (int) – 318

class plexapi.library.Style(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Style library media tag.

Variables:

TAGTYPE (int) – 301

class plexapi.library.Tag(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Tag library media tag.

Variables:

TAGTYPE (int) – 0

class plexapi.library.Theme(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Theme library media tag.

Variables:

TAGTYPE (int) – 317

class plexapi.library.Writer(server, data, initpath=None, parent=None)[source]

Bases: LibraryMediaTag

Represents a single Writer library media tag.

Variables:

TAGTYPE (int) – 5

class plexapi.library.FilteringType(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single filtering Type object for a library.

Variables:
  • TAG (str) – ‘Type’

  • active (bool) – True if this filter type is currently active.

  • fields (List<FilteringField>) – List of field objects.

  • filters (List<FilteringFilter>) – List of filter objects.

  • key (str) – The API URL path for the libtype filter.

  • sorts (List<FilteringSort>) – List of sort objects.

  • title (str) – The title for the libtype filter.

  • type (str) – The libtype for the filter.

class plexapi.library.FilteringFilter(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single Filter object for a FilteringType.

Variables:
  • TAG (str) – ‘Filter’

  • filter (str) – The key for the filter.

  • filterType (str) – The FilteringFieldType type (string, boolean, integer, date, etc).

  • key (str) – The API URL path for the filter.

  • title (str) – The title of the filter.

  • type (str) – ‘filter’

class plexapi.library.FilteringSort(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single Sort object for a FilteringType.

Variables:
  • TAG (str) – ‘Sort’

  • active (bool) – True if the sort is currently active.

  • activeDirection (str) – The currently active sorting direction.

  • default (str) – The currently active default sorting direction.

  • defaultDirection (str) – The default sorting direction.

  • descKey (str) – The URL key for sorting with desc.

  • firstCharacterKey (str) – API URL path for first character endpoint.

  • key (str) – The URL key for the sorting.

  • title (str) – The title of the sorting.

class plexapi.library.FilteringField(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single Field object for a FilteringType.

Variables:
  • TAG (str) – ‘Field’

  • key (str) – The URL key for the filter field.

  • title (str) – The title of the filter field.

  • type (str) – The FilteringFieldType type (string, boolean, integer, date, etc).

  • subType (str) – The subtype of the filter (decade, rating, etc).

class plexapi.library.FilteringFieldType(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single FieldType for library filtering.

Variables:
  • TAG (str) – ‘FieldType’

  • type (str) – The filtering data type (string, boolean, integer, date, etc).

  • operators (List<FilteringOperator>) – List of operator objects.

class plexapi.library.FilteringOperator(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents an single Operator for a FilteringFieldType.

Variables:
  • TAG (str) – ‘Operator’

  • key (str) – The URL key for the operator.

  • title (str) – The title of the operator.

class plexapi.library.FilterChoice(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single FilterChoice object. These objects are gathered when using filters while searching for library items and is the object returned in the result set of listFilterChoices().

Variables:
  • TAG (str) – ‘Directory’

  • fastKey (str) – API URL path to quickly list all items with this filter choice. (/library/sections/<section>/all?genre=<key>)

  • key (str) – The id value of this filter choice.

  • thumb (str) – Thumbnail URL for the filter choice.

  • title (str) – The title of the filter choice.

  • type (str) – The filter type (genre, contentRating, etc).

class plexapi.library.ManagedHub(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a Managed Hub (recommendation) inside a library.

Variables:
  • TAG (str) – ‘Hub’

  • deletable (bool) – True if the Hub can be deleted (promoted collection).

  • homeVisibility (str) – Promoted home visibility (none, all, admin, or shared).

  • identifier (str) – Hub identifier for the managed hub.

  • promotedToOwnHome (bool) – Promoted to own home.

  • promotedToRecommended (bool) – Promoted to recommended.

  • promotedToSharedHome (bool) – Promoted to shared home.

  • recommendationsVisibility (str) – Promoted recommendation visibility (none or all).

  • title (str) – Title of managed hub.

reload()[source]

Reload the data for this managed hub.

move(after=None)[source]

Move a managed hub to a new position in the library’s Managed Recommendations.

Parameters:

after (obj) – ManagedHub object to move the item after in the collection.

Raises:

plexapi.exceptions.BadRequest – When trying to move a Hub that is not a Managed Recommendation.

remove()[source]

Removes a managed hub from the library’s Managed Recommendations.

Raises:

plexapi.exceptions.BadRequest – When trying to remove a Hub that is not a Managed Recommendation or when the Hub cannot be removed.

updateVisibility(recommended=None, home=None, shared=None)[source]

Update the managed hub’s visibility settings.

Parameters:
  • recommended (bool) – True to make visible on your Library Recommended page. False to hide. Default None.

  • home (bool) – True to make visible on your Home page. False to hide. Default None.

  • shared (bool) – True to make visible on your Friends’ Home page. False to hide. Default None.

Example

managedHub.updateVisibility(recommended=True, home=True, shared=False).reload()
# or using chained methods
managedHub.promoteRecommended().promoteHome().demoteShared().reload()
promoteRecommended()[source]

Show the managed hub on your Library Recommended Page.

demoteRecommended()[source]

Hide the managed hub on your Library Recommended Page.

promoteHome()[source]

Show the managed hub on your Home Page.

demoteHome()[source]

Hide the manged hub on your Home Page.

promoteShared()[source]

Show the managed hub on your Friends’ Home Page.

demoteShared()[source]

Hide the managed hub on your Friends’ Home Page.

class plexapi.library.Folder(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a Folder inside a library.

Variables:
  • key (str) – Url key for folder.

  • title (str) – Title of folder.

subfolders()[source]

Returns a list of available Folder for this folder. Continue down subfolders until a mediaType is found.

allSubfolders()[source]

Returns a list of all available Folder for this folder. Only returns Folder.

class plexapi.library.FirstCharacter(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a First Character element from a library.

Variables:
  • key (str) – Url key for character.

  • size (str) – Total amount of library items starting with this character.

  • title (str) – Character (#, !, A, B, C, …).

class plexapi.library.Path(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single directory Path.

Variables:
  • TAG (str) – ‘Path’

  • home (bool) – True if the path is the home directory

  • key (str) – API URL (/services/browse/<base64path>)

  • network (bool) – True if path is a network location

  • path (str) – Full path to folder

  • title (str) – Folder name

browse(includeFiles=True)[source]

Alias for browse().

walk()[source]

Alias for walk().

class plexapi.library.File(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a single File.

Variables:
  • TAG (str) – ‘File’

  • key (str) – API URL (/services/browse/<base64path>)

  • path (str) – Full path to file

  • title (str) – File name

class plexapi.library.Common(server, data, initpath=None, parent=None)[source]

Bases: PlexObject

Represents a Common element from a library. This object lists common fields between multiple objects.

Variables:
  • TAG (str) – ‘Common’

  • collections (List<Collection>) – List of collection objects.

  • contentRating (str) – Content rating of the items.

  • countries (List<Country>) – List of countries objects.

  • directors (List<Director>) – List of director objects.

  • editionTitle (str) – Edition title of the items.

  • fields (List<Field>) – List of field objects.

  • genres (List<Genre>) – List of genre objects.

  • grandparentRatingKey (int) – Grandparent rating key of the items.

  • grandparentTitle (str) – Grandparent title of the items.

  • guid (str) – Plex GUID of the items.

  • guids (List<Guid>) – List of guid objects.

  • index (int) – Index of the items.

  • key (str) – API URL (/library/metadata/<ratingkey>).

  • labels (List<Label>) – List of label objects.

  • mixedFields (List<str>) – List of mixed fields.

  • moods (List<Mood>) – List of mood objects.

  • originallyAvailableAt (datetime) – Datetime of the release date of the items.

  • parentRatingKey (int) – Parent rating key of the items.

  • parentTitle (str) – Parent title of the items.

  • producers (List<Producer>) – List of producer objects.

  • ratingKey (int) – Rating key of the items.

  • ratings (List<Rating>) – List of rating objects.

  • roles (List<Role>) – List of role objects.

  • studio (str) – Studio name of the items.

  • styles (List<Style>) – List of style objects.

  • summary (str) – Summary of the items.

  • tagline (str) – Tagline of the items.

  • tags (List<Tag>) – List of tag objects.

  • title (str) – Title of the items.

  • titleSort (str) – Title to use when sorting of the items.

  • type (str) – Type of the media (common).

  • writers (List<Writer>) – List of writer objects.

  • year (int) – Year of the items.

property commonType

Returns the media type of the common items.

property ratingKeys

Returns a list of rating keys for the common items.

items()[source]

Returns a list of the common items.