Skip to main content

pytablewriter is a python library to write a table in various formats: CSV/HTML/JavaScript/JSON/Markdown/Excel/Pandas/Python/reStructuredText

Project description

pytablewriter

https://img.shields.io/pypi/pyversions/pytablewriter.svg https://travis-ci.org/thombashi/pytablewriter.svg?branch=master https://ci.appveyor.com/api/projects/status/2w0611ajvw21vho5?svg=true https://coveralls.io/repos/github/thombashi/pytablewriter/badge.svg?branch=master

Summary

pytablewriter is a python library to write a table in various formats: CSV/HTML/JavaScript/JSON/Markdown/Excel/Pandas/Python/reStructuredText

Features

  • Write a table in various formats:
    • CSV

    • Microsoft Excel TM

    • HTML

    • JavaScript (Definition of a nested list variable)

    • JSON

    • Markdown

    • Pandas (Definition of a DataFrame variable)

    • Python code (Definition of a nested list variable)

    • reStructuredText
      • Grid tables

      • Simple tables

      • CSV table

  • Automatic value formatting
    • Alignment

    • Padding

    • Decimal places of numbers

  • Output to a stream such as a file or the standard output

Examples

Write a Markdown table

import pytablewriter

writer = pytablewriter.MarkdownTableWriter()
writer.table_name = "zone"
writer.header_list = ["zone_id", "country_code", "zone_name"]
writer.value_matrix = [
    ["1", "AD", "Europe/Andorra"],
    ["2", "AE", "Asia/Dubai"],
    ["3", "AF", "Asia/Kabul"],
    ["4", "AG", "America/Antigua"],
    ["5", "AI", "America/Anguilla"],
]

writer.write_table()
# zone
zone_id|country_code|   zone_name
------:|------------|----------------
      1|AD          |Europe/Andorra
      2|AE          |Asia/Dubai
      3|AF          |Asia/Kabul
      4|AG          |America/Antigua
      5|AI          |America/Anguilla

Rendering result

markdown_ss

Rendered markdown at GitHub

Write a reStructuredText table (grid tables)

import pytablewriter

writer = pytablewriter.RstGridTableWriter()
writer.table_name = "zone"
writer.header_list = ["zone_id", "country_code", "zone_name"]
writer.value_matrix = [
    ["1", "AD", "Europe/Andorra"],
    ["2", "AE", "Asia/Dubai"],
    ["3", "AF", "Asia/Kabul"],
    ["4", "AG", "America/Antigua"],
    ["5", "AI", "America/Anguilla"],
]

writer.write_table()
.. table:: zone

    +-------+------------+----------------+
    |zone_id|country_code|   zone_name    |
    +=======+============+================+
    |      1|AD          |Europe/Andorra  |
    +-------+------------+----------------+
    |      2|AE          |Asia/Dubai      |
    +-------+------------+----------------+
    |      3|AF          |Asia/Kabul      |
    +-------+------------+----------------+
    |      4|AG          |America/Antigua |
    +-------+------------+----------------+
    |      5|AI          |America/Anguilla|
    +-------+------------+----------------+

Rendering result

zone

zone_id

country_code

zone_name

1

AD

Europe/Andorra

2

AE

Asia/Dubai

3

AF

Asia/Kabul

4

AG

America/Antigua

5

AI

America/Anguilla

Write a JavaScript table (variable definition of nested list )

import pytablewriter

writer = pytablewriter.JavaScriptTableWriter()
writer.table_name = "zone"
writer.header_list = ["zone_id", "country_code", "zone_name"]
writer.value_matrix = [
    ["1", "AD", "Europe/Andorra"],
    ["2", "AE", "Asia/Dubai"],
    ["3", "AF", "Asia/Kabul"],
    ["4", "AG", "America/Antigua"],
    ["5", "AI", "America/Anguilla"],
]

writer.write_table()
var zone = [
    ["zone_id", "country_code", "zone_name"],
    [1, "AD", "Europe/Andorra"],
    [2, "AE", "Asia/Dubai"],
    [3, "AF", "Asia/Kabul"],
    [4, "AG", "America/Antigua"],
    [5, "AI", "America/Anguilla"]
];

Write an Excel table

import pytablewriter

writer = pytablewriter.ExcelTableWriter()
writer.open_workbook("sample_single.xlsx")

writer.make_worksheet("zone")
writer.header_list = ["zone_id", "country_code", "zone_name"]
writer.value_matrix = [
    ["1", "AD", "Europe/Andorra"],
    ["2", "AE", "Asia/Dubai"],
    ["3", "AF", "Asia/Kabul"],
    ["4", "AG", "America/Antigua"],
    ["5", "AI", "America/Anguilla"],
]
writer.write_table()

writer.close()

Output

excel_single

Output excel file (sample_single.xlsx)

For more information

More examples are available at http://pytablewriter.readthedocs.org/en/latest/pages/examples/index.html

Installation

pip install pytablewriter

Dependencies

Python 2.7+ or 3.3+

Test dependencies

Documentation

http://pytablewriter.readthedocs.org/en/latest/

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytablewriter-0.1.1.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

pytablewriter-0.1.1-py2.py3-none-any.whl (19.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytablewriter-0.1.1.tar.gz.

File metadata

File hashes

Hashes for pytablewriter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 451188e413baf13b41370c1c0de150b60b0cdc4103fe6a94eac13a837b792e0c
MD5 56613ae1b5290d225fcfa3c5ef2d9882
BLAKE2b-256 f22e9c8b1d7376b3a62ff8fe7a7c30334626b19494a844e6b80a2bd314962f2b

See more details on using hashes here.

File details

Details for the file pytablewriter-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytablewriter-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1eedfb06cda1fbefc592ea13d674421421d6b5ee3dbcf16cbc7d04e4f9f65998
MD5 f4f63a875981a9f86ffa5237f01e839b
BLAKE2b-256 e6dd389640a86eed75567ecb5d756aa9d13a955070b8e12089ec38c5beababe6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page