Skip to main content

Enhanced display utilities for Jupyter/Colab notebooks with customizable styles

Project description

Colab Print

PyPI version Python versions License

Colab Print is a Python library that enhances the display capabilities of Jupyter and Google Colab notebooks, providing beautiful, customizable HTML outputs for text, lists, dictionaries, tables, and pandas DataFrames.

Features

  • 🎨 Rich Text Styling - Display text with predefined styles or custom CSS
  • 📊 Beautiful DataFrame Display - Present pandas DataFrames with extensive styling options
  • 📑 Customizable Tables - Create HTML tables with headers, rows, and custom styling
  • 📜 Formatted Lists - Display Python lists and tuples as ordered or unordered HTML lists.
  • 📖 Readable Dictionaries - Render dictionaries as structured definition lists.
  • 🎭 Extensible Themes - Use built-in themes or create your own custom styles
  • 📏 Smart Row/Column Limiting - Automatically display large DataFrames with sensible limits
  • 🔍 Cell Highlighting - Highlight specific rows, columns, or individual cells in tables and DataFrames
  • 🔄 Graceful Fallbacks - Works even outside Jupyter/IPython environments

Installation

pip install colab-print

Quick Start

from colab_print import Printer
import pandas as pd

# Create a printer with default styles
printer = Printer()

# Display styled text
printer.display("Hello, World!", style="highlight")

# Display a list
my_list = ['apple', 'banana', ['nested', 'item'], 'cherry']
printer.display_list(my_list, ordered=True, style="info")

# Display a dictionary
my_dict = {
    'name': 'Alice', 
    'age': 30, 
    'address': {'street': '123 Main St', 'city': 'Anytown'}
}
printer.display_dict(my_dict, style="success")

# Display a simple table
headers = ["Name", "Age", "City"]
rows = [
    ["Alice", 28, "New York"],
    ["Bob", 34, "London"],
    ["Charlie", 22, "Paris"]
]
printer.display_table(headers, rows, style="default")

# Display a pandas DataFrame with styling
df = pd.DataFrame({
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [28, 34, 22],
    'City': ['New York', 'London', 'Paris']
})
printer.display_df(df, 
                  highlight_cols=['Name'],
                  highlight_cells={(0, 'Age'): "background-color: #FFEB3B;"},
                  caption="Sample DataFrame")

Styling Options

Predefined Styles

  • default - Clean, professional styling
  • highlight - Stand-out text with emphasis
  • info - Informational blue text
  • success - Positive green message
  • warning - Attention-grabbing yellow alert
  • error - Critical red message
  • muted - Subtle gray text

Custom Styling

You can add your own styles:

printer = Printer()
printer.add_style("custom", "color: purple; font-size: 20px; font-weight: bold;")
printer.display("Custom styled text", style="custom")

Display Methods

  • printer.display(text, style="default", **inline_styles): Displays styled text.
  • printer.display_list(items, ordered=False, style="default", item_style=None, **inline_styles): Displays lists/tuples.
  • printer.display_dict(data, style="default", key_style=None, value_style=None, **inline_styles): Displays dictionaries.
  • printer.display_table(headers, rows, style="default", **table_options): Displays basic tables.
  • printer.display_df(df, style="default", **df_options): Displays pandas DataFrames with many options.

DataFrame Display Options

The display_df method supports numerous customization options:

printer.display_df(df,
                  style='default',           # Base style
                  max_rows=20,               # Max rows to display
                  max_cols=10,               # Max columns to display
                  precision=2,               # Decimal precision for floats
                  header_style="...",        # Custom header styling
                  odd_row_style="...",       # Custom odd row styling
                  even_row_style="...",      # Custom even row styling
                  index=True,                # Show index
                  width="100%",              # Table width
                  caption="My DataFrame",    # Table caption
                  highlight_cols=["col1"],   # Highlight columns
                  highlight_rows=[0, 2],     # Highlight rows
                  highlight_cells={(0,0): "..."}, # Highlight specific cells
                  font_size="14px",          # Custom font size for all cells
                  text_align="center")       # Text alignment for all cells

Advanced Usage

Creating Custom Themes

custom_themes = {
    'dark': 'color: white; background-color: #333; font-size: 16px;',
    'fancy': 'color: #8A2BE2; font-family: "Brush Script MT", cursive; font-size: 20px;'
}

printer = Printer(additional_styles=custom_themes)
printer.display("Dark theme", style="dark")
printer.display("Fancy theme", style="fancy")

Handling Non-Notebook Environments

The library gracefully handles non-IPython environments by printing fallback text representations:

# This will work in regular Python scripts
printer.display_list([1, 2, 3])
printer.display_dict({'a': 1})
printer.display_df(df)

Full Examples

For a comprehensive demonstration of all features, please see the example script:

example.py

This script covers:

  • Text, List, Dictionary, Table, and DataFrame display
  • Using built-in styles and inline styles
  • Adding custom styles
  • Creating a Printer instance with custom themes
  • Highlighting options for DataFrames
  • Fallback behavior notes (though the script runs outside a notebook)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

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

Source Distribution

colab_print-0.1.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

colab_print-0.1.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file colab_print-0.1.0.tar.gz.

File metadata

  • Download URL: colab_print-0.1.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.16

File hashes

Hashes for colab_print-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f798d4d5ffcd1840f3c4d114b7c1e737130ebd8349a5cabe569f42bdb73b9318
MD5 a2125ce33cb4ccfcdb6204690141855f
BLAKE2b-256 413479e18533122bfd9e29ed3c344c0f5e9382c09f60fc998fc3fd1210e9a4f6

See more details on using hashes here.

File details

Details for the file colab_print-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for colab_print-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9101ba8a79a20e8db28f76512bb097541efb1bc27c8295ed75190fc190f5000
MD5 71ee55a1d0b7998750d37d8df7c3e6bd
BLAKE2b-256 75024de7a6e89fdea09506e16e7c2d9089e9d6c5bc696de6c01b48eb66053d14

See more details on using hashes here.

Supported by

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