An intuitive and type-safe library for converting 2D Python lists to fancy ASCII/Unicode tables
Documentation and examples are available at table2ascii.rtfd.io
pip install -U table2ascii
Requirements: Python 3.7+
```py from table2ascii import table2ascii
output = table2ascii( header=["#", "G", "H", "R", "S"], body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]], footer=["SUM", "130", "140", "135", "130"], )
print(output)
""" βββββββββββββββββββββββββββββββ β # G H R S β βββββββββββββββββββββββββββββββ’ β 1 30 40 35 30 β β 2 30 40 35 30 β βββββββββββββββββββββββββββββββ’ β SUM 130 140 135 130 β βββββββββββββββββββββββββββββββ """ ```
```py from table2ascii import table2ascii
output = table2ascii( body=[["Assignment", "30", "40", "35", "30"], ["Bonus", "10", "20", "5", "10"]], first_col_heading=True, )
print(output)
""" ββββββββββββββ¦ββββββββββββββββββββ β Assignment β 30 40 35 30 β β Bonus β 10 20 5 10 β ββββββββββββββ©ββββββββββββββββββββ """ ```
```py from table2ascii import table2ascii, Alignment
output = table2ascii( header=["Product", "Category", "Price", "Rating"], body=[ ["Milk", "Dairy", "$2.99", "6.283"], ["Cheese", "Dairy", "$10.99", "8.2"], ["Apples", "Produce", "$0.99", "10.00"], ], column_widths=[12, 12, 12, 12], alignments=[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT, Alignment.DECIMAL], )
print(output)
""" βββββββββββββββββββββββββββββββββββββββββββββββββββββ β Product Category Price Rating β βββββββββββββββββββββββββββββββββββββββββββββββββββββ’ β Milk Dairy $2.99 6.283 β β Cheese Dairy $10.99 8.2 β β Apples Produce $0.99 10.00 β βββββββββββββββββββββββββββββββββββββββββββββββββββββ """ ```
See a list of 30+ preset styles here.
```py from table2ascii import table2ascii, Alignment, PresetStyle
output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], column_widths=[10, 10, 10, 10], style=PresetStyle.ascii_box )
print(output)
""" +----------+----------+----------+----------+ | First | Second | Third | Fourth | +----------+----------+----------+----------+ | 10 | 30 | 40 | 35 | +----------+----------+----------+----------+ | 20 | 10 | 20 | 5 | +----------+----------+----------+----------+ """
output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], style=PresetStyle.plain, cell_padding=0, alignments=Alignment.LEFT, )
print(output)
""" First Second Third Fourth 10 30 40 35 20 10 20 5 """ ```
Check TableStyle
for more info and PresetStyle
for examples.
```py from table2ascii import table2ascii, TableStyle
my_style = TableStyle.from_string("-..||:+-+:+ ''")
output = table2ascii( header=["First", "Second", "Third"], body=[["10", "30", "40"], ["20", "10", "20"], ["30", "20", "30"]], style=my_style )
print(output)
""" -------.--------.------- | First : Second : Third | +-------:--------:-------+ | 10 : 30 : 40 | | 20 : 10 : 20 | | 30 : 20 : 30 | -------'--------'------- """ ```
```py from table2ascii import table2ascii, Merge, PresetStyle
output = table2ascii( header=["#", "G", "Merge", Merge.LEFT, "S"], body=[ [1, 5, 6, 200, Merge.LEFT], [2, "E", "Long cell", Merge.LEFT, Merge.LEFT], ["Bonus", Merge.LEFT, Merge.LEFT, "F", "G"], ], footer=["SUM", "100", "200", Merge.LEFT, "300"], style=PresetStyle.double_thin_box, first_col_heading=True, )
print(output)
""" βββββββ¦ββββββ€ββββββββ€ββββββ β # β G β Merge β S β β ββββββ¬ββββββͺββββ€ββββ§ββββββ£ β 1 β 5 β 6 β 200 β βββββββ«ββββββΌββββ΄ββββββββββ’ β 2 β E β Long cell β βββββββ¨ββββββ΄ββββ¬ββββ¬ββββββ’ β Bonus β F β G β β ββββββ¦ββββββ€ββββ§ββββͺββββββ£ β SUM β 100 β 200 β 300 β βββββββ©ββββββ§ββββββββ§ββββββ """ ```
All parameters are optional. At least one of header
, body
, and footer
must be provided.
Refer to the documentation for more information.
| Option | Supported Types | Description |
| :-----------------: | :-----------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |
| header
| Sequence[SupportsStr]
, None
(Default: None
) | First table row seperated by header row separator. Values should support str()
|
| body
| Sequence[Sequence[SupportsStr]]
, None
(Default: None
) | 2D List of rows for the main section of the table. Values should support str()
|
| footer
| Sequence[SupportsStr]
, None
(Default: None
) | Last table row seperated by header row separator. Values should support str()
|
| column_widths
| Sequence[Optional[int]]
, None
(Default: None
/ automatic) | List of column widths in characters for each column |
| alignments
| Sequence[Alignment]
, Alignment
, None
(Default: None
/ all centered) | Column alignments
(ex. [Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT, Alignment.DECIMAL]
) |
| number_alignments
| Sequence[Alignment]
, Alignment
, None
(Default: None
) | Column alignments for numeric values. alignments
will be used if not specified. |
| style
| TableStyle
(Default: double_thin_compact
) | Table style to use for the table* |
| first_col_heading
| bool
(Default: False
) | Whether to add a heading column separator after the first column |
| last_col_heading
| bool
(Default: False
) | Whether to add a heading column separator before the last column |
| cell_padding
| int
(Default: 1
) | The minimum number of spaces to add between the cell content and the cell border |
| use_wcwidth
| bool
(Default: True
) | Whether to use wcwidth instead of len()
to calculate cell width |
*See a list of all preset styles here.
See the API Reference for more info.
Contributions are welcome!
See CONTRIBUTING.md for more details on how to get involved.
Bumps sphinx-book-theme from 0.3.3 to 1.0.0.
Sourced from sphinx-book-theme's releases.
v1.0.0
This is a major release that brings in the latest PyData Sphinx Theme, Bootstrap 5, and updates many features.
See the Sphinx Book Theme changelog for details.
Contributors
@β12rambau
(activity) |@βAakashGfude
(activity) |@βakhmerov
(activity) |@βAllenDowney
(activity) |@βavivajpeyi
(activity) |@βbmorris3
(activity) |@βcholdgraf
(activity) |@βchrisjsewell
(activity) |@βconsideRatio
(activity) |@βfeanil
(activity) |@βfm75
(activity) |@βghutchis
(activity) |@βguillaume-haerinck
(activity) |@βhaklc
(activity) |@βiasbusi
(activity) |@βivirshup
(activity) |@βJames11222
(activity) |@βkloczek
(activity) |@βksuess
(activity) |@βmartinfleis
(activity) |@βmathbunnyru
(activity) |@βmcjulian1107
(activity) |@βmelund
(activity) |@βmmcky
(activity) |@βpaugier
(activity) |@βPhilipVinc
(activity) |@βpradyunsg
(activity) |@βrkdarst
(activity) |@βrossbar
(activity) |@βscmmmh
(activity) |@βsieler
(activity) |@βSilverRainZ
(activity) |@βstevepiercy
(activity) |@βtrallard
(activity) |@βwhyjz
(activity) |@βyuvipanda
(activity) |@βZedThree
(activity)v1.0.0rc3
See https://github.com/executablebooks/sphinx-book-theme/releases/tag/v1.0.0rc1 for release notes
v1.0.0rc2
See https://github.com/executablebooks/sphinx-book-theme/releases/tag/v1.0.0rc1 for release notes
v1.0.0rc1
A release candidate for
v1.0
of this theme. We're making it 1.0 because there are several major breaking changes!pip install -U --pre sphinx-book-theme
Leave comments in this issue:
Release notes (work in progress)
Enhancements made
- ENH: sphinx >=4,<6 #644 (
@βAakashGfude
)- ENH: Allowing inline elements in sidenotes and marginnotes #641 (
@βAakashGfude
)- ENH: Improve Chinese (Taiwan) and Chinese (China) translation #585 (
@βwhyjz
)Bugs fixed
- FIX: Scroll padding on top for anchor links #669 (
@βcholdgraf
)- π FIX: Correcting a broken link in CHANGELOG.md #623 (
@βAakashGfude
)- FIX: Scroll to active navigation item #609 (
@βksuess
)Maintenance and upkeep improvements
- MAINT: Update pre-commit versions and fix minor bugs in tests #660 (
@βcholdgraf
)- MAINT: Move dependabot updates to monthly #658 (
@βcholdgraf
)- MAINT: Factor publish to pypi workflow into dedicated file #645 (
@βcholdgraf
)- MAINT: Remove duplication with pydata-sphinx-theme #640 (
@βcholdgraf
)- MAINT: remove incorrect comment from sphinx pin. #588 (
@βrossbar
)Documentation improvements
... (truncated)
Sourced from sphinx-book-theme's changelog.
v1.0.0 -- 2023-03-01
This is a major release that brings in the latest PyData Sphinx Theme and a number of new features with it. It also overhauls and standardizes the HTML structure of the theme. Because of this large refactor, we are bumping the major version to
1.0
. Note that this doesn't imply any new long-term support or stability, we will continue to try not to make major breaking changes but will continue incrementing major versions if we must do so.Enhancements made
- PyData Sphinx Theme
v0.13
. See the PyData Sphinx Themev0.13
release notes for details.- Icon links, more source providers, and bug fixes #691 (
@βcholdgraf
,@βmmcky
)
- We now support GitHub, GitLab, and BitBucket source providers.
- You can now include lists of icon links in your primary sidebar.
- Allowing inline elements in sidenotes and marginnotes #641 (
@βAakashGfude
)- Improve Chinese (Taiwan) and Chinese (China) translation #585 (
@βwhyjz
)- sphinx >=4,<6 #644 (
@βAakashGfude
)Bugs fixed
- FIX: Scroll padding on top for anchor links #669 (
@βcholdgraf
)- π FIX: Correcting a broken link in CHANGELOG.md #623 (
@βAakashGfude
)- FIX: Scroll to active navigation item #609 (
@βksuess
)- [FIX] Use logo url as is to allow for web urls. #661 (
@βfeanil
)Maintenance and upkeep improvements
- MAINT: Update pre-commit versions and fix minor bugs in tests #660 (
@βcholdgraf
)- MAINT: Move dependabot updates to monthly #658 (
@βcholdgraf
)- MAINT: Factor publish to pypi workflow into dedicated file #645 (
@βcholdgraf
)- MAINT: Remove duplication with pydata-sphinx-theme #640 (
@βcholdgraf
)- MAINT: remove incorrect comment from sphinx pin. #588 (
@βrossbar
)- IntersectionObserver at 1/3 screen #567 (
@βcholdgraf
)Documentation improvements
- DOCS: Minor typo correction #649 (
@βbmorris3
)- DOC: Update kitchen sink #610 (
@βcholdgraf
)Breaking changes to structure and API
- UPGRADE/BREAKING: PyData v0.13 and HTML refactoring #677 (
@βcholdgraf
)- Remove JQuery and update versions #668 (
@βcholdgraf
)Tips for migration
Long sidebar entries now wrap. If you'd like to un-do this and revert to old behavior (where they are cut off if too long), then use the following CSS rule in your custom Sphinx CSS:
.bd-sidebar-primary a { word-wrap: unset; </tr></table>
... (truncated)
6601a2f
RLS 1.0.0: (repeat) Fix a link and improve test reliability (#701)b84dc6b
RLS: v1.0.0 (#699)6469079
PyData release update (#698)c98de28
ENH: Add translation to page element (#695)996fa65
RLS: v1.0.0rc39e2bc2f
NEH: Icon links, latest PST, more source providers, and bug fixes (#691)30d0c2d
Fix: logo image stretching vertically (#689)70e8ade
Better early return for add_launch_buttons if no launch buttons (#693)282f14e
RLS: v1.0.0rc27c2a378
ENH: Improvements after v1.0.0rc1 feedback (#687)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
py.typed
in package data for mypy to recognize types (https://github.com/DenverCoder1/table2ascii/pull/100)SupportsStr
are now importable directly through the table2ascii
module (https://github.com/DenverCoder1/table2ascii/pull/94)TableStyle.set()
example to one that will not throw an exception (https://github.com/DenverCoder1/table2ascii/pull/94)Full Changelog: https://github.com/DenverCoder1/table2ascii/compare/v1.1.0...v1.1.1
Alignment.DECIMAL
for aligning numbers to a decimal point in https://github.com/DenverCoder1/table2ascii/pull/90Alignment
instead of a list in https://github.com/DenverCoder1/table2ascii/pull/91number_alignments
to table2ascii
in https://github.com/DenverCoder1/table2ascii/pull/92pyproject.toml
in https://github.com/DenverCoder1/table2ascii/pull/87Full Changelog: https://github.com/DenverCoder1/table2ascii/compare/v1.0.4...v1.1.0
Full Changelog: https://github.com/DenverCoder1/table2ascii/compare/v1.0.3...v1.0.4
Full Changelog: https://github.com/DenverCoder1/table2ascii/compare/v1.0.2...v1.0.3
Full Changelog: https://github.com/DenverCoder1/table2ascii/compare/1.0.1...v1.0.2
Full Changelog: https://github.com/DenverCoder1/table2ascii/compare/1.0.0...1.0.1
πΊ https://youtube.com/DevProTips π» Full Stack Dev π¨ 12+ years of web dev & design π Always learning!
GitHub Repository Homepageunicode ascii utils utilities python markdown terminal discord discord-py formatter pretty-print graphics terminal-graphics hacktoberfest