Skip to main content

lica-tables

Introduction

lica-tables is a lightweight utility for displaying tabular data in day-to-day LICA Python command-line applications. It defines a minimal display interface based on typing.Protocol and provides an adapter that renders tables in the standard output using tabulate.

The package supports plain text output, optional table titles, several tabulate formats, and optional pagination for long tables. Application code depends only on the DisplayService protocol, while the concrete rendering behaviour is supplied by an adapter.

Installation

Install lica-tables directly from the lica-ng Git repository:

pip install lica-tables

or add it to your pyproject.toml:

[project]
dependencies = [
    "lica-tables",
]

The included StdoutDisplay adapter requires tabulate:

[project]
dependencies = [
    "lica-tables",
    "tabulate",
]

Interfaces

lica-tables defines its display contracts using typing.Protocol. Adapters do not need to inherit from these protocols explicitly; they only need to provide the required methods.

Tabular data

from dataclasses import Field
from typing import Any, ClassVar, Protocol, TypeVar
from collections.abc import Mapping, Sequence


class DataclassLike(Protocol):
    __dataclass_fields__: ClassVar[dict[str, Field[Any]]]


DataClass = TypeVar("DataClass", bound=DataclassLike)

TableRow = DataClass | Mapping[str, Any] | Sequence[Any]
TabularData = Sequence[TableRow]

A table row may therefore be:

  • A dataclass instance.
  • A mapping, typically with string keys.
  • Any sequence of values.

Display service

from collections.abc import Sequence
from typing import Protocol

from lica_tables import TabularData


class DisplayService(Protocol):
    def show(self, text: str) -> None: ...

    def show_tabular(
        self,
        table: Sequence[TabularData],
        keys: Sequence[str] | None = None,
    ) -> None: ...

Adapters

Adapter Module Extra Description
StdoutDisplay lica_tables.adapters.tabulate tabulate Renders tabular data to standard output using tabulate.tabulate.

The adapter is created with an optional tabulate table format and an optional page size:

StdoutDisplay(table_fmt: str = "simple", page_size: int | None = None) -> None

Supported table formats

StdoutDisplay accepts the following tabulate formats:

  • simple
  • grid
  • fancy_grid
  • outline
  • presto
  • plain
  • psql

For formats that draw a complete table frame, an optional title is rendered inside the top border. For simpler formats, the title is centred above the table.

Pagination

If page_size is set, show_tabular() splits the input rows into fixed-size pages. After each page, it waits for the user to press Enter before displaying the next one. Ctrl-C aborts the display.

Usage example

from dataclasses import dataclass

from lica_tables import DisplayService
from lica_tables.adapters.tabulate import StdoutDisplay


@dataclass
class Star:
    name: str
    magnitude: float
    spectral_type: str


stars = [
    Star("Sirius", -1.46, "A1V"),
    Star("Vega", 0.03, "A0V"),
    Star("Betelgeuse", 0.50, "M1-2Ia-Iab"),
]

display: DisplayService = StdoutDisplay(table_fmt="fancy_grid")

display.show_tabular(
    stars,
    keys=["Name", "Magnitude", "Spectral type"],
    title="Bright stars",
)

Example output:

╔══════════════════════════════════════════════╗
║                 Bright stars                 ║
╠═════════════╦═══════════════╦════════════════╣
║ Name        ║   Magnitude   ║ Spectral type  ║
╠═════════════╬═══════════════╬════════════════╣
║ Sirius      ║         -1.46 ║ A1V            ║
║ Vega        ║          0.03 ║ A0V            ║
║ Betelgeuse  ║          0.50 ║ M1-2Ia-Iab     ║
╚═════════════╩═══════════════╩════════════════╝

Usage example, with lica-cli package

import sys
from argparse import ArgumentParser, Namespace

from lica_cli import parse_args, run_cli
from lica_tables.adapters.tabulate import StdoutDisplay

from myprog import __version__

DESCRIPTION = "My program short description"


def add_args(parser: ArgumentParser) -> None:
    """Add extra CLI arguments here"""
    pass


def cli_main(args: Namespace) -> None:
    rows = [
        ["Sirius", -1.46, "A1V"],
        ["Vega", 0.03, "A0V"],
    ]

    display = StdoutDisplay(table_fmt="simple")
    display.show_tabular(
        rows,
        keys=["Name", "Magnitude", "Spectral type"],
        title="Bright stars",
    )


def main():
    args = parse_args(add_args, __name__, __version__, DESCRIPTION)
    return_code = run_cli(cli_main, args, __name__, __version__)
    sys.exit(return_code)


if __name__ == "__main__":
    main()

Metadata

Release files for lica-tables 0.2.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 lica-tables 0.2.1
File Size Uploaded Provenance Actions
lica_tables-0.2.1.tar.gz 5.5 kB Without provenance Details for lica_tables-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lica-tables 0.2.1
File Interpreter ABI Platform Actions
lica_tables-0.2.1-py3-none-any.whl Python 3 none any Details for lica_tables-0.2.1-py3-none-any.whl

Total release size: 12.6 kB

Release files / lica_tables-0.2.1.tar.gz

Download URL lica_tables-0.2.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c99de257b226947e229f5c7100fdb638985062bcb2abd6059676878cb10ca853
BLAKE2b-256 checksum
How to use checksums
73224f2a88b170f6b7c6264aebda09145ef7845b7190ef350ac6cba5d81c6df4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"AlmaLinux","version":"10.2","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / lica_tables-0.2.1-py3-none-any.whl

Download URL lica_tables-0.2.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2aa6c4ccda1b9b09118254e3abba8882e1956fcf8352b06386d34bb69ce16d3e
BLAKE2b-256 checksum
How to use checksums
8ff858a9edc173a69c975ed55ad8cc4438d990c4d6aae5db25955f7d26fb47aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"AlmaLinux","version":"10.2","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for lica-tables 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.

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