Display
docculus.display ¶
Contain utilities to print LangChain documents to the terminal.
docculus.display.print_document ¶
print_document(
doc: Document,
max_length: int = 500,
console: Console | None = None,
compact_metadata: bool = False,
) -> None
Pretty-print a LangChain document to the terminal using rich.
Renders the document as a bordered panel titled with its id,
containing two nested panels: a content panel with the
document's page_content (truncated on a word boundary and
annotated with the omitted character count if it exceeds
max_length, with the total/truncated character count shown in
its subtitle), and, if metadata is non-empty, a metadata
panel listing entries sorted by key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The document to display. |
required |
max_length
|
int
|
Maximum number of content characters to display
before truncating. Defaults to |
500
|
console
|
Console | None
|
An optional rich :class: |
None
|
compact_metadata
|
bool
|
If |
False
|
docculus.display.print_documents ¶
print_documents(
documents: Iterable[Document],
max_length: int = 500,
console: Console | None = None,
compact_metadata: bool = False,
) -> None
Pretty-print an iterable of LangChain documents to the terminal using rich.
Each document is rendered with :func:print_document, one bordered
panel per document, printed in order to the same console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
Iterable[Document]
|
A list, generator, or other iterable of
|
required |
max_length
|
int
|
Maximum number of content characters to display
per document before truncating. Defaults to |
500
|
console
|
Console | None
|
An optional rich :class: |
None
|
compact_metadata
|
bool
|
If |
False
|
docculus.display.print_documents_metadata ¶
print_documents_metadata(
documents: Sequence[Document],
separator: str = "•",
console: Console | None = None,
) -> None
Pretty-print metadata for a sequence of documents, one line each.
Renders a bordered panel containing one line per document: the
document's id (if present) followed by its metadata entries,
sorted by key, rendered inline as key: value {separator} key: value.
Documents with no metadata show a dimmed placeholder instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
Sequence[Document]
|
The documents whose metadata to display. |
required |
separator
|
str
|
The string used to separate metadata entries on
each line. Defaults to |
'•'
|
console
|
Console | None
|
An optional rich :class: |
None
|