Structured Display
KeyValueList, RecordDetail, CodeBlock, and JsonViewer are small data/dev-app primitives for admin panels, AI tools, and internal dashboards.
Quick Start
from faststrap import CodeBlock, JsonViewer, KeyValueList, RecordDetail
KeyValueList({
"Status": "Ready",
"Owner": "Ops",
})
RecordDetail(
{"ID": 42, "State": "queued"},
title="Training Job",
subtitle="Submitted 2 minutes ago",
)
CodeBlock("print('hello')", language="python", filename="demo.py")
JsonViewer({"accuracy": 0.94, "loss": 0.12}, title="Metrics")
Usage Scenarios
Admin Record Detail
RecordDetail(
{
"Name": "Acme Corp",
"Plan": "Enterprise",
"Seats": "25",
"Status": "Active",
},
title="Acme Corp",
subtitle="Customer since 2023",
actions=[
Button("Edit", variant="primary", href=f"/customers/{id}/edit"),
Button("Deactivate", variant="danger"),
],
)
API Response Viewer
Code Snippet with Copy
CodeBlock(
"from faststrap import Button\nButton('Click me')",
language="python",
filename="main.py",
copy=True,
)
Key-Value List in a Card
Card(
Card.Header("System Status"),
Card.Body(
KeyValueList({
"CPU": "42%",
"Memory": "6.2 GB",
"Disk": "120 GB free",
}, striped=True),
),
)
Notes
CodeBlockdoes not ship a syntax highlighter in core. It emitslanguage-*classes so an optional highlighter can enhance it later.JsonViewer(title=...)uses a native<details>element; omittitlefor an always-visible block.- These components are core-safe: no JavaScript and no extra dependencies.
Accessibility
CodeBlockuses semantic<pre>and<code>markup.JsonVieweruses native<details>/<summary>for expand/collapse.- Ensure
CodeBlocktext meets contrast requirements for your theme.
Parameters
| Component | Key Parameters | Notes |
|---|---|---|
KeyValueList |
items, striped, compact |
Accepts a dict, tuple list, or label/value mappings. |
RecordDetail |
items, title, subtitle, actions |
Card-style detail view around KeyValueList. |
CodeBlock |
code, language, filename, copy, wrap |
Escapes code content by default. copy=True shows a visual badge only. |
JsonViewer |
data, title, expanded |
Pretty-prints JSON-like data using json.dumps(..., default=str). |
API Reference
faststrap.components.display.structured.KeyValueList(items, *, striped=False, compact=False, **kwargs)
Render label/value metadata rows.
Source code in src/faststrap/components/display/structured.py
faststrap.components.display.structured.RecordDetail(items, *, title=None, subtitle=None, actions=None, **kwargs)
Render a card-style detail view for one record.
Source code in src/faststrap/components/display/structured.py
faststrap.components.display.structured.CodeBlock(code, *, language=None, filename=None, copy=False, wrap=False, **kwargs)
Render escaped source code in a Bootstrap-styled block.
Source code in src/faststrap/components/display/structured.py
faststrap.components.display.structured.JsonViewer(data, *, title=None, expanded=True, **kwargs)
Render JSON-like data as an escaped, readable details block.