Skip to content
Nuvyntra Labs

Platform integration

Python

ctypes wheel. Set NUVEXA_NATIVE_LIB to the published shared library.

Overview

ctypes wrapper. NUVEXA_NATIVE_LIB is required.

1. Download

From NuvexaDB v1.0.6, take both zips for your machine:

Your machinePython zipNative zipLibrary file
macOS Apple SiliconNuvexaDB-Python-osx-arm64.zipNuvexaDB-Native-osx-arm64.ziplibnuvexa.dylib
Linux x64NuvexaDB-Python-linux-x64.zipNuvexaDB-Native-linux-x64.ziplibnuvexa.so
Windows x64NuvexaDB-Python-win-x64.zipNuvexaDB-Native-win-x64.zipnuvexa.dll

Inside the Python zip: nuvexadb-1.0.6-py3-none-any.whl (the wheel is tagged py3-none-any; the RID on the zip only tells you which CI job built it).

2. Empty project

python3 -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
mkdir acme_store && cd acme_store

3. Add the downloaded package

python3 -m pip install /path/to/nuvexadb-1.0.6-py3-none-any.whl
export NUVEXA_NATIVE_LIB="/absolute/path/to/libnuvexa.dylib"

Windows (PowerShell):

$env:NUVEXA_NATIVE_LIB = "C:\path\to\nuvexa.dll"

Without that variable, create / open raise NuvexaException.

4. Create, open, close

from nuvexadb import NuvexaDatabase, NuvexaEncryptionException

path = "app.nvx"
with NuvexaDatabase.create(path, key) as db:  # key=None for plaintext
    pass

if NuvexaDatabase.is_encrypted(path) and not key:
    raise SystemExit("Encrypted .nvx — pass the key")

with NuvexaDatabase.open(path, key) as db:
    pass

Opening encrypted without a key raises NuvexaEncryptionException.

5. Delete the database

from pathlib import Path

db.close()
Path(path).unlink(missing_ok=True)
Path(path + "-wal").unlink(missing_ok=True)

6. Collections

db.insert("users", '{"name":"Ada","age":36}')
print(db.list_collections())
db.rename_collection("users", "people")
db.drop_collection("people")

7. Documents

import json

doc_id = db.insert("users", json.dumps({"name": "Ada", "age": 36}))
db.insert_many("users", json.dumps([{"name": "Grace", "age": 85}]))
ada = db.find_by_id("users", doc_id)
db.replace("users", json.dumps({"_id": doc_id, "name": "Ada Lovelace", "age": 36}))
db.delete_by_id("users", doc_id)
rows = db.execute("db.users.find({ age: { $gte: 21 } }).sort({ name: 1 }).limit(20)")

8. Password for an encrypted file

Load the key from the environment or a secret store (keyring), not from a committed .env in git. A demo may use a throwaway string; production must not use 1234.

db.change_encryption_key(current_key, next_key)

See Encryption notes.

Discussion

Comment on NuvexaDB. The thread lives on this component's GitHub repository (nuvyntralabs/NuvexaDB). Sign in with GitHub — Giscus uses Discussions, Utterances uses Issues.