Skip to main content

djhtmx

CI

Interactive UI Components for Django using htmx

Agent Skills

This repository is the home of three skills for coding agents: djhtmx-setup for wiring djhtmx into a project and its settings, djhtmx-components for writing components, and djhtmx-testing for testing them. Install them in your project with dotagents, so the guidance travels with the library instead of drifting in each consumer:

[[skills]]
name = "djhtmx-setup"
source = "edelvalle/djhtmx"

[[skills]]
name = "djhtmx-components"
source = "edelvalle/djhtmx"

[[skills]]
name = "djhtmx-testing"
source = "edelvalle/djhtmx"

They describe djhtmx alone; the conventions of your own project belong in a skill of your own that points at these.

Install

uv add djhtmx

or

pip install djhtmx

Configuration

djhtmx needs Redis running for component state, and five things wired:

INSTALLED_APPS = [
    ...,
    "djhtmx",
]

# Last, so its exception hook runs first.
MIDDLEWARE = [
    ...,
    "djhtmx.middleware",
]

TEMPLATES = [{
    ...,
    "OPTIONS": {"context_processors": [
        ...,
        "django.template.context_processors.request",
        "djhtmx.context.component_repo",
    ]},
}]
# urls.py -- the prefix is yours
urlpatterns = [
    ...,
    path("_htmx/", include("djhtmx.urls")),
]
{# the base template #}
{% load htmx %}
<!doctype html>
<html>
  <head>
    {% htmx-headers %}
  </head>
</html>

DJHTMX_REDIS_URL defaults to redis://localhost/0. Every setting, what running server-sent events asks of the deployment, and what to look at when a component renders but does not respond are in the djhtmx-setup skill.

Getting started

djhtmx is a framework for building components, not a component library: it ships no components, templates or styles, and is unopinionated about all three.

Components are discovered in the htmx module -- or the htmx package -- of each installed app.

from djhtmx.component import HtmxComponent


class Counter(HtmxComponent):
    _template_name = "Counter.html"
    counter: int = 0

    def inc(self, amount: int = 1):
        self.counter += amount

The inc event handler is ready to be called from the front-end to respond to an event.

The counter.html would be:

{% load htmx %}
<div {% hx-tag %}>
  {{ counter }}
  <button {% on "inc" %}>+</button>
  <button {% on "inc" amount=2 %}>+2</button>
</div>

When the event is dispatched to the back-end the component state is reconstructed, the event handler called and then the full component is rendered back to the front-end.

Now use the component in any of your html templates, by passing attributes that are part of the component state:

{% load htmx %}

Counters: <br />
{% htmx "Counter" %} Counter with init value 3:<br />
{% htmx "Counter" counter=3 %}

The djhtmx-components skill covers the rest -- state and model fields, handlers, events, model subscriptions, query-string state, rendering, SSE -- and djhtmx-testing covers testing components with djhtmx.testing.Htmx.

Metadata

Release files for djhtmx 1.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djhtmx 1.6.1
File Size Uploaded Provenance Actions
djhtmx-1.6.1.tar.gz 258.3 kB Without provenance Details for djhtmx-1.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for djhtmx 1.6.1
File Interpreter ABI Platform Actions
djhtmx-1.6.1-py3-none-any.whl Python 3 none any Details for djhtmx-1.6.1-py3-none-any.whl

Total release size: 525.4 kB

Release files / djhtmx-1.6.1.tar.gz

Download URL djhtmx-1.6.1.tar.gz
Size 258.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a5bf489d5c6d61cda69a9271d1ec9b6ced4a198d7d90a477ecab34c26c044606
BLAKE2b-256 checksum
How to use checksums
d4e3e147987daf427a7e5380a260107be942137766137b69c46dce3c76050275
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Omarchy","version":"4.5.0","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / djhtmx-1.6.1-py3-none-any.whl

Download URL djhtmx-1.6.1-py3-none-any.whl
Size 267.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50a0a6bee4e8dea59549719031d39746957ed26359b8ac780a8b83342e7bb3b8
BLAKE2b-256 checksum
How to use checksums
2cf00dd4bf76cd5c50c602230195c491aeeb275b2ee1f247a9d8f1eae27de68d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Omarchy","version":"4.5.0","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for djhtmx 1.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.6.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page