### Navigation

- index
- modules |
- next |
- previous |
- Mopidy 1.0.2 documentation »
- Module reference »

# `mopidy.local` – Local backend

For details on how to use Mopidy’s local backend, see Mopidy-Local.

class `mopidy.local.``Library`(config)

  Local library interface.

  Extensions that wish to provide an alternate local library storage backend need to sub-class this class and install and configure it with an extension. Both scanning and library calls will use the active local library.

  Parameters: | config – Config dictionary

  `ROOT_DIRECTORY_URI` = u'local:directory'

    URI of the local backend’s root directory.

    This constant should be used by libraries implementing the `Library.browse()` method.

  `add`(track, tags=None, duration=None)

    Add the given track to library. Optional args will only be added if `add_supports_tags_and_duration` has been set.

    Parameters: | track (`Track`) – Track to add to the library tags (dictionary of tag keys with a list of values.) – All the tags the scanner found for the media. See `mopidy.audio.utils` for details about the tags. duration (`int` or `None`) – Duration of media in milliseconds or `None` if unknown

  `add_supports_tags_and_duration` = False

    Feature marker to indicate that you want `add()` calls to be called with optional arguments tags and duration.

  `begin`()

    Prepare library for accepting updates. Exactly what this means is highly implementation depended. This must however return an iterator that generates all tracks in the library for efficient scanning.

    Return type: | `Track` iterator

  `browse`(uri)

    Browse directories and tracks at the given URI.

    The URI for the root directory is a constant available at `Library.ROOT_DIRECTORY_URI`.

    Parameters: | path (string) – URI to browse.
    Return type: | List of `Ref` tracks and directories.

  `clear`()

    Clear out whatever data storage is used by this backend.

    Return type: | Boolean indicating if state was cleared.

  `close`()

    Close any resources used for updating, commit outstanding work etc.

  `flush`()

    Called for every n-th track indicating that work should be committed. Sub-classes are free to ignore these hints.

    Return type: | Boolean indicating if state was flushed.

  `get_distinct`(field, query=None)

    List distinct values for a given field from the library.

    Parameters: | field (string) – One of `artist`, `albumartist`, `album`, `composer`, `performer`, `date``or ``genre`. query (dict) – Query to use for limiting results, see `search()` for details about the query format.
    Return type: | set of values corresponding to the requested field type.

  `get_images`(uris)

    Lookup the images for the given URIs.

    The default implementation will simply call `lookup()` and try and use the album art for any tracks returned. Most local libraries should replace this with something smarter or simply return an empty dictionary.

    Parameters: | uris (list) – list of URIs to find images for
    Return type: | {uri: tuple of `mopidy.models.Image`}

  `load`()

    (Re)load any tracks stored in memory, if any, otherwise just return number of available tracks currently available. Will be called at startup for both library and update use cases, so if you plan to store tracks in memory this is when the should be (re)loaded.

    Return type: | `int` representing number of tracks in library.

  `lookup`(uri)

    Lookup the given URI.

    Parameters: | uri (string) – track URI
    Return type: | list of `Track` (or single `Track` for backward compatibility)

  `name` = None

    Name of the local library implementation, must be overriden.

  `remove`(uri)

    Remove the given track from the library.

    Parameters: | uri (str) – URI to remove from the library/

  `search`(query=None, limit=100, offset=0, exact=False, uris=None)

    Search the library for tracks where `field` contains `values`.

    Parameters: | query (dict) – one or more queries to search for limit (int) – maximum number of results to return offset (int) – offset into result set to use. exact (bool) – whether to look for exact matches uris (list of strings or `None`) – zero or more URI roots to limit the search to
    Return type: | `SearchResult`

### Navigation

- index
- modules |
- next |
- previous |
- Mopidy 1.0.2 documentation »
- Module reference »