A Django app that connects to a replica of the MusicBrainz database.
Project description
Django MusicBrainz Connector
The Django MusicBrainz Connector is a Django app that connects to a replica of the MusicBrainz PostgreSQL database. For more information, see the documentation.
This app is not feature-complete compared to the MusicBrainz schema. For a feature-complete Python alternative based on SQLAlchemy, take a look at mbdata.
Installation
-
Using the Django MusicBrainz Connector requires that you have a replica of the MusicBrainz database. You can create one by following the installation steps in the MusicBrainz Server.
-
Install this module from PyPI, for example:
python3 -m pip install django-musicbrainz-connectorAlternatively, install from code. For example:
git clone git@github.com:mneia-gr/django-musicbrainz-connector.git cd django-musicbrainz-connector python setup.py sdist python -m pip install dist/django-musicbrainz-connector-0.0.1.tar.gz -
Append the app to your Django project's
settings.pylist ofINSTALLED_APPS, for example:INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_musicbrainz_connector', # <-- like this ]
-
Create a read-only user in the MusicBrainz Postgresql replica database. This step is not required, but it is highly recommended. Example commands:
\c musicbrainz_db CREATE USER django_musicbrainz_connector WITH PASSWORD 'sUp3rSecr3t'; GRANT CONNECT ON DATABASE musicbrainz_db TO django_musicbrainz_connector; GRANT USAGE ON SCHEMA musicbrainz TO django_musicbrainz_connector; GRANT SELECT ON ALL TABLES IN SCHEMA musicbrainz TO django_musicbrainz_connector; ALTER USER django_musicbrainz_connector SET SEARCH_PATH TO musicbrainz;
You can confirm this configuration with something like:
SELECT grantee, privilege_type FROM information_schema.role_table_grants WHERE table_name='area_type';
The output should include the user you just created:
grantee | privilege_type ------------------------------+---------------- musicbrainz | INSERT musicbrainz | SELECT musicbrainz | UPDATE musicbrainz | DELETE musicbrainz | TRUNCATE musicbrainz | REFERENCES musicbrainz | TRIGGER django_musicbrainz_connector | SELECTYou can also connect to the database with
psql:psql --dbname musicbrainz_db --username django_musicbrainz_connector SELECT * FROM musicbrainz.area_type; -
Add the MusicBrainz database to your Django project's
settings.pylist ofDATABASES. You shouldn't use the MusicBrainz database as the Django default database, because this app is only meant to have read access. For example:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', }, 'musicbrainz_db': { 'NAME': "musicbrainz_db", "ENGINE": "django.db.backends.postgresql", "USER": "django_musicbrainz_connector", "PASSWORD": "sUp3rSecr3t", }, }
-
Add the database router to your Django project's
settings.pylist ofDATABASE_ROUTERS, for example:DATABASE_ROUTERS = [ "django_musicbrainz_connector.routers.DjangoMusicBrainzConnectorDatabaseRouter", ]
-
Apply the migrations. This doesn't make any changes to the MusicBrainz database:
python manage.py migrate -
Include the URLs in your Django project's
urls.py, for example:urlpatterns = [ path("admin/", admin.site.urls), path("mb/", include("django_musicbrainz_connector.urls")), # <-- like this # other stuff here ]
Notes on Read-Only Access
This app provides read-only connectivity to the database, because it assumes that you maintain a replica of the MusicBrainz Postgresql database, and therefore it makes no sense to be able to write to it. This is done in several ways:
-
It is recommended that you create a read-only user in Postgresql, and use that user for this app. The installation documentation includes step-by-step instructions for this.
-
All models have
Meta.managedset toFalse. -
For models registered in the Django Admin, methods
has_add_permission,has_change_permissionandhas_delete_permissionare always set toFalse. -
All classes that inherit from Django REST Framework's
ViewSethavehttp_method_namesset to["get"]only.
Development
Testing
Install test dependencies with:
python -m pip install --requirement requirements-test.txt
Then, run tests with:
./test
Documentation
To build the documentation locally:
python -m pip install --requirement docs/requirements.txt
sphinx-build -M html docs build/docs
Release
-
Bump the value of
versioninsetup.cfg, and push to GitHub. -
Create a git tag same as the
version, and push it, for example:git tag --annotate v0.0.2 --message "Release v0.0.2" git push origin v0.0.2 -
Build:
python setup.py sdist python setup.py bdist_wheel -
Upload to TestPyPI:
python -m twine upload --repository testpypi dist/* -
If the output looks OK, upload to PyPI:
python -m twine upload dist/* -
Create a new Release on GitHub, from the tag pushed earlier.
-
Publish a blog post on docs.mneia.gr for the new release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_musicbrainz_connector-0.0.9.tar.gz.
File metadata
- Download URL: django_musicbrainz_connector-0.0.9.tar.gz
- Upload date:
- Size: 47.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
943eb3ecd80952939242ee591110c9f5e51d6ee5ba2c928b730d15b3663a6912
|
|
| MD5 |
0ce2669a0acdf75e62f61554f495d975
|
|
| BLAKE2b-256 |
1eaea55e6ded81bdbfe9e3a49e8eead2dca3dd4b7a844ef36e1bbfb353401c9a
|
File details
Details for the file django_musicbrainz_connector-0.0.9-py3-none-any.whl.
File metadata
- Download URL: django_musicbrainz_connector-0.0.9-py3-none-any.whl
- Upload date:
- Size: 95.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fb7704a319db1ea3848d5ebdb36fcd531b3d146dcba6942fca9e9b3ca884092
|
|
| MD5 |
642029f368720bec1c172f165fa96bf4
|
|
| BLAKE2b-256 |
665f04bf25382c1ca442eb3214e8e096d96f0a3348c8c10bd5053efa23ed8aa4
|