litestar-feedback
Litestar plugins for an in-app customer support inbox and session replay. SupportPlugin
stores customer issues with a reply thread and an operator inbox. ReplayPlugin stores rrweb
recordings, plays them back from a moment, and builds click heatmaps. Each plugin works alone.
Install
uv add litestar-feedback
For replay, install the replay extra (empty today, kept for future dependencies):
uv add "litestar-feedback[replay]"
Requires Python 3.12+, Litestar 2.23+ and SQLAlchemy 2.0 async. No Advanced Alchemy.
Support inbox
SupportPlugin follows ISSUES-STANDARD.md: tables issues, issue_events,
issue_attachments, and routes under /issues and /admin/issues.
- Statuses
open,waiting_customer,resolved,closed. A move not allowed is 409. closedis final. A customer comment on a closed issue opens a new issue whosefollows_idis the closed one. The answer is the new issue's first event, so itsissue_idis the new issue. An operator comment on a closed issue is 409 withcode: "issue_closed".- A customer comment reopens a
waiting_customerorresolvedissue. - A
waiting_customerorresolvedissue moves on after 14 days with no activity. - Internal notes (
internal: true) never reach customer routes, and never make a customer'slast_seen_event_idstale. - The operator sets
kindafter triage. The change is written as an internal note. - A public operator reply calls your mailer after the transaction commits. A rolled back reply
sends no mail. The event records
notified_ator the reason it was skipped (pendinguntil the mailer answers). - Customer messages are rate limited per actor (20 per hour by default). Over the limit is 429.
- Images are uploaded first, then attached by id. No store configured means 503.
- Every error body has
status_code,detailand a stablecode, for exampleissue_closedorstale_thread.
Wire it
- Write a function that turns a request into a
Caller. - Write a function that opens a session for that caller.
- Add the plugin.
from contextlib import asynccontextmanager
from litestar import Litestar, Request
from litestar.exceptions import NotAuthorizedException
from sqlalchemy import text
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from litestar_feedback.support import Caller, SupportAdapter, SupportConfig, SupportPlugin
engine = create_async_engine("postgresql+psycopg://app@db/app")
sessions = async_sessionmaker(engine, expire_on_commit=False)
async def caller(request: Request) -> Caller:
user = request.user # however your app signs users in
if user is None:
raise NotAuthorizedException()
return Caller(
scope_id=str(user.tenant_id),
user_id=str(user.id),
actor=user.email,
is_operator=user.is_staff,
)
@asynccontextmanager
async def session(caller: Caller):
async with sessions.begin() as s:
if not caller.is_operator:
await s.execute(text("SELECT set_config('app.tenant_id', :t, true)"), {"t": caller.scope_id})
yield s
app = Litestar(
plugins=[
SupportPlugin(
adapter=SupportAdapter(caller=caller, session=session),
config=SupportConfig(path="/v1"),
)
]
)
A runnable version is examples/support_app.py.
Adapter
| Field | Type | What it does |
|---|---|---|
caller |
async (Request) -> Caller |
Who is calling. Raise NotAuthorizedException for nobody. |
session |
(Caller) -> async context manager of AsyncSession |
One transaction per request. Commit on exit, roll back on error. Set row-level security here. |
mailer |
Mailer or None |
async send_reply(ReplyNotice) -> bool. False means the customer has no address. |
storage |
AttachmentStore or None |
async put, delete, presign_get. None makes uploads return 503. |
Caller has scope_id: str, user_id: str | None, actor: str, is_operator: bool. The ids
are strings so UUID and integer keys fit the same columns.
SupportConfig holds path, the two timers, the rate limit, upload limits, system_actor,
list_limit and clock. Defaults follow the standard.
Routes
| Method | Path | Who |
|---|---|---|
| POST | /issues |
customer |
| GET | /issues |
customer |
| GET | /issues/{id} |
customer |
| POST | /issues/{id}/comments |
customer |
| POST | /issues/{id}/resolve |
customer |
| POST | /issue-attachments |
customer |
| GET | /admin/issues |
operator |
| GET | /admin/issues/{id} |
operator |
| POST | /admin/issues/{id}/comments |
operator |
| POST | /admin/issues/{id}/status |
operator |
| POST | /admin/issues/{id}/kind |
operator |
Tables
Call the helper from an Alembic migration:
from alembic import op
from litestar_feedback.support.migration import create_tables, drop_tables
def upgrade() -> None:
create_tables(op)
def downgrade() -> None:
drop_tables(op)
Then add your row-level security policies on scope_id in the same migration.
Jobs to schedule
The plugin applies timers when an issue is read. These SupportService methods are for a
scheduler:
sweep_timers(): apply due timers to every issue.reap_staged(): delete uploads no message claimed within 24 hours.forget_user(user_id): delete a user's screenshots and unlink their issues.import_issue(...): insert a historical issue withnotify_skipped_reason='seeded'.
Contract test
The package ships the standard's black-box contract as a pytest plugin.
- Define five fixtures in
tests/conftest.py:client,customer_headers,operator_headers,other_tenant_headers,seeded_issue. - Add
tests/test_support_contract.py:
from litestar_feedback.support.contract import SupportContract
class TestSupportContract(SupportContract):
pass
Set the rate limit high in the app under test. Every contract test posts as one customer.
Session replay
ReplayPlugin stores rrweb events in chunks, one recording per page load. The browser recorder
is not part of this package: run rrweb in the browser and post its events to the ingest route.
- A session id belongs to the first caller that writes to it. Another scope or user gets 409.
- A repeated
seqis ignored ("action": "exists"), so the browser can retry safely. - Caps: 1 MiB per chunk, 5,000 events per chunk, 20 MiB per session. Over a cap is 413.
- Playback with
offset_msloads from the last full snapshot before that moment. - Clicks are kept per page path and viewport width bucket, for heatmaps.
prunedeletes old recordings.delete_userdeletes a user's recordings.- Recordings in the adapter's
protected_sessionssurvive both.
Ingest API
POST /replay/ingest, signed in as the user being recorded:
{
"session_id": "7c0e4b7e-2f1a-4c55-9a51-0d6c1f3f6a10",
"seq": 0,
"events": [{"type": 4, "timestamp": 1767225600000, "data": {"href": "https://app.example/orders", "width": 1280, "height": 800}}],
"entry_url": "https://app.example/orders",
"viewport_w": 1280,
"viewport_h": 800
}
- Pick a new
session_id(UUID) on every page load. - Buffer rrweb events. Send them every 10 seconds or 400 events, with
seqcounting from 0. - On 5xx, retry the same body. On 4xx, drop the batch.
- To link a support issue, put
replay_session_idandreplay_offset_ms(milliseconds since the first event) in the issue'scontext.
The answer is {"action": "appended" | "exists", "event_count": n}. 403 means no consent.
Wire it
from litestar_feedback.replay import ReplayAdapter, ReplayConfig, ReplayPlugin
from litestar_feedback.support import referenced_replay_sessions
replay = ReplayPlugin(
adapter=ReplayAdapter(
caller=caller, # same functions as for SupportPlugin
session=session,
retention_days=30,
consent=has_analytics_consent, # async (Caller, Request) -> bool
protected_sessions=referenced_replay_sessions, # only if SupportPlugin is installed
),
config=ReplayConfig(path="/v1"),
)
app = Litestar(plugins=[replay])
Run the jobs from your scheduler. system_caller is an operator Caller:
result = await replay.prune(system_caller) # PruneResult(candidates, deleted, protected)
deleted = await replay.delete_user(system_caller, str(user.id))
A runnable version is examples/replay_app.py.
Adapter
| Field | Type | What it does |
|---|---|---|
caller |
async (Request) -> Caller |
Who is calling. Operators can play back and see heatmaps. |
session |
(Caller) -> async context manager of AsyncSession |
One transaction per request. |
chunk_store |
ChunkStore or None |
async put, get, delete. None stores chunks in replay_chunks.events. |
retention_days |
int |
prune deletes recordings whose last event is older. 0 keeps all. |
consent |
async (Caller, Request) -> bool or None |
False answers 403 and stores nothing. |
protected_sessions |
async (AsyncSession) -> set[UUID] or None |
Recordings that prune and user deletion keep. |
ReplayConfig holds path, the three caps, viewport_buckets (default 0, 640, 1024, 1440),
the heatmap grid size, list_limit and clock.
Routes
| Method | Path | Who |
|---|---|---|
| POST | /replay/ingest |
the recorded user |
| GET | /admin/replay/sessions |
operator |
| GET | /admin/replay/sessions/{id}?offset_ms= |
operator |
| DELETE | /admin/replay/sessions/{id} |
operator |
| GET | /admin/replay/heatmaps |
operator |
| GET | /admin/replay/heatmap?path=&viewport_bucket= |
operator |
A heatmap is a grid: 20 columns across the viewport width, rows of 50 pixels. Click y is in
viewport pixels, not page pixels: rrweb reports clicks relative to the viewport.
Tables
replay_sessions, replay_chunks, replay_clicks. Create them with
litestar_feedback.replay.migration.create_tables(op) in an Alembic migration.
Links
Metadata
Release files for litestar-feedback 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| litestar_feedback-0.2.1.tar.gz | 48.8 kB | Without provenance | Details for litestar_feedback-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| litestar_feedback-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for litestar_feedback-0.2.1-py3-none-any.whl |
Total release size: 98.3 kB
Release files / litestar_feedback-0.2.1.tar.gz
| Download URL | litestar_feedback-0.2.1.tar.gz |
|---|---|
| Size | 48.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cafb59817c081454ad198cba0bc7c1b18484875b2ee46f95659153308b3c8618
|
|
BLAKE2b-256 checksum How to use checksums |
82c37726f6d13d72fcf80e79b77324adcc1f3ef0ead33ff395841c7668a45f40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / litestar_feedback-0.2.1-py3-none-any.whl
| Download URL | litestar_feedback-0.2.1-py3-none-any.whl |
|---|---|
| Size | 49.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0bd346c7fc2ba36a16f0c93b4fdc17530561d016b28105bf6f1092b01e056dbd
|
|
BLAKE2b-256 checksum How to use checksums |
889a850c0429a4fd53d52e2abba7ae5c3b005d9c3f3f10f7d04576ca377b5625
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for litestar-feedback 0.2.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.