Skip to main content

django-fqq

Tests

Generate schema-prefixed table names with the Django ORM.

django-fqq provides a custom database backend that wraps Django's built-in PostgreSQL backend. It overrides quote_name to prepend the active schema to table names — so "my_table" becomes "my_schema"."my_table" automatically. No changes to your models or queries required.

django-fqq does not modify queries if set_schema has not been called or has been set to a falsy value (e.g. None or "").

Installation

pip install django-fqq

Configuration

1. Set the database backend

DATABASES = {
    "default": {
        "ENGINE": "django_fqq.backend",
        "NAME": "your_db",
        # ... other options
    }
}

If you need a custom database backend you can either inherit from django_fqq.backend.base.DatabaseWrapper or set ops_class = DatabaseOperations from django_fqq.backend.operations.DatabaseOperations in your DatabaseWrapper.

2. Add the app

INSTALLED_APPS = [
    # ...
    "django_fqq",
]

3. Configure shared apps (optional)

Apps listed in FQQ_SHARED_APPS will always use the public schema, regardless of the active schema.

FQQ_SHARED_APPS = ["auth", "contenttypes"]

4. Add the middleware (optional)

The middleware provides very basic routing of requests to a specific database schema. For a more robust solution that handles migrations and other functionality, check out django-tenants.

MIDDLEWARE = [
    "django_fqq.middleware.SchemaMiddleware",
    # ...
]

Subclass SchemaMiddleware and override _get_schema(request) to resolve the schema from the request (e.g. from subdomain, header, or URL).

Usage

Setting the schema manually

from django_fqq.schema import set_schema, clear_schema

set_schema("my_schema")
# All queries now target the "my_schema" schema
# ...
clear_schema()

In a middleware or view

from django_fqq.middleware import SchemaMiddleware

class MySchemaMiddleware(SchemaMiddleware):
    def _get_schema(self, request):
        host = request.get_host().split(".")[0]
        return host

Using a context manager

query_schema sets the schema for the duration of a block and restores the previous state on exit.

from django_fqq.schema import query_schema

with query_schema("my_schema"):
    # All queries target "my_schema"
    ...
# Schema is restored to its previous value (or cleared if none was set)

Nesting is supported — each level restores the schema that was active before it:

from django_fqq.schema import set_schema, query_schema

set_schema("schema_a")

with query_schema("schema_b"):
    # queries target "schema_b"
    with query_schema("schema_c"):
        # queries target "schema_c"
        ...
    # back to "schema_b"

# back to "schema_a"

Context-safe

Schema state is stored in a ContextVar, so it's safe across concurrent async requests and threads.

Development

Requires Python 3.12+ and Django 4.2+. Tested against Django 4.2, 5.2, and 6.0.

uv sync
uv run pytest

License

MIT

Metadata

Release files for django-fqq 0.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-fqq 0.1.0
File Size Uploaded Provenance Actions
django_fqq-0.1.0.tar.gz 8.0 kB With provenance Details for django_fqq-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-fqq 0.1.0
File Interpreter ABI Platform Actions
django_fqq-0.1.0-py3-none-any.whl Python 3 none any Details for django_fqq-0.1.0-py3-none-any.whl

Total release size: 13.8 kB

Release files / django_fqq-0.1.0.tar.gz

Download URL django_fqq-0.1.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3bfbcab41fb810e61f9838acc5929d2b697afe08317c1727c515685becfd5660
BLAKE2b-256 checksum
How to use checksums
b49afc35298d5f525c2172996865d68ae88c189f06c221cc009cee4ae069076d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 15, 2026.

Transparency log

Release files / django_fqq-0.1.0-py3-none-any.whl

Download URL django_fqq-0.1.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e58afd4656fc0133b42c59248d17b56562a7e0ac16faa2d6a9206b760fe1f605
BLAKE2b-256 checksum
How to use checksums
141e02c5a37587e4ff5398d5d01bdbb8d86083b8fcda4108b95669d7ea46909d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 15, 2026.

Transparency log

Security for django-fqq 0.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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_fqq-0.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 Mar 15, 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

0.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