Skip to main content

dt2 — DataTables v2 for Shiny for Python dt2 hex logo

CI PyPI Python versions Docs License R package: DT2

A Python port of the R DT2 package: an anywidget binding for DataTables v2, designed for Shiny for Python (and usable in Jupyter).

It configures DataTables via plain Python (1:1 with the JS API), reusing the same DataTables runtime (2.3.4) and extensions as the R package.

📖 Documentation: https://strategicprojects.github.io/dt2py/ · 📦 PyPI: https://pypi.org/project/dt2/

Status: feature-complete toward R parity, pre-release. Config, all 15 extensions, server-side processing, proxy, events and inline inputs are implemented and unit-tested. The live in-browser Comm transport has not yet been visually verified. See ROADMAP.md and CHANGELOG.md.

Install (dev)

npm install && npm run build        # build the JS bundle into src/dt2/static/
uv venv && uv pip install -e ".[shiny,pandas]"

(The built bundle is committed, so an installed wheel needs no Node toolchain.)

Quick start

import pandas as pd
from shiny import App, ui
from shinywidgets import output_widget, render_widget
from dt2 import dt2

df = pd.read_csv("data.csv")

app_ui = ui.page_fluid(output_widget("tbl"))

def server(input, output, session):
    @render_widget
    def tbl():
        return dt2(df, select=True, pageLength=10)

app = App(app_ui, server)

Configure with Options

Chainable builder mirroring the R pipe helpers:

from dt2 import Options, JS, dt2

opts = (Options(df)
        .cols_align(["revenue"], "right")
        .format_number(["revenue"], thousands=".", decimal=",", digits=2, prefix="R$ ")
        .format_datetime(["updated"], from_="YYYY-MM-DD", to="DD/MM/YYYY")
        .cols_render(["score"], JS("function(d,t){ return t==='display' ? d+'%' : d; }"))
        .order(("revenue", "desc"))
        .length_menu([10, 25, -1]))

dt2(df, options=opts)

JS(...) is the parity for htmlwidgets::JS(): the source is revived into a real function in the browser, with DataTable, $ and moment in scope.

Extensions

All 15 DataTables extensions are bundled; activate via Options:

opts = (Options(df)
        .buttons(["copyHtml5", "csvHtml5", "excelHtml5"])  # jszip bundled; PDF needs pdfmake
        .select({"style": "os"})
        .responsive()
        .fixed_header()
        .row_group("field"))

dt2.extensions() lists what is bundled.

Server-side processing

Keep large data Python-side; DataTables fetches pages over the Comm:

dt2(big_df, server_side=True, pageLength=25)

Filtering/ordering/paging run in dt2.server.process_ssp.

Proxy, events and inline inputs

# proxy (Python -> table): call on the rendered widget
tbl.widget.search("ada")
tbl.widget.order(("field", "desc"))
tbl.widget.select_rows([1, 3])

# events (table -> Python): read reactively
from shinywidgets import reactive_read
reactive_read(tbl.widget, "selected_rows")  # also: state, row_check, row_button

# inline row inputs
opts = Options(df).col_checkbox("select", value_col="active").col_button("act", label="Ping")

See examples/ for runnable apps: app.py, app_config.py, app_extensions.py, app_serverside.py, app_proxy_inputs.py.

How it relates to the R package

The DataTables runtime is shared conceptually with R DT2. What differs is the transport: R talks to Shiny via window.Shiny; here the widget talks to the Python kernel over the anywidget Comm, bridged to Shiny reactivity by shinywidgets. The htmlwidgets::JS() mechanism becomes the JS() marker + client-side reviver. See the header of js/index.js for the full mapping.

Authors

  • André Leite (maintainer) — Universidade Federal de Pernambuco
  • Hugo Vasconcelos — Universidade Federal de Pernambuco
  • Diogo Bezerra — Universidade Federal de Pernambuco
  • Marcos Wasiliew
  • Carlos Amorim — Universidade Federal de Pernambuco

License

MIT © André Leite

Download files

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

Source Distribution

dt2-0.1.1.tar.gz (275.2 kB view details)

Uploaded Source

Built Distribution

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

dt2-0.1.1-py3-none-any.whl (246.5 kB view details)

Uploaded Python 3

File details

Details for the file dt2-0.1.1.tar.gz.

File metadata

  • Download URL: dt2-0.1.1.tar.gz
  • Upload date:
  • Size: 275.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for dt2-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fcb79b670eb58ad8390401788150c6f058ff719260f588abd545a893bce93e0f
MD5 7f399caae491f29b327f04a2a6ee037f
BLAKE2b-256 ce8ea2be5fcd250eb5c039cb5a097943cb9b2fb7eb1f9a4ae8c4a00707bc68ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for dt2-0.1.1.tar.gz:

Publisher: release.yml on StrategicProjects/dt2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dt2-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dt2-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 246.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for dt2-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e87a0973463d9b784e7fa7109bf6d59d1935b6252d03c88403234fa222f4515d
MD5 615b356af50f76b675543980779f0edf
BLAKE2b-256 0b382fc28f43aab7d6b6fb8d3a5151abaa91922bffcadbf0eaede3c45532fbb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for dt2-0.1.1-py3-none-any.whl:

Publisher: release.yml on StrategicProjects/dt2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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