lazy_table - a python-tabulate wrapper for producing tables from generators

Overview

lazy_table

A python-tabulate wrapper for producing tables from generators.

Motivation

lazy_table is useful when (i) each row of your table is generated by a possibly expensive computation and (ii) you want to print rows to the screen as soon as they are available.

For example, the rows in the table below correspond to numerically solving an ordinary differential equation with progressively more steps. See examples/euler_vdp.py for the code to generate this table.

Here is the same example with a progress bar.

Installation and usage

Install lazy_table via pip:

$ pip install lazy_table

In your Python code, add

import lazy_table as lt

Now, generating your own lazy table is as simple as calling lt.stream on a generator that yields one or more lists, where each list is a row of your table (see the example below).

Example

As a toy example, consider printing the first 10 Fibonacci numbers in a table. Since this is a relatively cheap operation, we will pretend it is expensive by adding an artificial sleep(1) call beteween Fibonacci numbers.

import time
import lazy_table as lt

def fib_table(n):
     x0, x1 = 0, 1
     yield [0, x0]
     yield [1, x1]
     for i in range(2, n + 1):
         time.sleep(1)  # Simulate work
         x0, x1 = x1, x0 + x1
         yield [i, x1]

lt.stream(fib_table(10), headers=['N', 'F_N'])

Your final table should look like this:

  N    F_N
---  -----
  0      0
  1      1
  2      1
  3      2
  4      3
  5      5
  6      8
  7     13
  8     21
  9     34
 10     55

You can also specify an "artist" that determines how the table is rendered. For example, the ConsoleWithProgress artist displays a progress bar alongside the table indicating the percentage of rows completed:

n_rows = 10
artist = lt.artists.ConsoleWithProgress()
lt.stream(fib_table(n_rows), headers=['N', 'F_N'], n_rows=n_rows, artist=artist)
You might also like...
cli simple python script to interact with iphone afc api based on python library( tidevice )
cli simple python script to interact with iphone afc api based on python library( tidevice )

afcclient cli simple python script to interact with iphone afc api based on python library( tidevice ) installation pip3 install -U tidevice cp afccli

Python command line tool and python engine to label table fields and fields in data files.

Python command line tool and python engine to label table fields and fields in data files. It could help to find meaningful data in your tables and data files or to find Personal identifable information (PII).

xonsh is a Python-powered, cross-platform, Unix-gazing shell
xonsh is a Python-powered, cross-platform, Unix-gazing shell

xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt.

A command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, VueJS projects.
A command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, VueJS projects.

Cookiecutter A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python

Dead simple CLI tool to try Python packages - It's never been easier! :package:
Dead simple CLI tool to try Python packages - It's never been easier! :package:

try - It's never been easier to try Python packages try is an easy-to-use cli tool to try out Python packages. Features Install specific package versi

Python commandline tool for remembering linux/terminal commands
Python commandline tool for remembering linux/terminal commands

ehh Remember linux commands Commandline tool for remembering linux/terminal commands. It stores your favorite commands in ~/ehh.json in your homedir a

A Telegram Bot Written In Python To Upload Medias To telegra.ph

Telegraph-Uploader A Telegram Bot Written In Python To Upload Medias To telegra.ph DEPLOY YOU CAN SIMPLY DEPLOY ON HEROKU BY CLICKING THE BUTTON BELOW

Rich is a Python library for rich text and beautiful formatting in the terminal.
Rich is a Python library for rich text and beautiful formatting in the terminal.

The Rich API makes it easy to add color and style to terminal output. Rich can also render pretty tables, progress bars, markdown, syntax highlighted source code, tracebacks, and more — out of the box.

Comments
  • status bar stays on screen after using ConsoleWithProgress

    status bar stays on screen after using ConsoleWithProgress

    If you stream a table with ConsoleWithProgress, it works great. But I have more output to display after the table but the 100% progress bar is stuck somehow on the bottom of the screen.

    example

    lazy_table.stream(...artist=lazy_table.artists.ConsoleWithProgress()) print("Hello world!") # this line will be above the status bar.

    I think after the table is printed the cursor is positioned before the status bar and it inserts any additional output before the status bar.

    Is there a way to remove the status bar when complete?

    opened by amm042 2
  • Remove tqdm

    Remove tqdm

    Removes tqdm as a dependency in lieu of a custom progress bar and solves issue #2 in the process.

      Steps      Value          Delta       Order
    -------  ---------  -------------  ----------
        200   0.785109  nan            nan
        400  -0.131546   -0.916655     nan
        800  -0.723048   -0.591502       0.631995
       1600  -1.02156    -0.298515       0.986578
       3200  -1.16159    -0.140028       1.09209
       6400  -1.22794    -0.0663467      1.07762
      12800  -1.26004    -0.0321066      1.04715
      25600  -1.27581    -0.0157701      1.02568
      51200  -1.28363    -0.00781233     1.01337
     102400  -1.28751    -0.00388776     1.00681
     204800  -1.28945    -0.00193925     1.00344
     409600  -1.29042    -0.000968464    1.00173
    
    |████████████████████████████████| 12/12 [6.22s, 1.93it/s]
    
    opened by parsiad 0
Releases(v0.2.1)
Python script to tabulate data formats like json, csv, html, etc

pyT PyT is a a command line tool and as well a library for visualising various data formats like: JSON HTML Table CSV XML, etc. Features Print table o

Mobolaji Abdulsalam 1 Dec 30, 2021
Open-Source Python CLI package for copying DynamoDB tables and items in parallel batch processing + query natural & Global Secondary Indexes (GSIs)

Python Command-Line Interface Package to copy Dynamodb data in parallel batch processing + query natural & Global Secondary Indexes (GSIs).

null 1 Oct 31, 2021
Zecwallet-Python is a simple wrapper around the Zecwallet Command Line LightClient written in Python

A wrapper around Zecwallet Command Line LightClient, written in Python Table of Contents About Installation Usage Examples About Zecw

Priveasy 2 Sep 6, 2022
An awesome Python wrapper for an awesome Docker CLI!

An awesome Python wrapper for an awesome Docker CLI!

Gabriel de Marmiesse 303 Jan 3, 2023
Python wrapper and CLI utility to render LaTeX markup and equations as SVG using dvisvgm and svgo.

latex2svg Python wrapper and CLI utility to render LaTeX markup and equations as SVG using dvisvgm and svgo. Based on the original work by Tino Wagner

Matthias C. Hormann 4 Feb 18, 2022
NudeNet wrapper made to provide a simple cli interface to the library

Nudenet Wrapper. Small warpper script for NudeNet Made to provide a small and easy to use cli interface with the library. You can indicate a single im

null 1 Oct 20, 2021
🗃️ Fileio-cli wrapper for fileioapi.py with fire.py, inspiration DOS

??️ File.io File.io simply upload a file, share the link, and after it is downloaded, the file is completely deleted. An API wrapper for the file.io w

nkot56297 2 May 12, 2022
Ssl-tool - A simple interactive CLI wrapper around openssl to make creation and installation of self-signed certs easy

What's this? A simple interactive CLI wrapper around openssl to make self-signin

Aniket Teredesai 9 May 17, 2022
🐍The nx-python plugin allows users to create a basic python application using nx commands.

?? NxPy: Nx Python plugin This project was generated using Nx. The nx-python plugin allows users to create a basic python application using nx command

StandUP Communications 74 Aug 31, 2022
Simple Python Library to display text with color in Python Terminal

pyTextColor v1.0 Introduction pyTextColor is a simple Python Library to display colorful outputs in Terminal, etc. Note: Your Terminal or any software

Siddhesh Chavan 1 Jan 23, 2022