Code conventions
The rule book of the server is AGENTS.md. It is written for AI assistants and holds for people too. This page lists the points a review checks most often. Several of them are also pre-commit hooks, see Test your change.
- Async only. The server is one event loop, so a blocking call stalls everything. Use an async library, or
asyncio.to_threadfor blocking work. Thecheck_blocking_iohook catches known blocking calls. New to asyncio? Start with the asyncio documentation. - Names that explain. A function, variable or class name says what it does or holds, so a reader does not have to guess.
- Private methods at the bottom. Public methods come first, private ones last; the
check_method_orderhook checks it within a class. - Reuse the helpers. Look in
music_assistant/helpers/before you write a utility. For the current time, useutc()ornow()fromhelpers/datetime.py, neverdatetime.now().
Docstrings and comments
Section titled “Docstrings and comments”A docstring tells the caller what a function does and what its parameters mean, not how it works inside. Use Sphinx style with :param:, and start a multi-line docstring on the line after the quotes:
async def get_report(self, include_log_tail: bool = False) -> dict[str, Any]: """ Return a full (sanitized) diagnostics report.
:param include_log_tail: Include the recent warning/error log excerpt. """Write a comment only where the code is not clear on its own. Keep the comments others wrote unless they no longer hold. Docstrings and comments describe the code as it is, not what changed.
Documentation next to the code
Section titled “Documentation next to the code”The README.md in the folder of a controller or provider explains its layout, data model and design. A change that makes it wrong or incomplete updates it in the same pull request.
Stored data
Section titled “Stored data”A change to a config key or a database table needs a migration, and a maintainer decides how before the work is done. Where data lives explains the rules.
The API schema version
Section titled “The API schema version”A new command, a new or changed parameter, or a new field the server sends raises API_SCHEMA_VERSION in music_assistant/constants.py. The comment next to it says when, and The API and events explains why.
Texts and translations
Section titled “Texts and translations”Text a user sees lives in a strings.json: the shared one in music_assistant/ or the one in the folder of your provider or controller. Code refers to it by key:
- A
ConfigEntryhas no label in code. Its label and description areconfig_entries.<key>.labelandconfig_entries.<key>.descriptioninstrings.json. - A browse or recommendation folder sets
translation_key, with its English name instrings.json.
scripts/build_translations.py combines every strings.json into translations/en.json, which the translators work from. The check_config_entries and check_translatable_labels hooks fail on text written in code.
The usage policy
Section titled “The usage policy”Music Assistant streams music to your own speakers; it is not a way to download or keep copies of it. Some guards exist only for that reason and must stay: the read-rate pacing on the stream endpoints, background audio analysis only on local files, and the artist tracks listing that stays empty for a provider without an artist tracks endpoint. The usage policy and Streaming rules explain what a provider must and must not do.
Music Assistant is a project of the Open Home Foundation.