Skip to main content

Server-side processing for DataTables and Editor using SQLAlchemy Core

Project description

DataTables Python server-side libraries

This is a collection of Python libraries to provide easy server-side support for the DataTables Javascript library - the Javascript table library.

These libraries provide support for:

  • Server-side processing - work with millions of rows
  • Editor - CRUD UI for DataTables
  • ColumnControl - Column search controls for DataTables
  • SearchBuilder - Complex search logic UI

SQLAlchemy Core is used to provide the SQL database integration, allowing a wide range of databases to be supported. Furthermore, the library is framework-agnostic: use it with Flask, FastAPI, Django, or any other Python web framework that can pass a request body and a SQLAlchemy Connection or Engine to a route handler.

Installation

pip install datatables_server

SQLAlchemy 2.x and Python date utilities are the two required dependencies for this library and are installed automatically with the above command. A database driver (e.g. psycopg2, pymysql, aiosqlite) must be installed separately.

Quick Start

The following shows a Flask endpoint that will accept both DataTables and Editor requests:

from flask import Flask, request, jsonify
from sqlalchemy import create_engine
from datatables_server import Editor, Field

app = Flask(__name__)
engine = create_engine("postgresql+psycopg2://user:pass@localhost/mydb")

@app.route("/api/staff", methods=["GET", "POST", "PUT", "DELETE"])
def staff():
    with engine.connect() as db:
        editor = (
            Editor(db, "staff", "id")
            .field(Field("first_name"))
            .field(Field("last_name"))
            .field(Field("position"))
            .field(Field("salary"))
        )
        response = editor.process(request.values.to_dict(flat=True))
    return jsonify(response)

Similarly, if your table is readonly, the DataTable and Column classes can be used (this will support DataTables' client-side or server-side processing modes):

from flask import Flask, request, jsonify
from sqlalchemy import create_engine
from datatables_server import DataTable, Column

app = Flask(__name__)
engine = create_engine("postgresql+psycopg2://user:pass@localhost/mydb")

@app.route("/api/staff", methods=["GET"])
def staff():
    with engine.connect() as db:
        table = (
            DataTable(db, "staff", "id")
            .column(Column("first_name"))
            .column(Column("last_name"))
            .column(Column("position"))
            .column(Column("salary"))
        )
        response = table.process()
    return jsonify(response)

Documentation

For full documentation, please refer to the DataTables site.

License

MIT — see LICENSE for full text.

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

datatables_server-3.0.0b1.tar.gz (79.6 kB view details)

Uploaded Source

Built Distribution

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

datatables_server-3.0.0b1-py3-none-any.whl (92.8 kB view details)

Uploaded Python 3

File details

Details for the file datatables_server-3.0.0b1.tar.gz.

File metadata

  • Download URL: datatables_server-3.0.0b1.tar.gz
  • Upload date:
  • Size: 79.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for datatables_server-3.0.0b1.tar.gz
Algorithm Hash digest
SHA256 47ebd8fecd992b414e09bc7722be80164888abb9ef7d68cd406d113475ed756c
MD5 a1cb8054a23499e27c3cfde21e0b6bc3
BLAKE2b-256 c1e094c1093f48125c6f31a85e9b13b5d24569d966bc8b868e750a5bd0318b97

See more details on using hashes here.

File details

Details for the file datatables_server-3.0.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for datatables_server-3.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 00ae0fd7dbb727f6b1dd3249df144fa566a59e648f140d9129d27fb9750bdc73
MD5 3ac025d828b7fa5c3cd7bdbd0c5c59ba
BLAKE2b-256 937ce956262eb90a4695812f350d82fcde9a2c65d1cd465da38e3a71f737fd67

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