All Projects → alttch → Rapidtables

alttch / Rapidtables

Licence: mit
Super fast list of dicts to pre-formatted tables conversion library for Python 2/3

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Rapidtables

Arduinopcap
A library for creating and sending .pcap files for Wireshark and other programms.
Stars: ✭ 278 (-4.79%)
Mutual labels:  library
Discord Rpc Csharp
C# custom implementation for Discord Rich Presence. Not deprecated and still available!
Stars: ✭ 282 (-3.42%)
Mutual labels:  library
React Spectrum
Generate colorful text placeholders 🎨
Stars: ✭ 289 (-1.03%)
Mutual labels:  library
Dry Configurable
A simple mixin to make Ruby classes configurable
Stars: ✭ 280 (-4.11%)
Mutual labels:  library
Pannellum
Pannellum is a lightweight, free, and open source panorama viewer for the web. Built using HTML5, CSS3, JavaScript, and WebGL, it is plug-in free. It can be deployed easily as a single file, just 21kB gzipped, and then embedded into pages as an <iframe>. A configuration utility is included to generate the required code for embedding. An API is included for more advanced integrations.
Stars: ✭ 3,286 (+1025.34%)
Mutual labels:  library
Framework7
Full featured HTML framework for building iOS & Android apps
Stars: ✭ 16,560 (+5571.23%)
Mutual labels:  library
Swiftuix
Extensions and additions to the standard SwiftUI library.
Stars: ✭ 4,087 (+1299.66%)
Mutual labels:  library
Sparklinelayout
Simple and lightweight library for drawing sparklines / graphs. Support markers and gradients.
Stars: ✭ 291 (-0.34%)
Mutual labels:  library
Rex
Your RegEx companion.
Stars: ✭ 283 (-3.08%)
Mutual labels:  library
Beagle
A smart, reliable, and highly customizable debug menu library for Android apps that supports screen recording, network activity logging, and many other useful features.
Stars: ✭ 287 (-1.71%)
Mutual labels:  library
Vue Advanced Cropper
The advanced vue cropper library that gives you opportunity to create your own croppers suited for any website design
Stars: ✭ 281 (-3.77%)
Mutual labels:  library
Cute headers
Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games
Stars: ✭ 3,274 (+1021.23%)
Mutual labels:  library
Mojs
The motion graphics toolbelt for the web
Stars: ✭ 17,189 (+5786.64%)
Mutual labels:  library
Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (-4.45%)
Mutual labels:  library
Android Location Tracker
Android helper that tracks user location
Stars: ✭ 289 (-1.03%)
Mutual labels:  library
Swup
🎉 Complete, flexible, extensible and easy to use page transition library for your static web.
Stars: ✭ 3,190 (+992.47%)
Mutual labels:  library
React Modern Library Boilerplate
Boilerplate for publishing modern React modules with Rollup
Stars: ✭ 285 (-2.4%)
Mutual labels:  library
Libmqtt
MQTT v3.1.1/5.0 library in Go
Stars: ✭ 290 (-0.68%)
Mutual labels:  library
Spruce Ios
Swift library for choreographing animations on the screen.
Stars: ✭ 3,249 (+1012.67%)
Mutual labels:  library
Cppfs
Cross-platform C++ file system library supporting multiple backends
Stars: ✭ 279 (-4.45%)
Mutual labels:  library

rapidtables

rapidtables is a module for Python 2/3, which does only one thing: converts lists of dictionaries to pre-formatted tables. And it does the job as fast as possible.

rapidtables is focused on speed and is useful for applications which dynamically refresh data in console. The module code is heavily optimized and written purely in Python.

And unlike other similar modules, rapidtables can output pre-formatted generators of strings or even generators of tuples of strings, which allows you to colorize every single column.

Install

pip install rapidtables

Example

# if you need to keep strict column ordering, use OrderedDict for the rows
data = [
    { 'name': 'John', 'salary': 2000, 'job': 'DevOps' },
    { 'name': 'Jack', 'salary': 2500, 'job': 'Architect' },
    { 'name': 'Diana', 'salary': None, 'job': 'Student' },
    { 'name': 'Ken', 'salary': 1800, 'job': 'Q/A' }
]

