Skip to content

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.

500
console Console | None

An optional rich :class:~rich.console.Console to print to. If None, the current active console (as returned by :func:rich.get_console) is used.

None
compact_metadata bool

If True, render metadata entries as a single dimmed inline line (key: value · key: value) instead of one per line. Useful when scanning many documents in a row and one metadata line per key would take up too much vertical space. Defaults to False.

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 langchain_core.documents.Document objects. Consumed exactly once; if a generator/iterator is passed in, it will be exhausted by this call.

required
max_length int

Maximum number of content characters to display per document before truncating. Defaults to 500.

500
console Console | None

An optional rich :class:~rich.console.Console to print to. If None, the current active console (as returned by :func:rich.get_console) is used.

None
compact_metadata bool

If True, render each document's metadata entries as a single dimmed inline line instead of one per line. Defaults to False.

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:~rich.console.Console to print to. If None, the current active console (as returned by :func:rich.get_console) is used.

None