Skip to main content

delta-trace-db

(en)Japanese ver is here.
(ja) この解説の日本語版はここ にあります。

Overview

DeltaTraceDB is a lightweight and high-performance in-memory NoSQL database that stores and searches class structures as-is.
Although it is NoSQL, it also supports full-text search across nested child objects.

Queries in DeltaTraceDB are also represented as classes.
By serializing and storing these query objects, you can not only restore the database to any past state,
but also keep operation metadata such as who / when / what / why / from.
This allows you to build rich and highly detailed operation logs suitable for security audits and usage analysis.

Features

  • Store and search classes directly (your model classes define the DB structure)
  • High-speed search performance even with ~100,000 records
  • Queries are classes, making it easy to preserve operation logs
  • Exact decimal / rational comparison and sorting with identical results in Dart and Python
    (EnumValueType.decimal_ / rational_, using simple_portable_numeric).
    Store such values as strings (e.g. "10.50"), not as numbers.
  • There is a Dart version for the front end.
    → https://pub.dev/packages/delta_trace_db
  • GUI editor for DB content is under available.
    → https://github.com/MasahideMori-SimpleAppli/delta_trace_studio

Basic Operations

For detailed usage, including how to write queries, see the documentation:

📘 Online Documentation

Quickstart

Here's a simple example of server-side code:
ServerSide Example

And here's a simple example:

from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Dict, Any
from file_state_manager import CloneableFile
from delta_trace_db import DeltaTraceDatabase, QueryBuilder


@dataclass
class User(CloneableFile):
    id: int
    name: str
    age: int
    created_at: datetime
    updated_at: datetime
    nested_obj: dict

    @classmethod
    def from_dict(cls, src: Dict[str, Any]) -> "User":
        return User(
            id=src["id"],
            name=src["name"],
            age=src["age"],
            created_at=datetime.fromisoformat(src["createdAt"]).astimezone(timezone.utc),
            updated_at=datetime.fromisoformat(src["updatedAt"]).astimezone(timezone.utc),
            nested_obj=dict(src["nestedObj"]),
        )

    def to_dict(self) -> Dict[str, Any]:
        return {
            "id": self.id,
            "name": self.name,
            "age": self.age,
            "createdAt": self.created_at.astimezone(timezone.utc).isoformat(),
            "updatedAt": self.updated_at.astimezone(timezone.utc).isoformat(),
            "nestedObj": dict(self.nested_obj),
        }

    def clone(self) -> "User":
        return User.from_dict(self.to_dict())


def main():
    db = DeltaTraceDatabase()
    now = datetime.now(timezone.utc)

    users = [
        User(
            id=-1,
            name="Taro",
            age=30,
            created_at=now,
            updated_at=now,
            nested_obj={"a": "a"},
        ),
        User(
            id=-1,
            name="Jiro",
            age=25,
            created_at=now,
            updated_at=now,
            nested_obj={"a": "b"},
        ),
    ]

    # If you want the return value to be reflected immediately on the front end,
    # set return_data = True to get data that properly reflects the serial key.
    query = (
        QueryBuilder.add(
            target="users",
            add_data=users,
            serial_key="id",
            return_data=True,
        )
        .build()
    )

    # In the Python version, no type specification is required (duck typing)
    r = db.execute_query(query)

    # If you want to check the return value, you can easily do so by using toDict, which serializes it.
    print(r.to_dict())

    # You can easily convert from the Result object back to the original class.
    # The value of r.result is deserialized using the function specified by convert.
    results = r.convert(User.from_dict)


if __name__ == "__main__":
    main()

DB structure

In DeltaTraceDB, each collection corresponds to a list of class instances.
Since the data structure directly mirrors your class definitions,
it becomes easy to keep consistency between the frontend and backend while
focusing solely on retrieving the class objects you need.

📦 Database (DeltaTraceDB)
├── 🗂️ CollectionA (key: "collection_a")
│   ├── 📄 Item (ClassA)
│   │   ├── id: int
│   │   ├── name: String
│   │   └── timestamp: String
│   └── ...
├── 🗂️ CollectionB (key: "collection_b")
│   ├── 📄 Item (ClassB)
│   │   ├── uid: String
│   │   └── data: Map<String, dynamic>
└── ...

Performance

DeltaTraceDB is fast due to its in-memory design. Although it has no dedicated optimization mechanisms at the moment, its performance is roughly equivalent to a simple for loop over the data. Around 100,000 records can typically be handled without issues.

You can run performance tests using:

tests/test_speed.py

Below is an example result from a Ryzen 5 3500 machine (Python 3.12.3):

