Hi There!
Nuitka (https://nuitka.net/) is a tool that transpiles at least a part of Python code into C++ before compiling it into machine code. Because I’ve been experimenting with some optimization tweaks for my Django apps recently, I came across it, but I didn’t have much success in compiling even a basic Django application with it.
The Nuitka compilation process is something similar to this:
For testing purposes, without starting with a very large project right away, I created a basic project with just a core app and the manager responsible for configurations using uv as the package manager.
├── .venv
├── apps
│ └── core
│ ├── migrations
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── build
│ ├── manage.build
│ └── manage.dist
├── manager
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── .gitignore
├── .python-version
├── manage.py
├── pyproject.toml
├── README.md
└── uv.lock
The expected result is a collection of compiled binaries in the build/manage.dist folder.
I installed only Django 5.1.2 and Nuitka itself 2.4.8, which are only compatible with Python 3.12 for now. Then I ran the build, asking to include Django in the compilation process:
uv run python -m nuitka --standalone --include-package=django --output-dir=build manage.py
But I’m getting this error:
FATAL: implicit-imports: Error, expression 'get_parameter("settings-module", None)' for module 'django.core.management' did not evaluate to 'str' result.
To me, it looks like the compiler is unable to infer the type of some code in Django itself.
I know that this is not the orthodox approach for deploying Django apps, and that Cython is a thing, but this is more a matter of experimentation for me. I’m not using this approach in any production environment. Has anyone had any success in using Nuitka with the Django? Are there any recommended resources or materials on this topic?
Thanks!