$ show mwouts/itables
ITables is a Python library that transforms Pandas, Polars, and other DataFrame libraries into interactive, sortable, and filterable HTML tables using the DataTables.js library. It integrates seamlessly with Jupyter Notebook/Lab, VS Code, Colab, Quarto, and web frameworks like Dash, Streamlit, Shiny, and Panel. The architecture is a thin Python wrapper that generates HTML/JavaScript snippets, with a bundled JavaScript package (dt_for_itables) containing DataTables and its extensions. Key entry points include `itables.show()`, `itables.init_notebook_mode()`, and framework-specific components (e.g., `itables.dash.ITable`). Data flows from DataFrame to JSON serialization (with special handling for floats, categories, and large integers) to HTML template injection. External dependencies include DataTables.js (via CDN or offline bundle), optional Narwhals for multi-backend support, and framework-specific packages (Dash, Streamlit, etc.). The library also provides fallback static HTML and Markdown table rendering for environments without JavaScript.
The LLM identified 4 files worth highlighting for reuse:
Provides `datatables_rows()` and `generate_encoder()` for converting DataFrame rows to JSON with custom handling of floats (NaN, Inf), categorical columns (encoded as integer ranks for correct sorting), large integers, and mixed types. This is a non-obvious, reusable pattern for any system that needs to serialize DataFrames for JavaScript table libraries, handling edge cases that standard JSON serialization fails on.
Implements downsampling logic that reduces DataFrame rows and columns based on configurable byte size limits (`maxBytes`, `maxRows`, `maxColumns`). It calculates the approximate byte size of the JSON representation and trims the data accordingly, displaying a warning to the user. This pattern is reusable for any application that needs to limit the size of data sent to a frontend or stored in a notebook.
Defines typed dictionaries (`ITableOptions`, `DTForITablesOptions`) for all DataTables and ITables-specific options, with runtime type checking via `typeguard`. Supports loading options from TOML files (`itables.toml` or `pyproject.toml`). This is a clean, reusable pattern for managing complex configuration with validation, applicable to any Python library that needs user-configurable settings.
The main JavaScript module that creates the interactive table widget, handles dark mode detection across multiple ancestor documents (using MutationObserver), and manages the lifecycle of DataTables instances. It is designed to be reusable as a standalone widget for embedding DataTables in any web page, with robust theme detection and Shadow DOM support.