Skip to main content

Python client for NubDT — a blazing-fast, AOF-based in-memory database written in Zig

Project description

NubDB Python Client

🚀 Python client for NubDB — a blazing-fast, AOF-based in-memory database written in Zig.

PyPI version Python License: MIT

Installation

pip install nubdb

Quick Start

Make sure your NubDB server is running (default: localhost:6379), then:

from nubdb import NubDB

# Connect to NubDB
db = NubDB()

# Set and get values
db.set("name", "Alice")
print(db.get("name"))  # → Alice

# Use TTL (auto-expire in 60 seconds)
db.set("session", "abc123", ttl=60)

# Counters
db.set("views", 0)
db.incr("views")  # → 1
db.incr("views")  # → 2
db.decr("views")  # → 1

# Check existence
db.exists("name")  # → True
db.exists("nope")  # → False

# Database size
db.size()  # → 3

# Delete keys
db.delete("name")

# Close when done
db.close()

Context Manager

from nubdb import NubDB

with NubDB() as db:
    db.set("key", "value")
    print(db.get("key"))
# Connection automatically closed

Configuration

from nubdb import NubDB

# Custom host and port
db = NubDB(host="db.nubcoder.com", port=6379)

# With timeout and retry settings
db = NubDB(
    host="localhost",
    port=6379,
    timeout=10.0,          # Socket timeout (seconds)
    auto_reconnect=True,   # Auto-reconnect on connection loss
    max_retries=5,         # Max reconnection attempts
)

Environment Variables

Variable Default Description
NUBDB_HOST localhost Server hostname
NUBDB_PORT 6379 Server port
export NUBDB_HOST=db.nubcoder.com
export NUBDB_PORT=6379

API Reference

Connection

Method Description
NubDB(host, port, ...) Create client and connect
db.connect() Reconnect to server
db.close() Close connection
db.ping() Check server is reachable
db.connected Connection status (property)

Commands

Method Returns Description
db.set(key, value, ttl=None) bool Set a key-value pair
db.get(key) str | None Get value by key
db.delete(key) bool Delete a key
db.exists(key) bool Check if key exists
db.incr(key) int Increment integer value
db.decr(key) int Decrement integer value
db.size() int Get number of keys
db.clear() bool Delete all keys

Bulk Operations

Method Returns Description
db.mset({"k1": "v1", ...}) bool Set multiple key-value pairs
db.mget("k1", "k2", ...) dict Get multiple keys at once

Error Handling

from nubdb import NubDB, ConnectionError, TimeoutError, CommandError

try:
    db = NubDB()
    db.set("key", "value")
except ConnectionError:
    print("Could not connect to NubDB server")
except TimeoutError:
    print("Command timed out")
except CommandError as e:
    print(f"Command failed: {e}")

Requirements

  • Python 3.8+
  • Running NubDB server (setup guide)
  • Zero dependencies — uses only Python standard library

NubDB Server

NubDB is a high-performance, AOF-based in-memory database written in Zig:

  • 100k+ ops/sec throughput
  • <5µs SET latency, <1µs GET latency
  • AOF persistence with background compaction
  • Docker & Kubernetes ready
# Start NubDB server with Docker
docker run -d -p 6379:6379 nubdb:latest

# Or build from source
git clone https://github.com/nub-coders/nubdt.git
cd nubdt && make server

License

MIT License — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nubdt-1.0.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nubdt-1.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file nubdt-1.0.0.tar.gz.

File metadata

  • Download URL: nubdt-1.0.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nubdt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f4b5593625c8ab72a671b1416414740404bd19955e2ed2899ebb0beb3d31596b
MD5 dcde3be1e5256df02c34e482392babab
BLAKE2b-256 76fbfd16739c30478f49d479399ff56fd1c0d8877a288cfd8fbcb8f5bc3b4cdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for nubdt-1.0.0.tar.gz:

Publisher: pypi-publish.yml on nub-coders/nubdt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nubdt-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nubdt-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nubdt-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3eccbcccbb9093c0a58b82eeff4c1a984ac79b724832caabef24c27cbd60089
MD5 69de02a43ce91e20cab5bd685fb483b6
BLAKE2b-256 e1c9c8c5e1b871b540d538b1c5e22659a7beac1900ddc7d4bae6d6033265405a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nubdt-1.0.0-py3-none-any.whl:

Publisher: pypi-publish.yml on nub-coders/nubdt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page