django-rich pre-commit

Extensions for using Rich with Django.


Python 3.6 to 3.10 supported.

Django 2.2 to 4.0 supported.

Are your tests slow? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.


  1. Install with pip:

    python -m pip install django-rich


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.

You can use self.console like so:

from import RichCommand

class Command(RichCommand):
    def handle(self, *args, **options):
        self.console.print("[bold red]Alert![/bold red]")

You can customize the construction of the Console by overriding the make_rich_console class attribute. This should be a callable that returns a Console, such as a functools.partial. For example, to disable the default-on markup and highlighting flags:

from functools import partial

from import RichCommand
from rich.console import Console

class Command(RichCommand):
    make_rich_console = partial(Console, markup=False, highlight=False)

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

Download source code from Github

Download ZIP

Submit resources