https://github.com/mrjohannchang/columnify.py
Creating text-based columnized (ls-like) content suitable for console output from list of strings.
https://github.com/mrjohannchang/columnify.py
alignment column library ls-like python terminal text-editing
Last synced: 5 months ago
JSON representation
Creating text-based columnized (ls-like) content suitable for console output from list of strings.
- Host: GitHub
- URL: https://github.com/mrjohannchang/columnify.py
- Owner: mrjohannchang
- License: mpl-2.0
- Created: 2022-07-21T06:00:17.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-25T14:05:10.000Z (almost 4 years ago)
- Last Synced: 2025-09-18T22:48:10.981Z (8 months ago)
- Topics: alignment, column, library, ls-like, python, terminal, text-editing
- Language: Python
- Homepage: https://pypi.org/project/columnify/
- Size: 22.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# columnify
Inspired by [columnify](https://github.com/timoxley/columnify).
`columnify` creates text-based columnized (ls-like) content suitable for console output from list of strings.
Columns are automatically resized to fit the content of the largest cell. Each cell will be padded with spaces to fill the available space and ensure column contents are aligned.
**Table of Contents**
- [Examples](#examples)
- [Installation](#installation)
- [API](#api)
- [Methods](#methods)
- [License](#license)
## Examples
```py
items: list[str] = [
"Canidae", "Felidae", "Cat", "Cattle", "Dog",
"Donkey", "Goat", "Guinea pig", "Horse", "Pig",
"Rabbit", "Fancy rat varieties", "laboratory rat strains",
]
```
### Default
```text
Canidae Cat Dog Goat Horse Rabbit laboratory rat strains
Felidae Cattle Donkey Guinea pig Pig Fancy rat varieties
```
### Horizon first
```text
Canidae Felidae Cat Cattle Dog Donkey Goat
Guinea pig Horse Pig Rabbit Fancy rat varieties laboratory rat strains
```
### center()
```text
Canidae Cat Dog Goat Horse Rabbit laboratory rat strains
Felidae Cattle Donkey Guinea pig Pig Fancy rat varieties
```
### rjust()
```text
Canidae Cat Dog Goat Horse Rabbit laboratory rat strains
Felidae Cattle Donkey Guinea pig Pig Fancy rat varieties
```
### Custom delimiter ( | )
```text
Canidae | Cattle | Goat | Pig | laboratory rat strains
Felidae | Dog | Guinea pig | Rabbit
Cat | Donkey | Horse | Fancy rat varieties
```
### Indent (4 spaces):
```text
Canidae Cattle Goat Pig laboratory rat strains
Felidae Dog Guinea pig Rabbit
Cat Donkey Horse Fancy rat varieties
```
See `examples/example.py` for more information.
## Installation
```console
pip install columnify
```
## API
### Methods
```py
def columnify(
items: list[str],
line_width: int,
indent: int = 0,
delimiter: str = ' ',
align_func_name: str = 'ljust',
horizon_first: bool = False) -> str:
...
```
## License
`columnify` is distributed under the terms of the [MPL-2.0](https://spdx.org/licenses/MPL-2.0.html) license.