Skip to main content

Python-first server-rendered templating runtime

Project description

Djule

Djule is a Python-first templating/runtime for server-rendered UI.

It currently includes:

  • a lexer and parser for .djule files
  • a renderer with import resolution and render-plan caching
  • a VS Code extension for syntax, diagnostics, and completions
  • an optional Django integration layer

Djule is licensed under Apache License 2.0.

Installation

Install the package locally:

python3 -m pip install .

Install from PyPI:

python3 -m pip install djule

Install with Django helpers:

python3 -m pip install '.[django]'

For local development:

python3 -m pip install -e '.[dev]'

Local Development

Install the editable dev environment:

make install-dev

Run the Python test suite:

make test

Run the parser CLI:

python3 -m djule.parser check-json tests/fixtures/01_simple_page.djule
python3 -m djule.parser render tests/fixtures/01_simple_page.djule --props '{"title":"Hello Djule"}'
djule render tests/fixtures/01_simple_page.djule --props '{"title":"Hello Djule"}'

Useful maintenance commands:

make check
make build
make clean
make clean-cache

Django Integration

Djule ships a small Django-facing API in src/djule/integrations/django.py.

Example:

from djule.integrations.django import render_djule_response


def dashboard_view(request):
    return render_djule_response(
        request,
        "examples/08_django_request_props.djule",
        props={
            "user": request.user,
            "notifications": [],
            "team": {"name": "Core"},
        },
)

Set DJULE_IMPORT_ROOTS in Django settings if you want explicit import roots. Otherwise Djule falls back to BASE_DIR.

Djule can also consume Django-style global context processors. It reads the standard Django template engine TEMPLATES[..].OPTIONS.context_processors list, and you can append Djule-only ones with DJULE_CONTEXT_PROCESSORS.

Example:

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_DIR / "templates"],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.request",
                "app.utils.context_processors.debug_variable",
                "app.utils.context_processors.vite_host",
            ],
        },
    },
]

DJULE_CONTEXT_PROCESSORS = [
    "app.utils.context_processors.extra_djule_globals",
]

Those values are merged into every render_djule(...) / render_djule_response(...) call before explicit props, so explicit props still override globals when needed.

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

djule-1.0.2.tar.gz (61.1 kB view details)

Uploaded Source

Built Distribution

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

djule-1.0.2-py3-none-any.whl (58.8 kB view details)

Uploaded Python 3

File details

Details for the file djule-1.0.2.tar.gz.

File metadata

  • Download URL: djule-1.0.2.tar.gz
  • Upload date:
  • Size: 61.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for djule-1.0.2.tar.gz
Algorithm Hash digest
SHA256 85f61104ea09760e9863784847cae3c59de858b216780e2c51406c8b374df347
MD5 a1f31fc4d38d8950f6041ba13fa5aa9b
BLAKE2b-256 fb060f3b43f5c9023e45b932dea087e8b14ed44f0b2bd0e3e06d01d9f6bf6126

See more details on using hashes here.

File details

Details for the file djule-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: djule-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 58.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for djule-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c873b9895a8e2f4a64dfbddae5e38cfbb1df1c48948e12992231b3e44f598cc8
MD5 435d1f4c629515a3af5c47e5347a798f
BLAKE2b-256 b6c2a91bdca5bb68a749372e26d28027e7178642768a9cf70ad0579628bcffa9

See more details on using hashes here.

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