# Django MusicBrainz Connector #
[](https://github.com/marios-zindilis/django-musicbrainz-connector/actions/workflows/django.yml)
[](https://django-musicbrainz-connector.readthedocs.org/en/latest/?badge=latest)
[](https://codecov.io/gh/marios-zindilis/django-musicbrainz-connector)
[](https://pypi.python.org/pypi/django-musicbrainz-connector)
[](https://pypi.python.org/pypi/django-musicbrainz-connector)
The **Django MusicBrainz Connector** is a Django app that connects to a replica of the MusicBrainz PostgreSQL database.
## Installation
1. 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](https://github.com/metabrainz/musicbrainz-server).
2. Install this module from PyPI, for example:
```
python3 -m pip install django-musicbrainz-connector
```
Alternatively, install from code:
```
git clone git@github.com:marios-zindilis/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
```
3. Append the app to your Django project's `settings.py` list of `INSTALLED_APPS`, for example:
```python
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
]
```
4. Create a read-only user in the MusicBrainz Postgresql replica database. This step is not required, but it is highly
recommended. Example commands:
```sql
\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 with something like:
```sql
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 | SELECT
```
You can also connect to the database with `psql`:
```
psql -d musicbrainz_db -U django_musicbrainz_connector
SELECT * FROM musicbrainz.area_type;
```
5. Add the MusicBrainz database to your Django project's `settings.py` list of `DATABASES`. You shouldn't use the
MusicBrainz database as the Django default database, because this app is only meant to have read access. For
example:
```python
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",
},
}
```
6. Add the database router to your Django project's `settings.py` list of `DATABASE_ROUTERS`, for example:
```python
DATABASE_ROUTERS = [
"django_musicbrainz_connector.routers.DjangoMusicBrainzConnectorDatabaseRouter",
]
```
7. Apply the migrations. This doesn't make any changes to the MusicBrainz database:
```
python manage.py migrate
```
8. Include the URLs in your Django project's `urls.py`, for example:
```python
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:
1. 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.
2. All models have `Meta.managed` set to `False`.
3. For models registered in the Django Admin, methods `has_add_permission`, `has_change_permission` and
`has_delete_permission` are always set to `False`.
4. All classes that inherit from Django REST Framework's `ViewSet` have `http_method_names` set to `["get"]` only.
Raw data
{
"_id": null,
"home_page": "https://github.com/marios-zindilis/django-musicbrainz-connector",
"name": "django-musicbrainz-connector",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "Marios Zindilis",
"author_email": "marios@zindilis.com",
"download_url": "https://files.pythonhosted.org/packages/44/0c/a690ba5a91cbdb0c8c3975cb358e6569e5190733de7dc794756a8475fa38/django-musicbrainz-connector-0.0.2.tar.gz",
"platform": null,
"description": "# Django MusicBrainz Connector #\n\n[](https://github.com/marios-zindilis/django-musicbrainz-connector/actions/workflows/django.yml)\n[](https://django-musicbrainz-connector.readthedocs.org/en/latest/?badge=latest)\n[](https://codecov.io/gh/marios-zindilis/django-musicbrainz-connector)\n[](https://pypi.python.org/pypi/django-musicbrainz-connector)\n[](https://pypi.python.org/pypi/django-musicbrainz-connector)\n\nThe **Django MusicBrainz Connector** is a Django app that connects to a replica of the MusicBrainz PostgreSQL database.\n\n## Installation\n\n1. Using the Django MusicBrainz Connector requires that you have a replica of the MusicBrainz database. You can create\n one by following the installation steps in the [MusicBrainz Server](https://github.com/metabrainz/musicbrainz-server).\n\n2. Install this module from PyPI, for example:\n\n ```\n python3 -m pip install django-musicbrainz-connector\n ```\n\n Alternatively, install from code:\n\n ```\n git clone git@github.com:marios-zindilis/django-musicbrainz-connector.git\n cd django-musicbrainz-connector\n python setup.py sdist\n python -m pip install dist/django-musicbrainz-connector-0.0.1.tar.gz\n ```\n\n3. Append the app to your Django project's `settings.py` list of `INSTALLED_APPS`, for example:\n\n ```python\n INSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n 'django_musicbrainz_connector', # <-- like this\n ]\n ```\n\n4. Create a read-only user in the MusicBrainz Postgresql replica database. This step is not required, but it is highly\n recommended. Example commands:\n\n ```sql\n \\c musicbrainz_db\n CREATE USER django_musicbrainz_connector WITH PASSWORD 'sUp3rSecr3t';\n GRANT CONNECT ON DATABASE musicbrainz_db TO django_musicbrainz_connector;\n GRANT USAGE ON SCHEMA musicbrainz TO django_musicbrainz_connector;\n GRANT SELECT ON ALL TABLES IN SCHEMA musicbrainz TO django_musicbrainz_connector;\n ALTER USER django_musicbrainz_connector SET SEARCH_PATH TO musicbrainz;\n ```\n\n You can confirm this with something like:\n\n ```sql\n SELECT grantee, privilege_type FROM information_schema.role_table_grants WHERE table_name='area_type';\n ```\n\n The output should include the user you just created:\n\n ```\n grantee | privilege_type\n ------------------------------+----------------\n musicbrainz | INSERT\n musicbrainz | SELECT\n musicbrainz | UPDATE\n musicbrainz | DELETE\n musicbrainz | TRUNCATE\n musicbrainz | REFERENCES\n musicbrainz | TRIGGER\n django_musicbrainz_connector | SELECT\n ```\n\n You can also connect to the database with `psql`:\n\n ```\n psql -d musicbrainz_db -U django_musicbrainz_connector\n SELECT * FROM musicbrainz.area_type;\n ```\n\n5. Add the MusicBrainz database to your Django project's `settings.py` list of `DATABASES`. You shouldn't use the\n MusicBrainz database as the Django default database, because this app is only meant to have read access. For\n example:\n\n ```python\n DATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n },\n 'musicbrainz_db': {\n 'NAME': \"musicbrainz_db\",\n \"ENGINE\": \"django.db.backends.postgresql\",\n \"USER\": \"django_musicbrainz_connector\",\n \"PASSWORD\": \"sUp3rSecr3t\",\n },\n }\n ```\n\n6. Add the database router to your Django project's `settings.py` list of `DATABASE_ROUTERS`, for example:\n\n ```python\n DATABASE_ROUTERS = [\n \"django_musicbrainz_connector.routers.DjangoMusicBrainzConnectorDatabaseRouter\",\n ]\n ```\n\n7. Apply the migrations. This doesn't make any changes to the MusicBrainz database:\n\n ```\n python manage.py migrate\n ```\n\n8. Include the URLs in your Django project's `urls.py`, for example:\n\n ```python\n urlpatterns = [\n path(\"admin/\", admin.site.urls),\n path(\"mb/\", include(\"django_musicbrainz_connector.urls\")), # <-- like this\n # other stuff here\n ]\n ```\n\n## Notes on Read-Only Access\n\nThis app provides read-only connectivity to the database, because it assumes that you maintain a replica of the\nMusicBrainz Postgresql database, and therefore it makes no sense to be able to write to it. This is done in several\nways:\n\n1. It is recommended that you create a read-only user in Postgresql, and use that user for this app. The installation\n documentation includes step-by-step instructions for this.\n\n2. All models have `Meta.managed` set to `False`.\n\n3. For models registered in the Django Admin, methods `has_add_permission`, `has_change_permission` and\n `has_delete_permission` are always set to `False`.\n\n4. All classes that inherit from Django REST Framework's `ViewSet` have `http_method_names` set to `[\"get\"]` only.\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "A Django app that connects to a replica of the MusicBrainz database.",
"version": "0.0.2",
"project_urls": {
"Homepage": "https://github.com/marios-zindilis/django-musicbrainz-connector"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "497c74d21e51e13c631d31f8ad752f27e35c088f3b0930c0240685a169f7ec97",
"md5": "bcb808b491e4cb7103da3e1da418dfcc",
"sha256": "3ca839f74f9df9c14e7cc9e8a72e043dbd566dba8aac83e00a2a8ef698722659"
},
"downloads": -1,
"filename": "django_musicbrainz_connector-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bcb808b491e4cb7103da3e1da418dfcc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 19577,
"upload_time": "2023-11-12T13:12:43",
"upload_time_iso_8601": "2023-11-12T13:12:43.888128Z",
"url": "https://files.pythonhosted.org/packages/49/7c/74d21e51e13c631d31f8ad752f27e35c088f3b0930c0240685a169f7ec97/django_musicbrainz_connector-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "440ca690ba5a91cbdb0c8c3975cb358e6569e5190733de7dc794756a8475fa38",
"md5": "e16d526f6cf5be9bddcf5d58f1ab4f14",
"sha256": "157cbb1f78f0db359d9e1a5c4c2d52fc32102848eb553fb244b64be925f4bb6f"
},
"downloads": -1,
"filename": "django-musicbrainz-connector-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "e16d526f6cf5be9bddcf5d58f1ab4f14",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 14821,
"upload_time": "2023-11-12T13:12:38",
"upload_time_iso_8601": "2023-11-12T13:12:38.907694Z",
"url": "https://files.pythonhosted.org/packages/44/0c/a690ba5a91cbdb0c8c3975cb358e6569e5190733de7dc794756a8475fa38/django-musicbrainz-connector-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-12 13:12:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "marios-zindilis",
"github_project": "django-musicbrainz-connector",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "django",
"specs": []
},
{
"name": "setuptools",
"specs": []
},
{
"name": "djangorestframework",
"specs": []
}
],
"lcname": "django-musicbrainz-connector"
}