This release is a pre-release and may not be stable for production use.
datatables-backend
Server-side processing for DataTables: paging, sorting, the global and column searches, and SearchBuilder criteria. Data can come from:
- SQL: SQLAlchemy 2, async or sync.
- OpenSearch: async or sync client.
The library is read-only and framework-agnostic.
Status: release candidate (0.1.0rc2). Until 1.0, a minor release (0.x) may break the Python API; each such change is listed in CHANGELOG.md. The wire format and the error codes change only in a release whose notes say so. See docs/PRD.md for the scope and design.
If you need a SQL backend with editing (DataTables Editor), use SpryMedia's own
datatables_server. This library adds:
- async SQLAlchemy;
- a search-engine backend;
- the same server-declared columns and safety rules on every source.
datatables-backend is not affiliated with or endorsed by DataTables or SpryMedia.
Install
pip installs no pre-release unless asked, so while 0.1.0 is a release candidate add --pre to each command.
pip install "datatables-backend[sqlalchemy]" # SQL, sync
pip install "datatables-backend[sqlalchemy-async]" # SQL, async (adds greenlet): also your async driver, e.g. asyncpg
pip install "datatables-backend[opensearch]" # OpenSearch, sync (installs opensearch-py)
pip install "datatables-backend[opensearch-async]" # OpenSearch, async (adds aiohttp)
pip install "datatables-backend[fastapi]" # the FastAPI dependency
SQL
from datatables_backend import Column, parse_request
from datatables_backend.sqlalchemy import SQLTable
users = SQLTable(
users_table, # a Table, join or subquery
[Column('id'), Column('email', field='email_address'), Column('joined')],
base_filter=users_table.c.active.is_(True), # rows the table shows at all
)
params = parse_request(request_json) # or the flat form/query parameters
async with AsyncSession(engine) as session:
response = await users.fetch(params, session) # fetch_sync() for a Session or Connection
return response.to_dict()
OpenSearch
from datatables_backend import Column
from datatables_backend.opensearch import IndexColumn, SearchTable
reports = SearchTable(
'reports',
[
IndexColumn('id', text='keyword'),
IndexColumn('title', text='text+keyword'), # the dynamic-mapping default
IndexColumn('body', text='text'), # analysed only: no sorting
Column('pages', type='number'),
Column('created', type='date'),
Column('published', type='boolean'), # a column is a string unless declared: the mapping is not read
],
unique_key='id', # required: an index has no primary key to break ties with
)
response = await reports.fetch(params, AsyncOpenSearch(hosts=['http://localhost:9200']))
The unique key. unique_key names a declared column (a tuple of names for a key of several) whose values are
unique for every document; OpenSearch needs it, since an index has no primary key to break ties with, and on SQL it
replaces the primary key. Its rules, the document _id and paging past the window are in the OpenSearch
rules.
FastAPI
from datatables_backend.fastapi import DataTablesParams
@app.post('/users/table')
async def users_table(params: DataTablesParams, session: SessionDep) -> dict[str, Any]:
return (await users.fetch(params, session)).to_dict()
On the page, DataTables' default POST (a form) is read as it comes, so the client needs no data or contentType:
new DataTable('#users', {
serverSide: true,
processing: true,
ajax: { url: '/users/table', type: 'POST' },
columns: [{ data: 'id' }, { data: 'email' }, { data: 'joined' }],
});
Options (TotalCache, RowHooks, page limits, a table per request for a per-user filter): docs/usage.md.
Tested with
CI runs the tests on Python 3.12 to 3.15 and on SQLite (sync, and async with aiosqlite); PostgreSQL 18 (psycopg 3, sync and async; psycopg2 with asyncpg); MySQL 8.4 (pymysql, aiomysql); SQL Server 2022 (pyodbc, aioodbc, ODBC Driver 18); and OpenSearch 3.10.0 and 2.19.7. It also runs the oldest supported releases: SQLAlchemy 2.0.31, Pydantic 2.10, opensearch-py 2.6 and FastAPI 0.133.
What the server decides
The library does not change how a database compares values. Each rule below is stated in full in docs/rules.md, and what each engine does on its own in docs/databases.md.
- Columns and ordering: only declared columns are used, the server decides what sorts, NULL is lowest, and a descending order is the exact reverse (one exception below).
- Types and matching: the declared type builds the filter, a date is matched by day, a day and a number have one spelling, and text matches in any case.
- Errors: a user's mistake comes back as a response with one of eight stable codes (the list is closed) and a text that says how to fix it; any other failure raises.
- Requests: bounded in length, lists, tree depth and conditions; a request the library cannot read
raises
MalformedRequest, answered 422 by the FastAPI dependency. - OpenSearch and SQL: the unique key, the document id, last pages, analysed text.
Exceptions to "no surprise", each with its reason in the rules:
- On OpenSearch, an order on a field of several values: descending is not the exact reverse of ascending.
- An OpenSearch column declared
text='text'has no whole string to sort by, so it is unorderable. - On PostgreSQL a column that can hold NULL needs its index declared
NULLS FIRSTto serve a sort. - A column that carries a time zone is matched by its UTC day; SQLite and MySQL
DATETIMEstore no offset. - SQLite, and OpenSearch before 3.1, fold ASCII letters only.
- A SQL column with a type of its own, or none, is compared as sent, not folded.
- On OpenSearch a page in the middle of more than
max_result_windowrows is refused (page_out_of_range), where the first and last pages work and SQL serves every page (paging past the window). - An OpenSearch column of analysed text only answers the word search,
contains,null,!nulland empty lists, where SQL answers every condition (the rule). - OpenSearch's global search skips number and date columns, and every backend's skips boolean columns (the rule).
- On OpenSearch a stored
""is not empty, where on SQL it is (the rule). - On OpenSearch a number outside its field's mapped range fails the request, a stated limit of this library (the entry, issue #47).
Development
uv sync
uv run pytest
uv run ruff check . && uv run basedpyright
Licence: MIT (LICENSE).
Metadata
Release files for datatables-backend 0.1.0rc2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datatables_backend-0.1.0rc2.tar.gz | 136.3 kB | With provenance | Details for datatables_backend-0.1.0rc2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datatables_backend-0.1.0rc2-py3-none-any.whl | Python 3 | none | any | Details for datatables_backend-0.1.0rc2-py3-none-any.whl |
Total release size: 190.8 kB
Release files / datatables_backend-0.1.0rc2.tar.gz
| Download URL | datatables_backend-0.1.0rc2.tar.gz |
|---|---|
| Size | 136.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8cc36ebdabc00f9fb2a535e11d373d4520843d4dfabaf210f43718f915c2f453
|
|
BLAKE2b-256 checksum How to use checksums |
52812286d6279d5e9a490460985c38b51af64d42b0e667d143f7dde46ca2817f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / datatables_backend-0.1.0rc2-py3-none-any.whl
| Download URL | datatables_backend-0.1.0rc2-py3-none-any.whl |
|---|---|
| Size | 54.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
557f7ab12431dccb3669cca7cc11d84a6866e16217298034d50a9f6341edbe8e
|
|
BLAKE2b-256 checksum How to use checksums |
282001406f19cf74ddc519a5e1b78a149cb619688ab078a53f6dfbcc306c6fb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for datatables-backend 0.1.0rc2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for datatables_backend-0.1.0rc2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.