Skip to main content

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_autocommit for 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 (mysqlclient or pymysql)

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
  • DoltAdminSite with sidebar grouping by database
  • @dolt_autocommit on a product comment view
  • DoltCommitMixin for "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 databases
  • DOLT_ADMIN_EXCLUDE - List of database aliases to skip during admin auto-registration
  • DOLT_AUTO_REGISTER_ADMIN - Set to False to disable auto-registration on admin.site during ready(). Use when providing a custom admin site.

Environment Variables

  • DOLT_REMOTE_USER - Username for remote authentication
  • DOLT_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

Metadata

Release files for django-dolt 1.1.0

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

Source distribution (sdist)

Source distribution for django-dolt 1.1.0
File Size Uploaded Provenance Actions
django_dolt-1.1.0.tar.gz 53.3 kB With provenance Details for django_dolt-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-dolt 1.1.0
File Interpreter ABI Platform Actions
django_dolt-1.1.0-py3-none-any.whl Python 3 none any Details for django_dolt-1.1.0-py3-none-any.whl

Total release size: 96.6 kB

Release files / django_dolt-1.1.0.tar.gz

Download URL django_dolt-1.1.0.tar.gz
Size 53.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f9bc43174781f46f46bb9ba0ee194aa5f3b55a2043800409d88e27e54a564da6
BLAKE2b-256 checksum
How to use checksums
b895900909c91f1b9a07018409caf85df28e7e3110895bf3661312080c9958a3
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 Apr 9, 2026.

Transparency log

Release files / django_dolt-1.1.0-py3-none-any.whl

Download URL django_dolt-1.1.0-py3-none-any.whl
Size 43.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7aae1a1cc1c9210f422830a9f4bafe3eb18f7fba87be1646894e81de97f0855
BLAKE2b-256 checksum
How to use checksums
5335b7386d2b283ba158e6dc86d69dd5ae573f60e01d88d3391e85d1d0b801b3
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 Apr 9, 2026.

Transparency log

Security for django-dolt 1.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_dolt-1.1.0.tar.gz

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 Apr 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

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