Django integration for Dolt version-controlled databases, with multi-database support
Project description
django-dolt
Django integration for Dolt version-controlled databases, with multi-database support.
Features
- Service layer - Python API for Dolt operations (add, commit, push, pull, diff, status, log)
- Management commands - CLI tools for database version control
- Admin integration - Browse branches, commits, remotes, and status; commit from the admin UI
- View decorator -
@dolt_autocommitfor automatic commits after view execution - Multi-database support - Manage multiple Dolt databases from one Django project
Requirements
- Python 3.12+
- Django 5.0+
- A Dolt database (speaks MySQL wire protocol)
- A MySQL client library (
mysqlclientorpymysql)
Installation
pip install django-dolt
Add to INSTALLED_APPS and configure your Dolt databases:
INSTALLED_APPS = [
...
"django_dolt",
]
DATABASES = {
"default": { ... },
"dolt": {
"ENGINE": "django.db.backends.mysql",
"NAME": "my_dolt_db",
"HOST": "127.0.0.1",
"PORT": "3306",
"USER": "root",
"PASSWORD": "...",
},
}
# Tell django-dolt which database aliases are Dolt databases
DOLT_DATABASES = ["dolt"]
Usage
Service Layer
from django_dolt import (
dolt_add,
dolt_commit,
dolt_add_and_commit,
dolt_status,
dolt_log,
dolt_diff,
dolt_push,
dolt_pull,
)
# Stage and commit atomically (recommended)
commit_hash = dolt_add_and_commit(
"Add new features",
author="Dev <dev@example.com>",
using="dolt",
)
# Returns None if nothing to commit
# Or stage and commit separately
dolt_add("my_table", using="dolt") # Stage specific table
dolt_add(using="dolt") # Stage all tables
commit_hash = dolt_commit("Update data", using="dolt")
# Check status
status = dolt_status(using="dolt")
for change in status:
print(f"{change['table_name']}: {change['status']} (staged={change['staged']})")
# View history
commits = dolt_log(limit=10, using="dolt")
for commit in commits:
print(f"{commit['commit_hash'][:8]} - {commit['message']}")
# View diff
changes = dolt_diff(from_ref="HEAD~1", to_ref="HEAD", using="dolt")
# Push to remote
dolt_push(remote="origin", branch="main", using="dolt")
# Pull from remote
dolt_pull(remote="origin", using="dolt")
All service functions accept a using keyword argument to specify which database alias to operate on.
View Decorator
Auto-commit after successful view execution:
from django_dolt import dolt_autocommit
@dolt_autocommit(using="dolt")
def my_view(request):
# ... modify data ...
return HttpResponse("OK")
# With dynamic message and author
@dolt_autocommit(
message=lambda req: f"Update by {req.user}",
author=lambda req: f"{req.user.get_full_name()} <{req.user.email}>",
using="dolt",
)
def my_view(request):
...
# Only commit when a condition is met
@dolt_autocommit(commit_on=lambda req, resp: resp.status_code == 200, using="dolt")
def my_view(request):
...
Management Commands
# Show database status
python manage.py dolt_status
python manage.py dolt_status --database dolt --log 5
# Commit and push changes
python manage.py dolt_sync "Update data"
python manage.py dolt_sync --database dolt --force
python manage.py dolt_sync --no-push # Commit only
# Pull from remote
python manage.py dolt_pull
python manage.py dolt_pull --database dolt --fetch-only
Admin Integration
Option 1: Use the full Dolt admin site (recommended):
# urls.py
from django_dolt.admin import DoltAdminSite
admin_site = DoltAdminSite()
urlpatterns = [
path("admin/", admin_site.urls),
]
# settings.py
DOLT_AUTO_REGISTER_ADMIN = False # Disable auto-registration on default admin
Option 2: Add Dolt views to your existing admin:
# admin.py
from django.contrib.admin import AdminSite
from django_dolt.admin import DoltAdminMixin
class MyAdminSite(DoltAdminMixin, AdminSite):
pass
The admin provides:
- Branch, commit, and remote browsing per database
- Status view with ability to commit (superusers only) at
/admin/dolt/status/{db_alias}/ - Sidebar grouping by database when using
DoltAdminSite
Save and commit from model forms:
from django_dolt import DoltCommitMixin
class MyModelAdmin(DoltCommitMixin, admin.ModelAdmin):
dolt_database = "dolt" # Which database to commit to
This adds a "Save and commit" button to the change form.
Demo Application
The demo/ directory contains a fake e-commerce app demonstrating multi-database Dolt integration with two independent version-controlled databases:
- Inventory database — Categories, products, and product comments
- Orders database — Customers, orders, and order items
The standard Django tables (auth, sessions, etc.) live in SQLite or Postgres as usual, while data you want to version control lives in your Dolt databases. A database router directs models to the right backend.
The demo showcases:
- Multi-database routing with per-database version history
DoltAdminSitewith sidebar grouping by database@dolt_autocommiton a product comment viewDoltCommitMixinfor "Save and commit" in admin forms- Dashboard views showing working set status and commit history
docker compose up -d # Start Dolt server
cd demo
uv pip install -e "..[demo]"
python manage.py setup_demo # Create databases, migrate, seed data
python manage.py createsuperuser
python manage.py runserver
Then visit http://localhost:8000/ for the app or http://localhost:8000/admin/ for the admin.
Configuration
Settings
DOLT_DATABASES- List of database aliases that are Dolt databasesDOLT_ADMIN_EXCLUDE- List of database aliases to skip during admin auto-registrationDOLT_AUTO_REGISTER_ADMIN- Set toFalseto disable auto-registration onadmin.siteduringready(). Use when providing a custom admin site.
Environment Variables
DOLT_REMOTE_USER- Username for remote authenticationDOLT_REMOTE_PASSWORD- Password (must be set at Dolt server level)
dolt_ignore
To exclude tables from version control, add patterns to the dolt_ignore table:
INSERT INTO dolt_ignore (pattern, ignored) VALUES ('django_%', 1);
INSERT INTO dolt_ignore (pattern, ignored) VALUES ('auth_%', 1);
Development
# Install dev dependencies
uv sync
# Run tests (requires Docker — auto-starts Dolt container)
bin/test
bin/test src/django_dolt/tests/test_services.py
# Type checking
uv run mypy src/django_dolt
# Linting
uv run ruff check src/django_dolt
License
MIT
Inspirations
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_dolt-1.1.0.tar.gz.
File metadata
- Download URL: django_dolt-1.1.0.tar.gz
- Upload date:
- Size: 53.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9bc43174781f46f46bb9ba0ee194aa5f3b55a2043800409d88e27e54a564da6
|
|
| MD5 |
4cae9050ac443157b9feab2b6d79c8e5
|
|
| BLAKE2b-256 |
b895900909c91f1b9a07018409caf85df28e7e3110895bf3661312080c9958a3
|
Provenance
The following attestation bundles were made for django_dolt-1.1.0.tar.gz:
Publisher:
publish.yml on myers/django-dolt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_dolt-1.1.0.tar.gz -
Subject digest:
f9bc43174781f46f46bb9ba0ee194aa5f3b55a2043800409d88e27e54a564da6 - Sigstore transparency entry: 1266444385
- Sigstore integration time:
-
Permalink:
myers/django-dolt@13261b7c83f622fcc735a5c3dd270f1f5906ae4a -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/myers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@13261b7c83f622fcc735a5c3dd270f1f5906ae4a -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_dolt-1.1.0-py3-none-any.whl.
File metadata
- Download URL: django_dolt-1.1.0-py3-none-any.whl
- Upload date:
- Size: 43.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7aae1a1cc1c9210f422830a9f4bafe3eb18f7fba87be1646894e81de97f0855
|
|
| MD5 |
60144827c3be3353c1b4b9d00e35255d
|
|
| BLAKE2b-256 |
5335b7386d2b283ba158e6dc86d69dd5ae573f60e01d88d3391e85d1d0b801b3
|
Provenance
The following attestation bundles were made for django_dolt-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on myers/django-dolt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_dolt-1.1.0-py3-none-any.whl -
Subject digest:
e7aae1a1cc1c9210f422830a9f4bafe3eb18f7fba87be1646894e81de97f0855 - Sigstore transparency entry: 1266444532
- Sigstore integration time:
-
Permalink:
myers/django-dolt@13261b7c83f622fcc735a5c3dd270f1f5906ae4a -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/myers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@13261b7c83f622fcc735a5c3dd270f1f5906ae4a -
Trigger Event:
push
-
Statement type: