Skip to main content

pypi badge

If you are developing a Python application that needs access to the MusicBrainz data, you can use the mbdata.models module to get SQLAlchemy models mapped to the MusicBrainz database tables.

All tables from the MusicBrainz database are mapped, all foreign keys have one-way relationships set up and some models, where it’s essential to access their related models, have two-way relationships (collections) set up.

In order to work with the relationships efficiently, you should use the appropriate kind of eager loading.

Example usage of the models:

>>> from sqlalchemy import create_engine
>>> from sqlalchemy.orm import sessionmaker
>>> from mbdata.models import Artist
>>> engine = create_engine('postgresql://musicbrainz:musicbrainz@127.0.0.1/musicbrainz', echo=True)
>>> Session = sessionmaker(bind=engine)
>>> session = Session()
>>> artist = session.query(Artist).filter_by(gid='8970d868-0723-483b-a75b-51088913d3d4').first()
>>> print artist.name

If you use the models in your own application and want to define foreign keys from your own models to the MusicBrainz schema, you will need to let mbdata know which metadata object to add the MusicBrainz tables to:

from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

# this should be the first place where you import anything from mbdata
import mbdata.config
mbdata.config.configure(base_class=Base)

# now you can import and use the mbdata models
import mbdata.models

You can also use mbdata.config to re-map the MusicBrainz schema names, if your database doesn’t follow the original structure:

import mbdata.config
mbdata.config.configure(schema='my_own_mb_schema')

If you need sample MusicBrainz data for your tests, you can use mbdata.sample_data:

from mbdata.sample_data import create_sample_data
create_sample_data(session)

Development

Normally you should work against a regular PostgreSQL database with MusicBrainz data, but for testing purposes, you can use a SQLite database with small data sub-set used in unit tests. You can create the database using:

./bin/create_sample_db.py sample.db

Then you can change your configuration:

DATABASE_URI = 'sqlite:///sample.db'

Running tests:

pytest -v

If you want to see the SQL queries from a failed test, you can use the following:

MBDATA_DATABASE_ECHO=1 pytest -v

GitHub Actions workflow that automatically runs the tests after each commit is here.

Release files for mbdata 31.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mbdata 31.0.1
File Size Uploaded
mbdata-31.0.1.tar.gz 200.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mbdata 31.0.1
File Interpreter ABI Platform
mbdata-31.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 448.2 kB

Release files / mbdata-31.0.1.tar.gz

Download URL mbdata-31.0.1.tar.gz
Size 200.8 kB
Tags Source
SHA-256 checksum
How to use checksums
859d2cacd70c7739c7444bc98cb6f57156e07c1c449b1bda56e8a74e515ba774
BLAKE2b-256 checksum
How to use checksums
36b1910cb8ec907580e3b77c9ae4ac3f4b4809d94a8e75f40746a4deef126dc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 8, 2026.

Transparency log

Release files / mbdata-31.0.1-py3-none-any.whl

Download URL mbdata-31.0.1-py3-none-any.whl
Size 247.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eda71b614e3d98fa26c8d81163730cc17e1e905f55a7bab1fa5fac961e8db4e7
BLAKE2b-256 checksum
How to use checksums
582aba28902a0167ea520a41a2bbbfabc0dee011eea9ba58d9f967c6b0822095
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

31.0.1 This release

2 release files

30.0.1

2 release files

27.1.0

1 release file

26.0.1

1 release file

26.0.0

1 release file

25.0.4

1 release file

25.0.3

1 release file

25.0.2

1 release file

25.0.1

1 release file

25.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page