Skip to main content

sqlalchemy2-datatables

versions license badge badge

Summary

sqlalchemy2-datatables is a framework agnostic library providing an SQLAlchemy integration of jQuery DataTables >= 1.10, and helping you manage server side requests in your application.

Inspiration

This project was inspired by sqlalchemy-datatables developed by Michel Nemnom aka Pegase745.

Motivation

Given the sunstantial changes with SQLAlchemy 2.0 most of not all of the SQLAlchemy based datatables serverside solution will be outdated soon (labeit currently still supported in SQLAlchemy 1.4). Specifically deprecation of sqlalchemy.orm.Query will render those packages obsolete. SQLAlchemy2.0.

Installation

pip install sqlalchemy2-datatables

Examples

Generic CRUD style function:

from typing import Any
from sqlalchemy import Engine
from sqlalchemy import FromClause

from datatables import DataTable
from datatables.base import DTDataCallbacks

def get_datatable_result(
    params: dict[str, Any],
    table: FromClause,
    column_names: list[str],
    engine: Engine,
    callbacks: DTDataCallbacks | None,
) -> dict[str, Any]:
    """
    Get database results specifically formatted for a display via jQuery datatables.
    :param params: dict - request parameters
    :param table: FromClause - the sqlalchemy from clause
    :param column_names - List of column names reflecting the table columns in the desired order
    :param engine: Engine -  the sqlalchemy engine
    :param callbacks - datatables callbacks to populate jQuery datatables DT_* attributes
    :return dict with DataTable output for the jQuery datatables in the frontend view
    """
    datatable: DataTable = DataTable(
        request_params=params,
        table=table,
        column_names=column_names,
        engine=engine,
        callbacks=callbacks
    )
    return datatable.output_result()

The output dictionary that can be serialized and returned to jQuery datatables.

{
    "start": 0,
    "length": 5,
    "draw": 1,
    "recordsTotal": 1000,
    "recordsFiltered": 1000,
    "data": [
        {
            "id": 1,
            "col1": "value",
            "col2": "value",
            "col3": "value",
            "col4": "value",
        },
        {
            "id": 2,
            "col1": "value",
            "col2": "value",
            "col3": "value",
            "col4": "value",
        },
        {
            "id": 3,
            "col1": "value",
            "col2": "value",
            "col3": "value",
            "col4": "value",
        },
        {
            "id": 4,
            "col1": "value",
            "col2": "value",
            "col3": "value",
            "col4": "value",
        },
        {
            "id": 5,
            "col1": "value",
            "col2": "value",
            "col3": "value",
            "col4": "value",
        },
    ],
}

Release files for sqlalchemy2-datatables 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy2-datatables 0.6.2
File Size Uploaded
sqlalchemy2_datatables-0.6.2.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy2-datatables 0.6.2
File Interpreter ABI Platform
sqlalchemy2_datatables-0.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 kB

Release files / sqlalchemy2_datatables-0.6.2.tar.gz

Download URL sqlalchemy2_datatables-0.6.2.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8d20ae44893c932a159675c1d547228283502d29458e53901b74535d3c30788a
BLAKE2b-256 checksum
How to use checksums
9c8c79847670b349f6fdf42abc363a7edf5f6d65c5e4c50e33055afc2a0bf77d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.0

Release files / sqlalchemy2_datatables-0.6.2-py3-none-any.whl

Download URL sqlalchemy2_datatables-0.6.2-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89e028b128665f2df06075285d67ebb496d0c053badbbd6805d5d3839a95919a
BLAKE2b-256 checksum
How to use checksums
8b3ba913ca939d547187d099ae9c40555b2ec0783a247e0d9e1f0954cb461ac3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.0

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.6.0

3 release files

0.5.4

2 release files

0.5.2

3 release files

0.5.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page