tests/test_speed.py speed test for 100000 records
start add
end add: 343 ms
start getAll (with object convert)
end getAll: 668 ms
returnsLength: 100000
start save (with json string convert)
end save: 474 ms
start load (with json string convert)
end load: 573 ms
start search (with object convert)
end search: 912 ms
returnsLength: 100000
start search paging, half limit pre search (with object convert)
end search paging: 458 ms
returnsLength: 50000
start searchOne, the last index object search (with object convert)
end searchOne: 37 ms
returnsLength: 1
start update at half index and last index object
end update: 94 ms
start updateOne of half index object
end updateOne: 18 ms
start conformToTemplate
end conformToTemplate: 83 ms
start delete half object (with object convert)
end delete: 667 ms
returnsLength: 50000
start deleteOne for last object (with object convert)
end deleteOne: 22 ms
returnsLength: 1
start add with serialKey
end add with serialKey: 99 ms
addedCount:100000
.aggregate speed test for 100000 records
start aggregate count_ with condition
end aggregate count_ with condition: 32 ms
result:{'count_': 50000}
start aggregate sum_, min_, max_, mean_ (floatStrict_, number values)
end aggregate sum_, min_, max_, mean_ (floatStrict_, number values): 200 ms
result:{'sum_score': 2499975000.0, 'min_score': 0.0, 'max_score': 49999.5, 'mean_score': 24999.75}
start aggregate sum_, min_, max_, mean_ (decimal_, string values)
end aggregate sum_, min_, max_, mean_ (decimal_, string values): 1117 ms
result:{'sum_price': '49999500.00', 'min_price': '0.00', 'max_price': '999.99', 'mean_price': '500.00'}
start aggregate sum_, min_, max_, mean_ (rational_, string values)
end aggregate sum_, min_, max_, mean_ (rational_, string values): 1598 ms
result:{'sum_price': '49999500', 'min_price': '0', 'max_price': '99999/100', 'mean_price': '99999/200'}
start getAll with SingleSort (decimal_, reversed)
end getAll with SingleSort (decimal_, reversed): 8310 ms
result:{'status': 'cancel', 'price': '999.99', 'score': 49999.5, 'customer': 'C199', 'date': '2026-11-26T10:30:00'}
start aggregate count_, sum_ grouped by customer
end aggregate count_, sum_ grouped by customer: 370 ms
result:{'customer': 'C121', 'count_': 500, 'sum_score': 12505250.0}
start aggregate count_, sum_ grouped by month of date-time strings
end aggregate count_, sum_ grouped by month of date-time strings: 595 ms
result:{'date': '2026-06', 'count_': 4320, 'sum_score': 165161160.0}
start getAll with SingleSort (datetime_)
end getAll with SingleSort (datetime_): 5471 ms
result:{'status': 'paid', 'price': '0.00', 'score': 0.0, 'customer': 'C000', 'date': '2025-01-01T00:00:00'}

With decimal_, rational_ and datetime_, values are converted at each comparison, so sorting by these types is much slower than sorting numbers.

Future plans

Although further optimization is possible, performance improvements have lower priority.
The focus will instead be on improving usability and developing surrounding tools.

Notes

This package is designed for single-threaded environments.
When using parallel processing without shared memory, additional mechanisms such as message passing are required.

Value conversion (vType)

When vType is specified, values are converted with the same rules in the Dart and Python versions, so the same query gives the same result in both.

  • Numeric strings follow Dart's int.parse / double.parse: surrounding whitespace is ignored, int_ accepts 0x hexadecimal numbers ("0x10" is 16), and "1_000", "inf" and non-ASCII digits (e.g. full-width digits) are not converted.
  • datetime_ accepts only valid ISO 8601 date-times. Values such as month 13 or hour 24 are not converted.
  • A value that cannot be converted makes a comparison false, and is sorted as null (to the end in ascending order).
  • Timezone-aware and naive date-times are not compared with each other (treated as a conversion failure). Store date-times in UTC, or use naive_utc_offset_minutes (e.g. 540 for UTC+9) to interpret naive values.
  • In a MultiSort, v_type and naive_utc_offset_minutes are set on each SingleSort, and the rules above apply to each of them.

Support

This package is developed and maintained by me personally as an open-source project.
For bug reports and feature requests, please use GitHub Issues.

If you need paid support, consulting, or custom development
(e.g. priority support, design advice, or implementation help), please contact my company:

SimpleAppli Inc.
https://simpleappli.com/en/index_en.html

About version control

The C part will be changed at the time of version upgrade.
However, versions less than 1.0.0 may change the file structure regardless of the following rules.

  • Changes such as adding variables, structure change that cause problems when reading previous files.
    • C.X.X
  • Adding methods, etc.
    • X.C.X
  • Minor changes and bug fixes.
    • X.X.C

License

This software is released under the Apache-2.0 License, see LICENSE file.

Copyright 2025-2026 Masahide Mori

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Trademarks

  • “Dart” and “Flutter” are trademarks of Google LLC.
    This package is not developed or endorsed by Google LLC.

  • “Python” is a trademark of the Python Software Foundation.
    This package is not affiliated with the Python Software Foundation.

  • GitHub and the GitHub logo are trademarks of GitHub, Inc.
    This package is not affiliated with GitHub, Inc.

Metadata

Release files for delta-trace-db 0.6.0

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

Source distribution (sdist)

Source distribution for delta-trace-db 0.6.0
File Size Uploaded Provenance Actions
delta_trace_db-0.6.0.tar.gz 99.6 kB Without provenance Details for delta_trace_db-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for delta-trace-db 0.6.0
File Interpreter ABI Platform Actions
delta_trace_db-0.6.0-py3-none-any.whl Python 3 none any Details for delta_trace_db-0.6.0-py3-none-any.whl

Total release size: 197.6 kB

Release files / delta_trace_db-0.6.0.tar.gz

Download URL delta_trace_db-0.6.0.tar.gz
Size 99.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5b6d4644f76f9266ce9d6cbcf82f58c4ee71a7e41bdae5791190ce0e6747b6f0
BLAKE2b-256 checksum
How to use checksums
981e91b60ecd4eb312865dd53f4d95d6769e3408eb3b2e53af64a001baff22c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / delta_trace_db-0.6.0-py3-none-any.whl

Download URL delta_trace_db-0.6.0-py3-none-any.whl
Size 98.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15c686512e41b4a168e1233756288c07d5545ed6a97bf8f0442ea7108797169f
BLAKE2b-256 checksum
How to use checksums
a2c1be43c1fd296cf5fc2bb9a8d82d48d2d18c72c2a656a57a71cd2c813a6918
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for delta-trace-db 0.6.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files No provenance

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