Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

larztable

Query and render tabular data — in one small object. Zero dependencies.

Most tools make you choose: a query/dataframe library (heavy) or a pretty-printer (no querying). larztable is both, tiny. Load rows, filter/sort/aggregate them with a fluent Django-style API, then print a clean terminal table or export to CSV/Markdown — no pandas, no tabulate.

from larztable import Table

t = Table.from_dicts([
    {"name": "Ada", "age": 36, "role": "admin"},
    {"name": "Bo",  "age": 24, "role": "user"},
    {"name": "Cy",  "age": 41, "role": "user"},
])

print(t.where(role="user").sort("age", reverse=True).select("name", "age"))
┌──────┬─────┐
│ name │ age │
├──────┼─────┤
│ Cy   │  41 │
│ Bo   │  24 │
└──────┴─────┘

Why

  • One tool for both jobs. Querying and presenting are the same object: .where(), .sort(), .select(), .limit(), .group_by(), aggregates — then print(t), t.to_csv(), t.to_markdown().
  • Expressive filters. Django-style lookups — where(age__gt=30, role="user", name__icontains="a") — plus arbitrary predicate functions.
  • Reads like data. Numbers auto-right-align in the Unicode table; CSV round-trips; Markdown for docs and PRs.
  • Zero dependencies. No pandas, no tabulate, no numpy.

Install

pip install larztable

Query

t.where(role="admin")                       # equality
t.where(age__gte=30, age__lt=40)            # gt/gte/lt/lte/ne/in/contains/...
t.where(lambda r: r["age"] % 2 == 0)        # any predicate
t.sort("age", reverse=True)
t.select("name", "age")
t.limit(10, offset=5)
t.distinct("role")

# aggregates
t.count(); t.sum("age"); t.avg("age"); t.min("age"); t.max("age")
t.group_by("role").count()                  # Table of role, count
t.group_by("role").avg("age")               # Table of role, age_avg

Every query returns a new Table (the original is untouched), so chains are safe.

Load & export

Table.from_csv("data.csv")
Table.from_csv_string("name,age\nAda,36\n")
Table.from_dicts([...])
Table.from_rows([["Ada", 36]], columns=["name", "age"])

t.to_csv("out.csv"); t.to_csv()             # string
t.to_markdown()
t.to_dicts(); t.to_rows()
print(t)                                    # pretty terminal table

Tests

python -m unittest discover -s tests -v   # 27 tests, zero deps

The Larz stack

Pure-Python, zero-dependency building blocks: larz · larzchain · larzmoney · larzcrypt · larzdb · larzagent · larzchart · larzmark · larztask · larzvault · larzvm · larzcache · larzvalidate · larzid · larzrpc · larzstate · larzhttp · larzconf · larzcron · larzlimit · larzlog · larzcli · larzretry · larztime · larzpdf · larzpack · larztemplate · larzcolor · larztable

License

MIT © larz-scripter

About

Query and render tabular data in one small object: fluent filter/sort/aggregate + pretty terminal tables, CSV, Markdown. Pure Python, zero dependencies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages