Metadata-Version: 2.4
Name: dnhydb
Version: 0.3.0
Classifier: Development Status :: 3 - Alpha
Classifier: License :: Other/Proprietary License
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Database :: Database Engines/Servers
Requires-Dist: numpy>=1.22 ; extra == 'numpy'
Requires-Dist: pytest>=7 ; extra == 'test'
Requires-Dist: numpy>=1.22 ; extra == 'test'
Provides-Extra: numpy
Provides-Extra: test
License-File: LICENSE.md
License-File: THIRD-PARTY-LICENSES.txt
Summary: dNHyDB (directNHyDB) – general-purpose database with direct addressing (u, v, side); native Rust engine with Python bindings
Keywords: database,storage-engine,rust,numpy,append-only
Author-email: Achim Meissner <achim.meissner@nhydb.de>
Requires-Python: >=3.12
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Changelog, https://github.com/nhydb-run4/dNHyDB/blob/main/CHANGELOG.md
Project-URL: Documentation, https://github.com/nhydb-run4/dNHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md
Project-URL: Issues, https://github.com/nhydb-run4/dNHyDB/issues
Project-URL: Repository, https://github.com/nhydb-run4/dNHyDB

# dNHyDB (directNHyDB)

**A compact record store with direct mathematical addressing.**

dNHyDB is the streamlined member of the **Dynadron** database family. Every
value lives in a cell `(u, v, s)`: `u` is the record, `v` the field or
position, `s` one of two sides. There are no tables and no primary index –
the address space itself provides order, and each cell has an exact natural
number `N` that is computed when needed, never stored. The engine is written
in native Rust and used from Python.

