txtable - Plain text tables for Python 3
Pretty-print tabular data as plain text. Supports Markdown and reStructuredText tables too.
Sample outputs
Default formatter
Date Mobile Operating System Percent of Usage ========== ======================= ================ 2008-12-01 Android 0 2008-12-01 iOS 32.56 2008-12-01 SymbianOS 42.02 2008-12-01 Series 40 0 2008-12-01 BlackBerry OS 0 2008-12-01 Samsung 0 2008-12-01 Unknown 16 2008-12-01 Windows Phone 0
Headless formatter
Date Mobile Operating System Percent of Usage 2008-12-01 Android 0 2008-12-01 iOS 32.56 2008-12-01 SymbianOS 42.02 2008-12-01 Series 40 0 2008-12-01 BlackBerry OS 0
MD formatter
Date | Mobile Operating System | Percent of Usage ---------- | ----------------------- | ---------------- 2008-12-01 | Android | 0 2008-12-01 | iOS | 32.56 2008-12-01 | SymbianOS | 42.02 2008-12-01 | Series 40 | 0 2008-12-01 | BlackBerry OS | 0
RST formatter
+------------+-------------------------+------------------+ | Date | Mobile Operating System | Percent of Usage | +============+=========================+==================+ | 2008-12-01 | Android | 0 | +------------+-------------------------+------------------+ | 2008-12-01 | iOS | 32.56 | +------------+-------------------------+------------------+ | 2008-12-01 | SymbianOS | 42.02 | +------------+-------------------------+------------------+ | 2008-12-01 | Series 40 | 0 | +------------+-------------------------+------------------+ | 2008-12-01 | BlackBerry OS | 0 | +------------+-------------------------+------------------+
Installation
It’s the usual process as with any other Python package:
python3 setup.py install
Or install with pip:
pip3 install txtable
Usage as a module
Default usage:
# let's pretty-print a CSV file
import csv
from txtable import TextTable
with open("cities.csv") as f:
data = list(csv.reader(f))
# the TextTable constructor takes a sequence type as the first argument
print(TextTable(data))
Use a formatter (available formatters are DefaultFormatter, HeadlessFormatter, MdFormatter, RstFormatter):
print(TextTable(data, formatter=MdFormatter()))
Command-line usage
The command-line interface supports formatting input data in JSON and CSV format. Input can be a list of files or stdin.
cat cities.csv | python3 -m txtable -t csv -f md
curl http://ponydealer.com/api/available.json | python3 -m txtable -t json
Command-line help
usage: txtable [-h] [-f FORMATTER] [-t TYPE] [files [files ...]]
positional arguments:
files Path to input files (json/csv) or read from stdin when
empty (default: [])
optional arguments:
-h, --help show this help message and exit
-f FORMATTER, --formatter FORMATTER
Table format: default, headless, md (Markdown) or rst
(ReStructuredText) (default: default)
-t TYPE, --type TYPE Input data type to read from stdin: json/csv (default:
json)
Metadata
Release files for txtable 2.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| txtable-2.1.2.tar.gz | 5.1 kB | Without provenance | Details for txtable-2.1.2.tar.gz |
Release files / txtable-2.1.2.tar.gz
| Download URL | txtable-2.1.2.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
029c144bb687ba383808558b565099618d4f6186edb0d00f9afeaff9df223c79
|
|
BLAKE2b-256 checksum How to use checksums |
9ab8d872404ff3134460044e6b78fd3d132e3cee64054874aa92600812fe479f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for txtable 2.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.