Library#

class beets.library.Library(path='library.blb', directory: str | None = None, path_formats=(('default', '$artist/$album/$track $title'),), replacements=None)[source]#

Bases: Database

A database of music containing songs and albums.

__init__(path='library.blb', directory: str | None = None, path_formats=(('default', '$artist/$album/$track $title'),), replacements=None)[source]#

Public methods summary

add(obj)

Add the Item or Album object to the library database.

add_album(items)

Create a new album consisting of a list of items.

add_functions(conn)

albums([query, sort])

Get Album objects matching the query.

get_album(item_or_id)

Given an album ID or an item associated with an album, return a Album object for the album.

get_default_album_sort()

Get a Sort object for albums from the config option.

get_default_item_sort()

Get a Sort object for items from the config option.

get_item(id)

Fetch a Item by its ID.

items([query, sort])

Get Item objects matching the query.

load_extension(path)

Load an SQLite extension into all open connections.

transaction()

Get a Transaction object for interacting directly with the underlying SQLite database.

Methods definition

add(obj)[source]#

Add the Item or Album object to the library database.

Return the object's new id.

add_album(items)[source]#

Create a new album consisting of a list of items.

The items are added to the database if they don't yet have an ID. Return a new Album object. The list items must not be empty.

albums(query=None, sort=None) Results[Album][source]#

Get Album objects matching the query.

get_album(item_or_id)[source]#

Given an album ID or an item associated with an album, return a Album object for the album.

If no such album exists, return None.

static get_default_album_sort()[source]#

Get a Sort object for albums from the config option.

static get_default_item_sort()[source]#

Get a Sort object for items from the config option.

get_item(id)[source]#

Fetch a Item by its ID.

Return None if no match is found.

items(query=None, sort=None) Results[Item][source]#

Get Item objects matching the query.

load_extension(path: str)#

Load an SQLite extension into all open connections.

revision = 0#

The current revision of the database. To be increased whenever data is written in a transaction.

supports_extensions = True#

Whether or not the current version of SQLite supports extensions

transaction() Transaction#

Get a Transaction object for interacting directly with the underlying SQLite database.