Skip to main content

stapel-chat

CI coverage pypi downloads python license llms.txt

Conversations and messaging over WebSocket: direct (1:1, idempotent by participant pair), group and support threads on one model; realtime send/edit/delete with a monotonic per-conversation seq for order and a separate revision sequence for resume, so an edit or a deletion made while a client was offline reaches it on reconnect; deletion is a tombstone the id keeps arriving under, so client caches and offline databases learn what to purge; attachments carry the render metadata a bubble needs on first paint (aspect, byte size, a 16px base64 thumbnail, voice duration and waveform, document mime and extension) behind an OPEN type registry; typing and activity states, read and delivery receipts as ephemeral signals; a live inbox stream so the conversation list does not poll either; anchor-paginated history and lists; leaving a thread, which hides it for the person who left and takes nothing away from anybody else (their messages, the other party's copy and their own history by id all stay), un-hides on the next message written there, and is undoable (the left threads are listed by ?left=true and put back by POST /conversations/{id}/rejoin, which clears the departure and nothing else); and a support layer (queue, first-come assignment, open/pending/resolved with reopen).

Part of the Stapel framework — composable Django apps that deploy as a monolith or as microservices without changing module code.

Install

pip install stapel-chat

At a glance

Fact Value
Version 0.11.0
Python >=3.11 (3.11, 3.12, 3.13, 3.14)
HTTP operations 16
Config axes 15
Usage surface 39
Extension points 9
Error codes 65
Fleet dependencies stapel-auth (optional) · stapel-cdn (optional) · stapel-core · stapel-realtime

Documentation

OpenAPI · capabilities.json · llms.txt (for agents)

One model backs three kinds of thread: direct (1:1, idempotent by participant pair), group, and support (a customer↔operator thread with a queue and assignment lifecycle).

Realtime is the module, not a mode of it. Messages are sent and received over a WebSocket; REST serves history, hydration and the support lifecycle. A deployment that cannot serve the socket fails manage.py check rather than degrading into a product that refreshes on a timer — because a polling fallback a product can end up in silently is exactly how "websockets are done" became a false claim once already.

Quick start

INSTALLED_APPS = [
    # ...
    "stapel_core.django.apps.CommonDjangoConfig",
    "stapel_core.django.users",
    "rest_framework",
    "stapel_realtime",
    "stapel_chat",
]

CHANNEL_LAYERS = {"default": {
    "BACKEND": "channels_redis.core.RedisChannelLayer",
    "CONFIG": {"hosts": [REDIS_URL]},
}}
STAPEL_COMM = {"SIGNAL_TRANSPORT": "channels"}
STAPEL_REALTIME = {"ALLOWED_ORIGINS": ["https://app.example.com"]}  # with the port

# urls.py
urlpatterns = [path("chat/", include("stapel_chat.urls"))]
# asgi.py — the whole file
from django.core.asgi import get_asgi_application
from stapel_realtime.asgi import build_websocket_application

application = build_websocket_application(http_application=get_asgi_application())
pip install 'stapel-chat[realtime]'

What you get

  • Two sockets. ws/chat/<conversation_id> is the resumable journal — hello{last_seq} → replay → live, with send / edit / delete / read / delivered / activity frames going through the same service layer the REST views call. ws/chat/inbox keeps the conversation list live, because a list with no socket refreshes on a timer forever however live the open thread is.
  • Two sequences. seq is a message's immutable place in the thread — the sort key and the history anchor. rev_seq is its place in the revision journal, re-allocated on every edit and delete, and it is what realtime replay is anchored on: an edit made while a client was offline arrives in the catch-up. A client upserts by id, sorts by seq, and remembers rev_seq as its cursor.
  • Edit and delete. An edit sets edited / edited_at. A delete leaves a tombstone: the id keeps being delivered with body: "", attachments: [] and deleted: true, so a client cache learns which id to purge. An id that stops arriving is an id nobody can purge. Retention is permanent.
  • Attachments that render on first paint — aspect, byte size and a ~16px base64 thumbnail for images and GIFs; duration and a waveform image for audio; mime and extension for documents; poster and duration for video. The type set is an open registry — stickers are a settings line — and the metadata comes from stapel-cdn by comm, once, at send time.
  • Receipts and activity. Separate delivery and read markers, both durable and both fanned out live; typing / recording_audio / sending_video / uploading_file as ephemeral signals with a TTL, from another open registry.
  • Conversations — POST /chat/api/v1/conversations (direct / group / support); direct is get-or-create by participant pair. GET lists yours (anchor-paginated) with unread_count, and every row carries its own stream_key and socket_path. ?search= finds a thread by the three things its row draws — the counterpart's display name, the subject card's title and the last line — and ?unread=true narrows to the rows with a badge; both filter before the page is taken, so the anchor keeps its meaning.
  • Leaving — DELETE /chat/api/v1/conversations/{id} is the caller leaving, not a delete: the thread drops off their list, counts and search, their live subscription is revoked and a chat.participant.left system line records it — while every message, every other participant and their own history by id stay exactly as they were. A new message from the other side brings the thread back. Staff erasure is not on this surface: user data has one deletion path, user.deleted.
  • Messages — GET/POST /chat/api/v1/conversations/{id}/messages, PATCH/DELETE .../messages/{message_id}. History is anchored on seq, newest-first, both directions.
  • Support — GET /chat/api/v1/support/queue, POST .../support/conversations/{id}/{assign,resolve,reopen}.

Configuration (STAPEL_CHAT)

Key Default Meaning
CHAT_KINDS ["direct","group","support"] Enabled thread kinds
ATTACHMENTS True Allow attachments on messages
MAX_BODY_LENGTH 4000 Hard cap on a text body
ATTACHMENT_TYPES {} Open registry, merged over image/gif/video/audio/file — the same names stapel-cdn uses
ACTIVITY_STATES {} Open registry, merged over typing/recording_audio/…
ATTACHMENT_METADATA "cdn" Ask cdn.describe, or trust the client
MAX_ATTACHMENTS 10 Attachments per message
MAX_PREVIEW_B64_BYTES 8192 Ceiling on an inline data: preview
EDIT_WINDOW_S 0 Seconds a message stays editable (0 = forever)
SCOPE_PROVIDER stapel_chat.scope.DefaultScopeProvider Resolve/enforce the opaque scope_key

There is no key that turns realtime off. See MODULE.md for the full wire contract, the extension seams and the anti-patterns.

License

MIT — see LICENSE.


This page is assembled by stapel-readme from docs/readme.md plus the contract artifacts in docs/. Edit the prose in docs/readme.md; the badges, facts and links above and below it are generated — do not hand-edit README.md.

Metadata

Release files for stapel-chat 0.11.0

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

Source distribution (sdist)

Source distribution for stapel-chat 0.11.0
File Size Uploaded Provenance
stapel_chat-0.11.0.tar.gz 247.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for stapel-chat 0.11.0
File Interpreter ABI Platform
stapel_chat-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 433.8 kB

Release files / stapel_chat-0.11.0.tar.gz

Download URL stapel_chat-0.11.0.tar.gz
Size 247.7 kB
Tags Source
SHA-256 checksum
How to use checksums
70cff88a43b4c398e3f9008c55804e439b0445b428441d3ce432d2b8ed01d9b8
BLAKE2b-256 checksum
How to use checksums
b6cdb4e1caa4dc5cf3f9871038490431d84d388ef76a7c2d4691306e54d131d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / stapel_chat-0.11.0-py3-none-any.whl

Download URL stapel_chat-0.11.0-py3-none-any.whl
Size 186.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bdc4c186bc4ea930b2ac942be0bbe02f355872077c22b8e0b15b51465ac3310
BLAKE2b-256 checksum
How to use checksums
0e601eaf9ee34ab950b060f46c24074a30bbc6313236a549efe7c16a29a8524f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for stapel-chat 0.11.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for stapel_chat-0.11.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files Full 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