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.1.tar.gz (8.6 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.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nubdt-1.0.1.tar.gz
  • Upload date:
  • Size: 8.6 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.1.tar.gz
Algorithm Hash digest
SHA256 66f268d1fccbd407954001323d4049a51e0de250a87a30ab6aca7b3df0e2004e
MD5 90f503d52374aabdb3d1a364294460c2
BLAKE2b-256 b02f82231b26041f47fd3cbd4ae806817313bcffd418b0464e5aa785170b5239

See more details on using hashes here.

Provenance

The following attestation bundles were made for nubdt-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: nubdt-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a139d50e80f15dafd41684ab613c2e9f4a7fa7b25a5ba822507253ed0fee4f7b
MD5 2deccd2d4ff75a951b5c1070a70e8610
BLAKE2b-256 df1ae50bbae1c87c52e70cf10a2f6b3744e09bc48a324c7df29dc63a1aa2e814

See more details on using hashes here.

Provenance

The following attestation bundles were made for nubdt-1.0.1-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