A Python library for creating beautifully formatted terminal tables with Unicode borders, automatic text wrapping, and 30 predefined color schemes optimized for dark terminal backgrounds.
✨ Beautiful Unicode Tables - Clean box-drawing characters for professional-looking output
🎨 30 Color Schemes - Predefined themes from subtle to vibrant, all optimized for dark terminals
📏 Automatic Text Wrapping - Intelligent column width management and text wrapping
đź”§ Flexible Sizing - Independent or unified column sizing across multiple tables
🎯 Simple API - Easy-to-use functions for single tables, multiple tables, or auto-detection
⚡ High Performance - Efficient rendering with automatic terminal width detection
đź”™ Backward Compatible - Direct color overrides still supported alongside named schemes
pip install table-formatter
from table_formatter import format_table
data = [
["Alice", "25", "Engineer"],
["Bob", "30", "Designer"],
["Carol", "27", "Manager"]
]
print(format_table(data,
title="Team Members",
header=["Name", "Age", "Role"]))
from table_formatter import format_tables
tables = [{
'title': 'Project Status',
'header': ['Task', 'Status', 'Assignee'],
'data': [
['Database Design', 'Complete', 'Alice'],
['API Development', 'In Progress', 'Bob'],
['Frontend UI', 'Planned', 'Carol']
],
'color_scheme': 'matrix_green' # Use predefined color scheme
}]
print(format_tables(tables))
from table_formatter import format_tables
tables = [
{
'title': 'Q1 Sales',
'header': ['Product', 'Revenue'],
'data': [['Widget A', '$1,200'], ['Widget B', '$800']],
'color_scheme': 'blue_theme'
},
{
'title': 'Q2 Sales',
'header': ['Product', 'Revenue'],
'data': [['Widget A', '$1,500'], ['Widget B', '$950']],
'color_scheme': 'green_theme'
}
]
print(format_tables(tables, unified_sizing=True))
The library includes 30 professionally designed color schemes organized into categories:
subtle_alternating
- Light cyan/gray distinctionblue_theme
- Professional blue tonesgreen_theme
- Nature-inspired greenshigh_contrast
- Bold white/yellow alternationwarm_tones
- Orange/peach alternationpurple_theme
- Elegant purplesmonochrome_elegant
- Sophisticated graysminimal_contrast
- Very subtle distinctionteal_cyan_theme
- Cool water tonesclean_and_bright
- Vibrant but readable
matrix_green
- Retro terminal feelsunset
- Warm gradient feelocean_depths
- Deep blue themepastel_dream
- Soft and gentleneon_cyberpunk
- Electric bright
earth_tones
- Natural and groundingice_blue
- Cool and crispamber_terminal
- Retro monochromeforest
- Deep woodland greensroyal_purple
- Majestic and rich
fire_and_ice
- Dramatic contrastvintage_terminal
- Classic green on blackrose_gold
- Elegant warm metallicsmidnight_blue
- Deep night skycopper
- Warm metallic tones
lavender_fields
- Soft purple themeterminal_hacker
- Classic hacker aestheticcoral_reef
- Vibrant ocean colorssilver
- Metallic monochromerainbow
- Playful multicolor
from table_formatter import list_color_schemes, get_color_scheme
# List all available schemes
schemes = list_color_schemes()
for scheme in schemes:
print(f"{scheme['scheme_key']}: {scheme['name']} - {scheme['description']}")
# Get specific scheme details
matrix_colors = get_color_scheme('matrix_green')
print(matrix_colors)
# Output: {'even_row_fg': 46, 'odd_row_fg': 40, 'line_fg': 34, 'title_fg': 82, 'header_fg': 118}
In addition to foreground colors, the table formatter allows you to set background colors for each element. These can be specified in both predefined color schemes and manual overrides.
from table_formatter import format_tables
tables = [{
'title': 'Background Colors',
'header': ['Item', 'Value'],
'data': [['Row1', 'Value1'], ['Row2', 'Value2']],
'color_scheme': 'matrix_green',
'colors': {
'even_row_bg': 234, # Dark gray background for even rows
'odd_row_bg': 232, # Black background for odd rows
'header_bg': 240, # Gray background for header
'title_bg': 232 # Black background for title
}
}]
print(format_tables(tables))
tables = [{
'title': 'Custom Colors',
'header': ['Item', 'Value'],
'data': [['Alpha', '100'], ['Beta', '200']],
'color_scheme': 'blue_theme', # Base scheme
'colors': {
'header_fg': 226, # Override header to bright yellow
'odd_row_fg': 196, # Override odd rows to bright red
# Other colors will use blue_theme values
}
}]
long_data = [
["Product", "This is a very long description that will be automatically wrapped"],
["Service", "Short description"]
]
print(format_table(long_data,
title="Product Catalog",
header=["Type", "Description"],
max_width=50)) # Force wrapping at 50 characters
Format a single table with Unicode box-drawing characters.
Parameters:
data
(List[List[str]]): Table rowstitle
(str, optional): Title to display above the tableheader
(List[str], optional): Header column namesmax_width
(int, optional): Maximum table width (defaults to terminal width)
Returns: Formatted table as string
Format multiple tables with Unicode box-drawing characters.
Parameters:
tables
(List[Dict]): List of table dictionariesunified_sizing
(bool): Use same column widths across all tablestable_spacing
(int): Number of blank lines between tablesmax_width
(int, optional): Maximum table width
Table Dictionary Format:
{
'data': List[List[str]], # Required: table rows
'title': str, # Optional: table title
'header': List[str], # Optional: header columns
'color_scheme': str, # Optional: predefined color scheme name
'colors': Dict[str, int], # Optional: manual color overrides
}
Returns: Formatted tables as string
Auto-detect single vs multiple tables and format accordingly.
List all available color schemes with names and descriptions.
Returns: List of dictionaries with scheme info
Get color values for a specific scheme.
Parameters:
scheme_name
(str): Name of the color scheme
Returns: Dictionary of color values or None if not found
Load color schemes from YAML file (with caching).
Parameters:
color_schemes_file
(str, optional): Path to YAML file
Returns: Dictionary of all color schemes
Each color scheme defines these properties:
even_row_fg
- Foreground color for even rows (0, 2, 4, ...)odd_row_fg
- Foreground color for odd rows (1, 3, 5, ...)line_fg
- Foreground color for borders and separatorstitle_fg
- Foreground color for table titlesheader_fg
- Foreground color for header text
even_row_bg
- Background color for even rows (0, 2, 4, ...)odd_row_bg
- Background color for odd rows (1, 3, 5, ...)line_bg
- Background color for borders and separatorstitle_bg
- Background color for table titlesheader_bg
- Background color for header text
Colors use ANSI 256-color codes (0-255) or null
for default terminal colors.
- Python 3.8+
- PyYAML 6.0+
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Initial release
- 30 predefined color schemes
- Unicode table formatting
- Automatic text wrapping
- Multiple table support with unified sizing
- Color scheme system with YAML configuration