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.10.1
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.10.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 stapel-chat 0.10.1
File Size Uploaded
stapel_chat-0.10.1.tar.gz 243.2 kB Details

Built distribution (wheel)

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

Total release size: 426.6 kB

Release files / stapel_chat-0.10.1.tar.gz

Download URL stapel_chat-0.10.1.tar.gz
Size 243.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1ec661ea02ebb28a0e77958d709592d7037c24ef6e73931d28865e9acb7ef05b
BLAKE2b-256 checksum
How to use checksums
8a9188d60ce4a6e822fe5d1011d902a79b4271e0c0be7316de6e8e4883833147
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 18, 2026.

Transparency log

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

Download URL stapel_chat-0.10.1-py3-none-any.whl
Size 183.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65bd2a1acf89e952986f13950255769efedfd56e1f9cba1788a635c2017ac01f
BLAKE2b-256 checksum
How to use checksums
3caffd508e51af7581df11d36945a1e8d708fa21342853e0aad092a532f7d6c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.10.1 This release

2 release files

0.10.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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