Performance

Django management command startup time has the potential to be noticeably slow, especially for large projects with many apps and models. Django must be fully bootstrapped before management commands can run. This can make the CLI feel sluggish and presents particular challenges for shell completion as this delay is incurred each time <tab> is pressed.

If you are experiencing difficulty with shell completion we recommend:

  1. Enabling menu based completion navigation in your terminal. This can reduce the number of calls to shellcompletion. For z-shell this would look like:

    zstyle ':completion:*' menu select
    
  2. Use import and performance analysis tools to determine if there are import bottle necks that can be lazily loaded.

The following benchmarks show total module loads, import and runtimes. All times are in seconds.

The first benchmark is for a minimal project that uses the settings file generated by startproject. You can see that when rich is installed several hundred extra modules must be imported. This adds a few 10s of milliseconds to the import time. To avoid this, uninstall rich. As of Typer 0.17, rich is lazily loaded, but until certain improvements are made to Typer , the import time penalty is still incurred by django-typer.

CLI Startup Benchmarks darwin | arm64 | Python 3.13 django-typer 3.3.0 | Typer 0.17 | Django 5.2   TyperCommand     TyperCommand    BaseCommandTyperCommand     (rich)        --help (rich)    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━  modules    550        592            745              746        time      0.16        0.17          0.24             0.22        imports   0.10        0.12          0.16             0.17       

The second benchmark shows the same stats for the polls example code. These benchmarks compare the BaseCommand native implementation to the TyperCommand implementation. They show that the overhead of using django-typer is minimal. On the order of a few 10s of milliseconds. Adding rich increases this overhead slightly, but the impact is still barely noticeable.

CLI Startup Benchmarks darwin | arm64 | Python 3.13 django-typer 3.3.0 | Typer 0.17 | Django 5.2   polls     polls     polls    --help    shell      polls     --help    polls     shell    (typer   (typer  completion (tutorial)(tutorial) (typer)  completi… w/rich)   w/rich)   (rich)    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━  modules   573       551       615       606      768       747      755     time      0.15      0.15      0.17     0.20      0.24     0.22      0.27    imports   0.11      0.10      0.12     0.12      0.16     0.15      0.15