Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nschloe/termtables
:desktop_computer: Pretty tables in the terminal
https://github.com/nschloe/termtables
pypi python table terminal
Last synced: 10 days ago
JSON representation
:desktop_computer: Pretty tables in the terminal
- Host: GitHub
- URL: https://github.com/nschloe/termtables
- Owner: nschloe
- License: gpl-3.0
- Created: 2019-07-06T11:15:34.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-27T07:23:46.000Z (over 3 years ago)
- Last Synced: 2024-05-12T00:42:25.885Z (9 months ago)
- Topics: pypi, python, table, terminal
- Language: Python
- Homepage:
- Size: 137 KB
- Stars: 97
- Watchers: 2
- Forks: 5
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
The tables have termed.
[](https://pypi.org/project/termtables)
[](https://pypi.org/pypi/termtables/)
[](https://github.com/nschloe/termtables)
[](https://pypistats.org/packages/termtables)[](https://github.com/nschloe/termtables/actions?query=workflow%3Aci)
[](https://codecov.io/gh/nschloe/termtables)
[](https://lgtm.com/projects/g/nschloe/termtables)
[](https://github.com/psf/black)termtables is a lightweight Python 3 package for pretty-printing tables on the command
line. Install with
```
pip install termtables
```
The code
```python
import termtables as tt
import numpynumpy.random.seed(0)
data = numpy.random.rand(5, 2)tt.print(data)
# tt.to_string(data) returns the string
```
produces
You can control border style, padding, alignment, and various other attributes. For
example,
```python
import termtables as ttheader = ["a", "bb", "ccc"]
data = [
[1, 2, 3], [613.23236243236, 613.23236243236, 613.23236243236]
]tt.print(
data,
header=header,
style=tt.styles.markdown,
padding=(0, 1),
alignment="lcr"
)
```
produces```
| a | bb | ccc |
|-----------------|-----------------|-----------------|
| 1 | 2 | 3 |
| 613.23236243236 | 613.23236243236 | 613.23236243236 |
```
which is useful for copy-pasting into websites that support Markdown (like GitHub).See
[`test/test_termtables.py`](https://github.com/nschloe/termtables/blob/master/test/test_termtables.py)
for more examples.If the styles in `termtables.styles`
```
thin
thin_thick
thin_double
rounded
rounded_thick
rounded_double
thick
thick_thin
double
double_thin
booktabsascii_thin
ascii_thin_double
ascii_double
ascii_double_thin
ascii_booktabsmarkdown
```
aren't good enough for you, simply provide your own
style as a string of length 11 or 15 (the extra 4 including header-separating
characters). For example
```python
import termtables as ttheader = ["a", "bb", "ccc"]
data = [
[1, 2, 3], [613.23236243236, 613.23236243236, 613.23236243236]
]tt.print(
data,
header=header,
style="x0123456789abcd"
)
```
produces```
1xxxxxxxxxxxxxxxxx7xxxxxxxxxxxxxxxxx7xxxxxxxxxxxxxxxxx2
0 a 0 bb 0 ccc 0
abbbbbbbbbbbbbbbbbcbbbbbbbbbbbbbbbbbcbbbbbbbbbbbbbbbbbd
0 1 0 2 0 3 0
5xxxxxxxxxxxxxxxxx9xxxxxxxxxxxxxxxxx9xxxxxxxxxxxxxxxxx6
0 613.23236243236 0 613.23236243236 0 613.23236243236 0
3xxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxx4
```### Testing
To run the termtables unit tests, check out this repository and type
```
tox
```### Other software for terminal tables
* [Rich](https://github.com/willmcgugan/rich)
### License
This software is published under the [GPL-3.0
license](https://www.gnu.org/licenses/gpl-3.0.en.html).