CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-itables

Python library that transforms Pandas and Polars DataFrames into interactive DataTables with sorting, pagination, and filtering capabilities.

Pending
Overview
Eval results
Files

core-display.mddocs/

Core Display Functions

Primary functions for rendering DataFrames as interactive tables in Jupyter environments. These functions provide the core functionality for transforming static DataFrames into interactive, sortable, filterable tables with pagination and search capabilities.

Capabilities

Interactive Table Display

Renders a DataFrame as an interactive datatable directly in Jupyter environments with automatic display using IPython's display system.

def show(df, caption=None, **kwargs):
    """
    Render the given DataFrame as an interactive datatable.

    Parameters:
    - df: Pandas/Polars DataFrame or Series to display
    - caption (str, optional): Table caption text
    - **kwargs: ITableOptions - Configuration options (see ITableOptions type)

    Returns:
    None (displays table directly)
    """

HTML Generation

Returns the HTML representation of a DataFrame as an interactive datatable without automatically displaying it, useful for custom rendering or saving to files.

def to_html_datatable(df, caption=None, **kwargs):
    """
    Return the HTML representation of the given DataFrame as an interactive datatable.

    Parameters:
    - df: Pandas/Polars DataFrame or Series to convert
    - caption (str, optional): Table caption text  
    - **kwargs: ITableOptions - Configuration options

    Returns:
    str: Complete HTML representation with embedded JavaScript
    """

Interactive Mode Initialization

Loads the DataTables JavaScript library and optionally activates interactive representation for all DataFrames in the notebook session.

def init_notebook_mode(all_interactive=True, connected=None, dt_bundle=None):
    """
    Load the DataTables library and activate interactive representation.

    Parameters:
    - all_interactive (bool): If True, make all DataFrames interactive by default
    - connected (bool, optional): If True, load DataTables from CDN; if False, use offline bundle (default: auto-detected based on environment)
    - dt_bundle (str | Path, optional): Custom path to DataTables bundle for offline mode

    Returns:
    None
    
    Note: Keep cell output when connected=False, otherwise tables will stop working
    """

Common Usage Examples

Basic Interactive Display

import pandas as pd
from itables import show

# Create sample data
df = pd.DataFrame({
    'Product': ['A', 'B', 'C', 'D'],
    'Sales': [100, 250, 300, 150],
    'Region': ['North', 'South', 'East', 'West']
})

# Display as interactive table
show(df, caption="Sales Data")

Custom Configuration

# Display with custom options
show(df, 
     pageLength=10,           # Show 10 rows per page
     scrollX=True,            # Enable horizontal scrolling
     column_filters="header", # Add column filters
     classes="display compact")  # Use compact styling

HTML Export

# Generate HTML for external use
html_output = to_html_datatable(df, 
                               caption="Exported Table",
                               connected=True)  # Use CDN for portability

# Save to file
with open('table.html', 'w') as f:
    f.write(html_output)

Global Interactive Mode

# Make all DataFrames interactive
init_notebook_mode(all_interactive=True, connected=False)

# Now all DataFrames display as interactive tables
df  # This will show as interactive table

# Polars DataFrames also supported
import polars as pl
polars_df = pl.DataFrame({'A': [1, 2, 3], 'B': ['x', 'y', 'z']})
polars_df  # Also displays as interactive table

Offline Mode Setup

from pathlib import Path

# Initialize with custom bundle path
init_notebook_mode(
    all_interactive=True,
    connected=False,
    dt_bundle=Path("custom/datatables.js")
)

Configuration Options

All display functions accept configuration options through keyword arguments. Common options include:

  • pageLength: Number of rows per page (default from options.py)
  • scrollX: Enable horizontal scrolling for wide tables
  • column_filters: Add column filters ("header", "footer", or False)
  • classes: CSS classes for table styling
  • showIndex: Control index column display ("auto", True, False)
  • maxRows: Maximum rows before downsampling (0 = unlimited)
  • maxColumns: Maximum columns before downsampling
  • allow_html: Allow HTML content in table cells (use with caution)

See Configuration Management for complete option details.

Install with Tessl CLI

npx tessl i tessl/pypi-itables

docs

configuration.md

core-display.md

data-utilities.md

framework-extensions.md

index.md

type-system.md

tile.json