Skip to main content

A modern structured Python library for formatted table output

Project description

RowDump

A modern, structured, no-dependency Python library for formatted table output with support for custom formatting, ASCII box drawing, and flexible column definitions.

Features

  • Structured table output with customizable column definitions
  • ASCII box drawing for beautiful table borders
  • Header separators with optional line between header and data
  • Custom formatters for data transformation
  • Automatic text truncation with configurable suffixes
  • DateTime formatting with RFC3339 support
  • Custom delimiters and output functions
  • Empty value handling with custom placeholders
  • Multiple table support with automatic table management

Installation

pip install rowdump

Requirements: Python 3.10+

Quick Start

from datetime import datetime
from rowdump import Column, Dump

# Create a dump instance
dump = Dump()

# Define columns
columns = [
    Column("id", "ID", int, 5),
    Column("name", "Name", str, 15),
    Column("age", "Age", int, 3),
    Column("city", "City", str, 12),
]

# Set columns and print header
dump.cols(columns)

# Add rows
dump.row({"id": 1, "name": "Alice", "age": 30, "city": "New York"})
dump.row({"id": 2, "name": "Bob", "age": 25, "city": "San Francisco"})
dump.row({"id": 3, "name": "Charlie", "age": 35, "city": "Los Angeles"})

# Close table and print summary
dump.close()

Output:

ID    Name            Age City        
1     Alice           30  New York    
2     Bob             25  San Franc...
3     Charlie         35  Los Angeles 
Total rows: 3

ASCII Box Formatting

dump = Dump(ascii_box=True)

columns = [
    Column("product", "Product", str, 20),
    Column("price", "Price", float, 10),
    Column("stock", "Stock", int, 8),
]

dump.cols(columns)
dump.row({"product": "Laptop", "price": 999.99, "stock": 15})
dump.row({"product": "Mouse", "price": 25.50, "stock": 100})
dump.close()

Output:

┌────────────────────┬──────────┬────────┐
│Product             │Price     │Stock   │
├────────────────────┼──────────┼────────┤
│Laptop              │999.99    │15      │
│Mouse               │25.5      │100     │
└────────────────────┴──────────┴────────┘
Total rows: 2

Custom Formatters

def currency_formatter(value):
    if value is None:
        return "$0.00"
    return f"${value:.2f}"

dump = Dump(ascii_box=True)

columns = [
    Column("item", "Item", str, 12),
    Column("price", "Price", float, 10, formatter=currency_formatter),
    Column("quantity", "Qty", int, 5),
]

dump.cols(columns)
dump.row({"item": "Coffee", "price": 4.50, "quantity": 2})
dump.row({"item": "Water", "price": None, "quantity": 3})
dump.close()

DateTime Formatting

dump = Dump(delimiter=" | ")

columns = [
    Column("event", "Event", str, 15),
    Column("timestamp", "Timestamp", datetime, 20),
    Column("status", "Status", str, 10),
]

dump.cols(columns)
dump.row({
    "event": "User Login",
    "timestamp": datetime(2024, 1, 15, 10, 30, 0),
    "status": "Success"
})
dump.close()

Output:

Event           | Timestamp            | Status    
--------------- | -------------------- | ----------
User Login      | 2024-01-15T10:30:00Z | Success   
Total rows: 1

Header Separators

# With separator (default)
dump = Dump()
columns = [Column("name", "Name", str, 10), Column("status", "Status", str, 8)]
dump.cols(columns)
dump.row({"name": "Alice", "status": "Active"})
dump.close()

# Without separator
dump = Dump(header_separator=False)
dump.cols(columns)
dump.row({"name": "Bob", "status": "Inactive"})
dump.close()

Output:

Name       Status  
---------- --------
Alice      Active  
Total rows: 1

Name       Status  
Bob        Inactive
Total rows: 1

API Reference

Column Class

Column(
    name: str,
    display_name: str | None = None,
    type: type = str,
    width: int = 20,
    empty_value: str = "",
    truncate_suffix: str = "...",
    formatter: Callable[[Any], str] | None = None,
)
  • name: Column name (used as dictionary key)
  • display_name: Header display name (defaults to name)
  • type: Data type (used for default formatting)
  • width: Maximum column width
  • empty_value: Value to display for None/empty values
  • truncate_suffix: Suffix for truncated values
  • formatter: Custom formatting function

Dump Class

Dump(
    delimiter: str = " ",
    ascii_box: bool = False,
    output_fn: Callable[[str], None] | None = None,
    header_separator: bool = True,
)
  • delimiter: Separator between columns
  • ascii_box: Enable ASCII box drawing
  • output_fn: Custom output function (defaults to print)
  • header_separator: Print separator line between header and data rows

Methods

  • cols(columns: Sequence[Column]): Set columns and print header
  • row(data: dict[str, Any]): Print a data row
  • close(summary: bool = True): Close table and optionally print summary

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rowdump-0.1.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rowdump-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file rowdump-0.1.0.tar.gz.

File metadata

  • Download URL: rowdump-0.1.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rowdump-0.1.0.tar.gz
Algorithm Hash digest
SHA256 62cdb83ab7f67f6dffb58cbe8ca772ad76a968fc6c5c01a8fc66829f475a6bc3
MD5 b52157eaac260d403bd69470ed6e36f7
BLAKE2b-256 921350f8f750d61e620dbfbbfd603b0c2e498f6f8c435ed158b66d48b8698d66

See more details on using hashes here.

Provenance

The following attestation bundles were made for rowdump-0.1.0.tar.gz:

Publisher: publish.yml on markjen/rowdump

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rowdump-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rowdump-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rowdump-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c565802e5900b514dffdd4d9e09212ecaa738c91a0402e763bec0b16d8b7fd2
MD5 3289388bd54f48c072fe255bc2d27a74
BLAKE2b-256 c71d8c89926d510d0b9ffbb9fd8ce254c41909d9f19dcf627b8725f3c13ad198

See more details on using hashes here.

Provenance

The following attestation bundles were made for rowdump-0.1.0-py3-none-any.whl:

Publisher: publish.yml on markjen/rowdump

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page