Skip to main content
https://img.shields.io/github/actions/workflow/status/adamchainz/django-rich/main.yml.svg?branch=main&style=for-the-badge https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge https://img.shields.io/pypi/v/django-rich.svg?style=for-the-badge https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge pre-commit

Extensions for using Rich with Django.


Work smarter and faster with my book Boost Your Django DX which covers many ways to improve your development experience. I wrote django-rich whilst working on the book!


Requirements

Python 3.9 to 3.14 supported.

Django 4.2 to 6.0 supported.

Installation

  1. Install with pip:

    python -m pip install django-rich

None of django-rich’s features are activated by default. Follow the documentation below to use them.

Reference

shell command integration

django-rich has an extended version of Django’s built-in shell command that does two things:

  1. It enables Rich’s pretty-printing.

  2. On Django 5.2+, it adds automatic imports of these functions from Rich:

To activate this feature, add django_rich to your INSTALLED_APPS setting:

INSTALLED_APPS = [
    ...,
    "django_rich",
    ...,
]

This feature only affects the Python and bypthon interpreters, not IPython. For IPython support, see the Rich documentation.

django_rich.management.RichCommand

A subclass of Django’s BaseCommand class that sets its self.console to a Rich Console. The Console uses the command’s stdout argument, which defaults to sys.stdout. Colourization is enabled or disabled according to Django’s --no-color and --force-color flags.

Use the features of self.console as you like:

from time import sleep

from django_rich.management import RichCommand


class Command(RichCommand):
    def handle(self, *args, **options):
        self.console.print("[bold blue]Frobnicating widgets:[/bold blue]")

        with self.console.status("Starting...") as status:
            for i in range(1, 11):
                status.update(f"Widget {i}...")
                sleep(1)
                self.console.log(f"Widget {i} frobnicated.")

You can customize the construction of the Console by overriding the make_rich_console() method. This takes some keyword arguments and passes them to the Console constructor. For example, to disable the on-by-default markup and highlighting flags, add them in a call to super():

from functools import partial

from django_rich.management import RichCommand
from rich.console import Console


class Command(RichCommand):
    def make_rich_console(self, **kwargs):
        return super().make_rich_console(**kwargs, markup=False, highlight=False)

    def handle(self, *args, **options): ...

django_rich.test.RichRunner

A subclass of Django’s DiscoverRunner with colourized outputs and nice traceback rendering.

https://raw.githubusercontent.com/adamchainz/django-rich/main/img/RichRunner.png

To use this class, point your TEST_RUNNER setting to it:

TEST_RUNNER = "django_rich.test.RichRunner"

You can also use it as a base for further customization. Since only output is modified, it should combine well with other classes.

The test runner provides the following features:

  • Output is colourized wherever possible. This includes Rich’s default highlighting which will format numbers, quoted strings, URL’s, and more.

  • Failures and errors use Rich’s traceback rendering. This displays the source code and local values per frame. Each frame also shows the filename and line number, and on many terminals you can click the link to jump to the file at that position.

  • Output is also colourized when using the --debug-sql and --pdb flags.

  • All other flags from Django’s DiscoverRunner continue to work in the normal way.

Output Width on CI

When tests run on your CI system, you might find the output a bit narrow for showing tracebacks correctly. This is because Rich tries to autodetect the terminal dimensions, and if that fails, it will default to 80 characters wide. You can override this default with the COLUMNS environment variable (as per Python’s shutil.get_terminal_size() function):

$ COLUMNS=120 ./manage.py test

Release files for django-rich 2.2.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-rich 2.2.0
File Size Uploaded
django_rich-2.2.0.tar.gz 62.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-rich 2.2.0
File Interpreter ABI Platform
django_rich-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 71.6 kB

Release files / django_rich-2.2.0.tar.gz

Download URL django_rich-2.2.0.tar.gz
Size 62.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ecec7842d040024ed8a225699388535e46b87277550c33f46193b52cece2f780
BLAKE2b-256 checksum
How to use checksums
a667e307a5fef657e7992468f567b521534c52e01bdda5a1ae5b12de679a670f
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 Sep 18, 2025.

Transparency log

Release files / django_rich-2.2.0-py3-none-any.whl

Download URL django_rich-2.2.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0d2c916bd9750b6e9beb57407aef5e836c8705d7dbe9e4fd4725f7bbe41c407
BLAKE2b-256 checksum
How to use checksums
27ed23fa669493d78cd67e7f6734fa380f8690f2b4d75b4f72fd645a52c3b32a
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 Sep 18, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.13.0

2 release files

1.12.0

2 release files

1.11.0

2 release files

1.10.0

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

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