Skip to main content

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 = 10
artist = lt.artists.ConsoleWithProgress()
lt.stream(fib_table(n), headers=['N', 'F_N'], n_rows=n + 1, artist=artist)

Release files for lazy-table 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 lazy-table 0.2.1
File Size Uploaded
lazy-table-0.2.1.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lazy-table 0.2.1
File Interpreter ABI Platform
lazy_table-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / lazy-table-0.2.1.tar.gz

Download URL lazy-table-0.2.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cc724a895ad55f3b65129a95f4bab58b5787a03d282470c4ddb02ff33386d433
BLAKE2b-256 checksum
How to use checksums
61c8444ab09de64d906cca5895caf1b553f4f0e48ed01d3175276153df81e923
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

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

Download URL lazy_table-0.2.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
342f19a49befc7fc31c393f6bd665938b75e0f73cef1560c7f228c860fc76a14
BLAKE2b-256 checksum
How to use checksums
b55db71cd562429fd16d698610bebe7e4e8d88ed8222d2e084bcb051e6c6b701
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

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