from rapidtables import format_table, FORMAT_GENERATOR_COLS
from termcolor import colored

header, rows = format_table(data, fmt=FORMAT_GENERATOR_COLS)
spacer = '  '
print(colored(spacer.join(header), color='blue'))
print(colored('-' * sum([(len(x) + 2) for x in header]), color='grey'))
for r in rows:
    print(colored(r[0], color='white', attrs=['bold']) + spacer, end='')
    print(colored(r[1], color='cyan') + spacer, end='')
    print(colored(r[2], color='yellow'))

colorized cols

Pretty cool, isn't it? Actually, it was the most complex example, you can work with header + table rows already joined:

from rapidtables import format_table, FORMAT_GENERATOR

header, rows = format_table(data, fmt=FORMAT_GENERATOR)
print(colored(header, color='blue'))
print(colored('-' * len(header), color='grey'))
for r in rows:
    print(colored(r, color='yellow'))

colorized rows

Or you can use make_table function to return the table out-of-the-box (or print_table to instantly print it), and print it in raw:

print_table(data)
name  salary  job
----  ------  ---------
John    2000  DevOps
Jack    2500  Architect
Ken     1800  Q/A

Quick API reference

format_table

Formats a table. Outputs data in raw, generator of strings (one string per row) or generator of tuples of strings (one tuple per row, one string per column):

  • fmt=rapidtables.FORMAT_RAW raw string
  • fmt=rapidtables.FORMAT_GENERATOR generator of strings
  • fmt=rapidtables.FORMAT_GENERATOR_COLS generator of tuples of strings

Align columns:

  • align=rapidtables.ALIGN_LEFT align all columns to left
  • align=rapidtables.ALIGN_NUMBERS_RIGHT align numbers to right (default)
  • align=rapidtables.ALIGN_RIGHT align all columns to right
  • align=rapidtables.ALIGN_CENTER align all columns to center
  • align=rapidtables.ALIGN_HOMOGENEOUS_NUMBERS_RIGHT align numbers to right but consider the table is homogeneous and check col values only to first number or string (works slightly faster)

To predefine aligns, set align to tuple or list:

align=(rapidtables.ALIGN_LEFT, rapidtables.ALIGN_RIGHT, ....)

number of items in list must match number of columns in table.

You may also customize headers, separators etc. Read pydoc for more info.

make_table

Generates a ready to output table. Supports basic formats:

table = rapidtables.make_table(data, tablefmt='raw')
name  salary  job
-----------------------
John     2000  DevOps
Jack     2500  Architect
Diana          Student
Ken      1800  Q/A
table = rapidtables.make_table(data, tablefmt='simple')
name   salary  job
----   ------  ---------
John     2000  DevOps
Jack     2500  Architect
Diana          Student
Ken      1800  Q/A
table = rapidtables.make_table(data, tablefmt='md') # Markdown
| name  | salary | job       |
|-------|--------|-----------|
| John  |   2000 | DevOps    |
| Jack  |   2500 | Architect |
| Diana |        | Student   |
| Ken   |   1800 | Q/A       |
table = rapidtables.make_table(data, tablefmt='rst') # reStructured, simple
=====  ======  =========
name   salary  job
=====  ======  =========
John     2000  DevOps
Jack     2500  Architect
Diana          Student
Ken      1800  Q/A
=====  ======  =========
table = rapidtables.make_table(data, tablefmt='rstgrid') # reStructured, grid
+-------+--------+-----------+
| name  | salary | job       |
+=======+========+===========+
| John  |   2000 | DevOps    |
+-------+--------+-----------+
| Jack  |   2500 | Architect |
+-------+--------+-----------+
| Diana |        | Student   |
+-------+--------+-----------+
| Ken   |   1800 | Q/A       |
+-------+--------+-----------+

print_table

The same as make_table, but prints table to stdout.

Benchmarks

(Python 3.7)

benchmarks

Enjoy!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].