mopidy.ext – Extension API
If you want to learn how to make Mopidy extensions, read Extension development.
- class mopidy.ext.Extension[source]
Base class for Mopidy extensions.
-
dist_name:
str The extension’s distribution name, as registered on PyPI
Example:
Mopidy-Soundspot
-
ext_name:
str The extension’s short name, as used in setup.py and as config section name
Example:
soundspot
- classmethod get_cache_dir(config) Path[source]
Get or create cache directory for the extension.
Use this directory to cache data that can safely be thrown away.
- Parameters:
config (
TypeAliasType) – the Mopidy config object- Return type:
Path- Returns:
pathlib.Path
- classmethod get_config_dir(config) Path[source]
Get or create configuration directory for the extension.
- Parameters:
config (
TypeAliasType) – the Mopidy config object- Return type:
Path- Returns:
pathlib.Path
- get_config_schema() ConfigSchema[source]
The extension’s config validation schema.
- Return type:
- Returns:
- classmethod get_data_dir(config) Path[source]
Get or create data directory for the extension.
Use this directory to store data that should be persistent.
- Parameters:
config (
TypeAliasType) – the Mopidy config object- Return type:
Path- Returns:
pathlib.Path
- get_default_config() str[source]
The extension’s default config as a text string.
- Return type:
str- Returns:
str
- setup(registry) None[source]
Register the extension’s components in the extension
Registry.For example, to register a backend:
def setup(self, registry): from .backend import SoundspotBackend registry.add('backend', SoundspotBackend)
See
Registryfor a list of registry keys with a special meaning. Mopidy will instantiate and start any classes registered under thefrontendandbackendregistry keys.This method can also be used for other setup tasks not involving the extension registry.
- Parameters:
registry (
Registry) – the extension registry- Return type:
None
- validate_environment() None[source]
Checks if the extension can run in the current environment.
Dependencies described by
setup.pyare checked by Mopidy, so you should not check their presence here.If a problem is found, raise
ExtensionErrorwith a message explaining the issue.- Raises:
ExtensionError- Return type:
None- Returns:
None
-
version:
str The extension’s version
Should match the
__version__attribute on the extension’s main Python module and the version registered on PyPI.
-
dist_name:
- class mopidy.ext.ExtensionData(extension, entry_point, config_schema, config_defaults, command)[source]
-
-
config_defaults:
Any Alias for field number 3
-
config_schema:
ConfigSchema Alias for field number 2
-
entry_point:
Any Alias for field number 1
-
config_defaults:
- class mopidy.ext.Registry None[source]
Registry of components provided by Mopidy extensions.
Passed to the
setup()method of all extensions. The registry can be used like a dict of string keys and lists.Some keys have a special meaning, including, but not limited to:
backendis used for Mopidy backend classes.frontendis used for Mopidy frontend classes.
Extensions can use the registry for allow other to extend the extension itself. For example the
Mopidy-Localhistorically used thelocal:librarykey to allow other extensions to register library providers forMopidy-Localto use. Extensions should namespace custom keys with the extension’sext_name, e.g.local:fooorhttp:bar.
- mopidy.ext.load_extensions() list[ExtensionData][source]
Find all installed extensions.
- Return type:
list[ExtensionData]- Returns:
list of installed extensions
- mopidy.ext.validate_extension_data(data) bool[source]
Verify extension’s dependencies and environment.
- Parameters:
data (
ExtensionData) – an extension to check- Return type:
bool- Returns:
if extension should be run