[![PyPI](https://img.shields.io/pypi/v/dnhydb)](https://pypi.org/project/dnhydb/)
· Python 3.12–3.15 · Linux, macOS, Windows ·
[License: source-available, non-production](#license)

**→ [Python Cookbook](https://github.com/nhydb-run4/dNHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md)** –
task-oriented guide with tested examples for the complete Python API.

## The addressing idea

`u` and `v` are integers from 1 to 2⁶⁴ − 1, the side `s` is `NL` or `NR`.
The number of a cell is

```text
G = u + v        N = G² − u  (side NL)        N = G² + v  (side NR)
```

so `(u, v) = (11, 13)` is `N = 565` on NL and `N = 589` on NR. The mapping is
exact in both directions (`dnhydb.n_of`, `dnhydb.address_of`); `N` needs up
to 130 bits and is handled as a Python integer.

## Installation

```bash
pip install dnhydb
pip install numpy        # optional, for the NumPy batch API
```

Prebuilt wheels are available for CPython 3.12–3.15 on Linux (x86_64,
aarch64), macOS (x86_64, arm64) and Windows (x64). No Rust toolchain is
needed; building from source is described in
[`BUILDING.md`](https://github.com/nhydb-run4/dNHyDB/blob/main/BUILDING.md).

## A first example

Create a database, write two records and a free cell, close it, open it
again as a reader and read:

```python
import os
import tempfile

import dnhydb

path = os.path.join(tempfile.mkdtemp(), "cities.dnhydb")

# Create: a typed BASE record layout, two records and one free cell.
with dnhydb.create(path) as db:
    db.define_base([("city", "utf8"), ("population", "u64")])
    db.put_record(1, ["Berlin", 3_685_000])
    db.put_record(2, ["Hamburg", 1_862_000])
    db.put_cell(2, 1_000, "port city")
# Leaving the block commits and closes the database.

db = dnhydb.open_reader(path)
print(db.get_record(2))
print(db.get_cell(2, 1_000))
n = dnhydb.n_of(2, 1)
print(n, dnhydb.address_of(n))
db.close()
```

```text
{'city': 'Hamburg', 'population': 1862000, 'v1000': 'port city'}
port city
7 (2, 1, 0)
```

The database is a single file (`cities.dnhydb`); next to it the engine keeps
a `.lock` file for the writer and a catalog (`.dnhydb-index`) that speeds up
opening and is rebuilt automatically. For a backup the `.dnhydb` file is
enough – see
[Cookbook, section 17](https://github.com/nhydb-run4/dNHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#17-files-on-disk-backup-and-restore).

## What dNHyDB offers

* **Records and cells:** a typed BASE record layout (`define_base`), named
  extensions, free cells anywhere in the address space, deletion with
  tombstones, two sides per cell.
* **Write path:** write buffer, batches, NumPy column batches, commit policy
  (manual or by thresholds), transactions with rollback, durability `fsync`,
  `full` or `none`.
* **One writer, many readers:** a reader – also in another process – sees
  the last commit as a consistent snapshot and moves forward with
  `refresh()`.
* **Crash safety:** append-only file with two CRC-protected superblocks; after
  a crash the last commit is valid, never half a batch.
* **Reading:** point access, records, iterators that skip gaps, column reads
  into NumPy, a VALUE index for equality and range lookups.
* **Maintenance:** stats, health, verify, checkpoint, compaction (in place or
  as a copy), tail inspection and repair.

Measured throughput figures and their exact test conditions are documented
in the
[technical documentation, section 16.3](https://github.com/nhydb-run4/dNHyDB/blob/main/docs/en/dNHyDB_Technical_Documentation.md#163-benchmarks).

## Documentation

* **[Python Cookbook](https://github.com/nhydb-run4/dNHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md)** –
  installation, the model, records and cells, addresses and `N`, types,
  iterators, batches, NumPy, transactions and durability, readers and
  writers, options, the VALUE index, maintenance, backups, errors, the
  command line, complete application examples and an API reference. All
  examples are executed by the test suite.
* [Technical documentation (English)](https://github.com/nhydb-run4/dNHyDB/blob/main/docs/en/dNHyDB_Technical_Documentation.md) ·
  [Technische Dokumentation (Deutsch)](https://github.com/nhydb-run4/dNHyDB/blob/main/docs/de/dNHyDB_Technische_Dokumentation.md) –
  mathematics, architecture, file format, guarantees.
* [Example programs](https://github.com/nhydb-run4/dNHyDB/tree/main/examples/python) ·
  [example configuration](https://github.com/nhydb-run4/dNHyDB/blob/main/config/dnhydb_config.example.toml) ·
  [`CHANGELOG.md`](https://github.com/nhydb-run4/dNHyDB/blob/main/CHANGELOG.md)
* Command line: `dnhydb --help` (or `python -m dnhydb`).
* Rust: the core crate `crates/dnhydb-core` has no Python dependency and can
  be used directly; see the technical documentation.

## Sibling project: NHyDB

[**NHyDB**](https://github.com/nhydb-run4/NHyDB) (`pip install nhydb`) is the full
Dynadron database: several realms, layouts CLASSIC, COLUMN, PACKED and
CUSTOM, MATH_MAP (placing values by formulas), text and full-text indexes,
the QueryEngine and NHySQL, and an encrypted external layout plan. Choose
**dNHyDB** for a compact, direct record store and **NHyDB** when you need
the full model.

## Scientific background

The mathematical foundations (in German):

* *Das Dynadron als mathematisches Datenbankprinzip* –
  [doi:10.5281/zenodo.23438748](https://doi.org/10.5281/zenodo.23438748)
* *Das Dynadron der natürlichen Zahlen* –
  [doi:10.5281/zenodo.22549415](https://doi.org/10.5281/zenodo.22549415)
* *Geometrie und Arithmetik im Dynadron* –
  [doi:10.5281/zenodo.22694525](https://doi.org/10.5281/zenodo.22694525)

## Known limitations

* **Scope:** one realm (R1) and the CLASSIC record layout only; `u` and `v`
  are `u64`; integer values up to 128 bits; no query language (access via
  API, iterators and the VALUE index).
* **One writer at a time** (exclusive lock on `<file>.lock`); readers see the
  last commit and call `refresh()` for newer commits.
* **`None` in BASE fields:** use extensions or free cells for optional values
  (see the Cookbook).
* **Durability `full`:** on macOS `F_FULLFSYNC` is used; if the file system
  rejects it, dNHyDB falls back to a plain `fsync` without reporting an
  error. On Linux `full` is the same as `fsync`; on Windows both use
  `FlushFileBuffers`.
* **Windows:** replacing the database file while readers hold it open
  (compaction) uses POSIX rename semantics (Windows 10 or newer, NTFS).
* **Status:** alpha – the API may still change between minor versions.

## License

dNHyDB is licensed under the **NHyDB / dNHyDB Experimental Software License
1.0** ([`LICENSE.md`](https://github.com/nhydb-run4/dNHyDB/blob/main/LICENSE.md)).
The source code is available, but this is **not an open-source license**:
free use is limited to non-production purposes (unlimited for private
individuals, time-limited for teaching, research and businesses), and
**production use is not permitted** without a separate written license.
Please read the license text before using the software.

The compiled extension module contains third-party Rust components under
MIT/Apache-2.0-style licenses; their notices are in
[`THIRD-PARTY-LICENSES.txt`](https://github.com/nhydb-run4/dNHyDB/blob/main/THIRD-PARTY-LICENSES.txt),
which is also shipped inside the wheel.

## Development

Building from source: [`BUILDING.md`](https://github.com/nhydb-run4/dNHyDB/blob/main/BUILDING.md) ·
release procedure: [`RELEASING.md`](https://github.com/nhydb-run4/dNHyDB/blob/main/RELEASING.md)

```bash
cargo clippy --workspace --all-targets -- -D warnings
pip install ".[test]"
python -m pytest tests/smoke            # smoke tests of the installed package
```

## Contact

Achim Meissner – achim.meissner@nhydb.de

