Skip to main content

Cython-accelerated Django template engine for benchmarking template rendering speedup (3-14x faster)

Project description

django-templates-cythonized

Cython-accelerated drop-in replacement for Django's template engine. 3-14x faster depending on template complexity.

This is a benchmarking tool to evaluate what a Cython-level template speedup would bring to your project. Not meant for production use. Feel free to try though — if you run into issues, open an issue and I'll see if I can help.

Benchmarks

Measured on an AMD Ryzen 9 5950X, Python 3.14t (free-threaded).

Benchmark Cythonized Stock Django Speedup
1000-book table (for/if/cycle/filters) 2.4 ms 33.7 ms 14x
50-book table + per-book forms (4 widgets/row) 6.1 ms 21.3 ms 3.5x

Usage

TEMPLATES = [
    {
        "BACKEND": "django_templates_cythonized.backend.CythonizedTemplates",
        "DIRS": [BASE_DIR / "templates"],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ],
        },
    }
]

For form-heavy templates, also set the form renderer:

FORM_RENDERER = "django_templates_cythonized.backend.CythonizedFormRenderer"

Development

git clone https://github.com/oliverhaas/django-templates-cythonized.git
cd django-templates-cythonized
uv sync --group dev
uv pip install -e .          # Build Cython extensions
uv run pytest                # Run tests
uv run pytest tests/benchmarks/ -v --no-cov -p no:codspeed  # Run benchmarks

Re-run uv pip install -e . after modifying .py files to recompile.

Attribution & License

Contains modified copies of Django's template source code. BSD-3-Clause (matching Django). Benchmark structure inspired by django-rusty-templates.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_templates_cythonized-0.1.0.tar.gz (2.4 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

django_templates_cythonized-0.1.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (11.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

django_templates_cythonized-0.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (11.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

django_templates_cythonized-0.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (11.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file django_templates_cythonized-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django_templates_cythonized-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9f2b2e985edc17296644c2550294d95fad0be573c21a227547b4b143cf1d3b8b
MD5 341be2835b9b8ac46174e4d0b30b469b
BLAKE2b-256 ed25abed71349f018e521ab1161bcefa97fcbd88a8dab3e537a02b40c226fcf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_templates_cythonized-0.1.0.tar.gz:

Publisher: publish.yml on oliverhaas/django-templates-cythonized

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_templates_cythonized-0.1.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for django_templates_cythonized-0.1.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 be97d41b5a5a040697924a19661812ed0ef437e0f219cde2d3394a2494ef2a0f
MD5 06cf6182f2580eca84d9361a3f2cd40b
BLAKE2b-256 69fa908f3b7e73b12123b2ed4084cc4ff4773e3ef418da8cac54910b0b1b5eb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_templates_cythonized-0.1.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on oliverhaas/django-templates-cythonized

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_templates_cythonized-0.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for django_templates_cythonized-0.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 20c03aba534afaff36b1b76ffc68d9c79e04f2b9f60b5de52a02208b994bfb8c
MD5 8fbacf774517b7fafd95fca071f88630
BLAKE2b-256 248980a74477990943d3bb31fb8fe9afecd3662ca97bef0333805828507f487e

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_templates_cythonized-0.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on oliverhaas/django-templates-cythonized

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_templates_cythonized-0.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for django_templates_cythonized-0.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0472232f17651be3bffaaf14be946e3255596ca3973cc8c9e1cc4f7810182e4f
MD5 3e63d820aa7da461b3c1d03115b57239
BLAKE2b-256 01d6d78b33d21eac18b475df5b17823d5cd91f6e0e5a1b558594a8a574e9d8f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_templates_cythonized-0.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on oliverhaas/django-templates-cythonized

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page