← Docs

Django

Gold Lapel ships Django support inside the Python wrapper — no separate plugin to install. Swap the database backend in settings.py and Gold Lapel starts on first connection.

Install

pip install goldlapel

The same install you'd use anywhere else in Python. The Django glue lives inside the goldlapel package at goldlapel.django. Install Django itself with regular pip.

Configure

Replace the engine in your database config — everything else stays as it is:

# settings.py
DATABASES = {
    "default": {
        "ENGINE": "goldlapel.django",  # was: django.db.backends.postgresql
        "NAME": "mydb",
        "USER": "myuser",
        "PASSWORD": "mypassword",
        "HOST": "localhost",
        "PORT": "5432",
    }
}

Gold Lapel starts when Django opens its first database connection. The L1 native cache activates with it — repeated reads serve in microseconds. The Django ORM, raw SQL, select_related, QuerySet, and migrations all flow through unchanged.

Management commands

manage.py migrate, makemigrations, dbshell, loaddata, and dumpdata all use the same backend, so they all route through Gold Lapel. Writes invalidate the cache; migrations see fresh data.

Configuration

Optional proxy settings live under OPTIONS.goldlapel in your database config:

DATABASES = {
    "default": {
        "ENGINE": "goldlapel.django",
        "NAME": "mydb",
        "USER": "myuser",
        "PASSWORD": "mypassword",
        "HOST": "localhost",
        "PORT": "5432",
        "OPTIONS": {
            "goldlapel": {
                "port": 9000,
                "config": {
                    "mode": "waiter",
                    "pool_size": 50,
                },
                "extra_args": ["--threshold-duration-ms", "200"],
            }
        },
    }
}
KeyDefaultDescription
port7932Local proxy port
config{}Full Gold Lapel config dict (same keys as goldlapel.start(config=...))
extra_args[]Extra CLI flags passed to the Gold Lapel binary

The config dict accepts the same keys as goldlapel.start(config=...) — see the configuration reference for every setting. extra_args and GOLDLAPEL_* environment variables are also available.

Multiple databases

Each connection wants its own proxy port:

DATABASES = {
    "default": {
        "ENGINE": "goldlapel.django",
        "HOST": "db1.example.com",
        "OPTIONS": {"goldlapel": {"port": 7932}},
    },
    "analytics": {
        "ENGINE": "goldlapel.django",
        "HOST": "db2.example.com",
        "OPTIONS": {"goldlapel": {"port": 7942}},
    },
}

Database routers, read replicas, and multi-tenant patterns continue to work — each connection carries its own Gold Lapel instance.

Requirements

  • Python 3.9+
  • Django 4.2+
  • goldlapel 0.2+
  • PostgreSQL (TCP connections)

How it works

goldlapel.django subclasses Django's PostgreSQL backend. On first connection it builds the upstream URL from your DATABASES entry, calls goldlapel.start() to spawn the proxy, and returns a wrapped connection with the L1 native cache attached. From there, every ORM call, raw query, and migration flows through Gold Lapel.

For the underlying Python wrapper API — goldlapel.start(), async support, and the wrapper helpers — see the Python guide.