Skip to main content
`Ctrl`+`K`

# LibModel

class beets.library.LibModel(db: D | None = None, fixed_values: dict[str, Any] | None = None, flex_values: dict[str, Any] | None = None, **kwargs: Any)

  Bases: `Model`[`Library`]

  Shared concrete functionality for Items and Albums.

  __init__(db: D | None = None, fixed_values: dict[str, Any] | None = None, flex_values: dict[str, Any] | None = None, **kwargs: Any) → None

    Create a new model instance.

    fixed_values/flex_values are raw values loaded from the database and converted lazily on access. kwargs are normal initial field values.

  Public methods summary

  `add`([lib]) | Add the object to the library database.
  `all_keys`() | Get a list of available keys for objects of this type.
  `any_field_query`(pattern, query_cls) |
  `any_writable_media_field_query`(pattern, ...) |
  `clear_dirty`() | Mark all fields as clean (i.e., not needing to be stored to the database).
  `copy`() | Create a copy of the model object.
  `duplicates_query`(fields) | Return a query for entities with same values in the given fields.
  `evaluate_template`(template[, for_path]) | Evaluate a template (a string or a Template object) using the object's fields.
  `field_query`(field, pattern, query_cls) | Get a FieldQuery for the given field on this model.
  `formatted`([included_keys, for_path]) | Get a mapping containing all values on this object formatted as human-readable unicode strings.
  `get`(key[, default, raise_]) | Get the value for a field, or default.
  `get_fresh_from_db`() | Load this object from the database.
  `items`() | Iterate over (key, value) pairs that this object contains.
  `keys`([computed]) | Get a list of available field names for this object.
  `load`() | Refresh the object's metadata from the library database.
  `remove`() | Remove the object's associated rows from the database.
  `set_parse`(key, string) | Set the object's key to a value represented by a string.
  `store`([fields]) | Save the object's metadata into the library database.
  `update`(values) | Assign all values in the given dict.

  Methods definition

  property filepath: Path

    The path to the entity as pathlib.Path.

  store(fields: Iterable[str] | None = None) → None

    Save the object’s metadata into the library database. :param fields: the fields to be stored. If not specified, all fields will be.

  remove() → None

    Remove the object’s associated rows from the database.

  add(lib: Library | None = None) → None

    Add the object to the library database. This object must be associated with a database; you can provide one via the db parameter or use the currently associated database.

    The object’s id and added fields are set along with any current field values.

  classmethod field_query(field: str, pattern: str, query_cls: FieldQueryType) → FieldQuery

    Get a FieldQuery for the given field on this model.

  duplicates_query(fields: list[str]) → AndQuery

    Return a query for entities with same values in the given fields.

  classmethod all_keys() → KeysView[str]

    Get a list of available keys for objects of this type. Includes fixed and computed fields.

  clear_dirty() → None

    Mark all fields as clean (i.e., not needing to be stored to the database). Also update the revision.

  copy() → Self

    Create a copy of the model object.

    The field values and other state is duplicated, but the new copy remains associated with the same database as the old object. (A simple copy.deepcopy will not work because it would try to duplicate the SQLite connection.)

  property db: D

    Get the database associated with this object.

    This validates that the database is attached and the object has an id.

  evaluate_template(template: str | Template, for_path: bool = False) → str

    Evaluate a template (a string or a Template object) using the object’s fields. If for_path is true, then no new path separators will be added to the template.

  formatted(included_keys: str = '*', for_path: bool = False) → FormattedMapping

    Get a mapping containing all values on this object formatted as human-readable unicode strings.

  get(key: str, default: Any = None, raise_: bool = False) → Any

    Get the value for a field, or default. Alternatively, raise a KeyError if the field is not available.

  get_fresh_from_db() → Self

    Load this object from the database.

  items() → Iterator[tuple[str, Any]]

    Iterate over (key, value) pairs that this object contains. Computed fields are not included.

  keys(computed: bool = False) → KeysView[str]

    Get a list of available field names for this object. The computed parameter controls whether computed (plugin-provided) fields are included in the key list.

  load() → None

    Refresh the object’s metadata from the library database.

    If check_revision is true, the database is only queried loaded when a transaction has been committed since the item was last loaded.

  set_parse(key: str, string: str) → None

    Set the object’s key to a value represented by a string.

  update(values: Mapping[str, Any]) → None

    Assign all values in the given dict.