xeze-dbr-core 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.4
2
+ Name: xeze-dbr-core
3
+ Version: 0.1.0
4
+ Summary: Official unified database wrapper for the Xeze infrastructure.
5
+ Author-email: Xeze <dev@xeze.org>
6
+ License: MIT
7
+ Project-URL: Homepage, https://code.xeze.org/xeze/xeze-dbr-core
8
+ Project-URL: Repository, https://code.xeze.org/xeze/xeze-dbr-core
9
+ Project-URL: Bug Tracker, https://code.xeze.org/xeze/xeze-dbr-core/issues
10
+ Keywords: xeze,database,grpc,postgres,mongodb,redis,vault
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Database
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.8
23
+ Description-Content-Type: text/markdown
24
+ Requires-Dist: hvac>=1.1.0
25
+ Requires-Dist: grpcio>=1.50.0
26
+ Requires-Dist: protobuf>=4.21.0
27
+ Requires-Dist: xeze-dbr
28
+ Dynamic: requires-python
29
+
30
+ # xeze-dbr-core
31
+
32
+ Official unified database wrapper for the Xeze infrastructure. Provides a single, heavily-abstracted client for **PostgreSQL**, **MongoDB**, and **Redis** over mTLS via HashiCorp Vault.
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install git+https://code.xeze.org/xeze/xeze-dbr-core.git
38
+ ```
39
+
40
+ Or install locally for development:
41
+
42
+ ```bash
43
+ pip install .
44
+ ```
45
+
46
+ ## Quick Start
47
+
48
+ ```python
49
+ from xeze_core import XezeCoreClient
50
+
51
+ db = XezeCoreClient(app_namespace="xms")
52
+ db.init_workspace() # Ensures the 'xms_pg' database exists
53
+
54
+ # Postgres
55
+ db.pg_insert("students", {"name": "Ayush", "grade": "A"})
56
+
57
+ # MongoDB
58
+ db.mongo_insert("audit_logs", {"action": "student_added", "timestamp": "2026-04-05"})
59
+
60
+ # Redis
61
+ db.redis_set("cache:student:latest", "Ayush", ttl=300)
62
+ ```
63
+
64
+ ## Environment Variables
65
+
66
+ | Variable | Default | Description |
67
+ | ------------------ | -------------------------- | -------------------------- |
68
+ | `VAULT_ADDR` | `http://127.0.0.1:8200` | HashiCorp Vault address |
69
+ | `VAULT_TOKEN` | `dev-root-token` | Vault authentication token |
70
+ | `DB_ROUTER_HOST` | `db.0.xeze.org:443` | Database Router gRPC host |
71
+
72
+ ## Architecture
73
+
74
+ - **Database-per-Service isolation** — each `app_namespace` gets its own `{ns}_pg`, `{ns}_mongo`, and `{ns}:` Redis prefix.
75
+ - **Vault mTLS** — client certs are fetched from Vault KV at `dbrouter/certs` and loaded in-memory only.
76
+ - **gRPC/Protobuf abstraction** — all Protobuf packing is handled internally; developers work with native Python dicts.
@@ -0,0 +1,47 @@
1
+ # xeze-dbr-core
2
+
3
+ Official unified database wrapper for the Xeze infrastructure. Provides a single, heavily-abstracted client for **PostgreSQL**, **MongoDB**, and **Redis** over mTLS via HashiCorp Vault.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install git+https://code.xeze.org/xeze/xeze-dbr-core.git
9
+ ```
10
+
11
+ Or install locally for development:
12
+
13
+ ```bash
14
+ pip install .
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```python
20
+ from xeze_core import XezeCoreClient
21
+
22
+ db = XezeCoreClient(app_namespace="xms")
23
+ db.init_workspace() # Ensures the 'xms_pg' database exists
24
+
25
+ # Postgres
26
+ db.pg_insert("students", {"name": "Ayush", "grade": "A"})
27
+
28
+ # MongoDB
29
+ db.mongo_insert("audit_logs", {"action": "student_added", "timestamp": "2026-04-05"})
30
+
31
+ # Redis
32
+ db.redis_set("cache:student:latest", "Ayush", ttl=300)
33
+ ```
34
+
35
+ ## Environment Variables
36
+
37
+ | Variable | Default | Description |
38
+ | ------------------ | -------------------------- | -------------------------- |
39
+ | `VAULT_ADDR` | `http://127.0.0.1:8200` | HashiCorp Vault address |
40
+ | `VAULT_TOKEN` | `dev-root-token` | Vault authentication token |
41
+ | `DB_ROUTER_HOST` | `db.0.xeze.org:443` | Database Router gRPC host |
42
+
43
+ ## Architecture
44
+
45
+ - **Database-per-Service isolation** — each `app_namespace` gets its own `{ns}_pg`, `{ns}_mongo`, and `{ns}:` Redis prefix.
46
+ - **Vault mTLS** — client certs are fetched from Vault KV at `dbrouter/certs` and loaded in-memory only.
47
+ - **gRPC/Protobuf abstraction** — all Protobuf packing is handled internally; developers work with native Python dicts.
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "xeze-dbr-core"
7
+ version = "0.1.0"
8
+ description = "Official unified database wrapper for the Xeze infrastructure."
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.8"
12
+ authors = [
13
+ { name = "Xeze", email = "dev@xeze.org" }
14
+ ]
15
+ keywords = ["xeze", "database", "grpc", "postgres", "mongodb", "redis", "vault"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.8",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Topic :: Database",
27
+ "Topic :: Software Development :: Libraries :: Python Modules",
28
+ ]
29
+ dependencies = [
30
+ "hvac>=1.1.0",
31
+ "grpcio>=1.50.0",
32
+ "protobuf>=4.21.0",
33
+ "xeze-dbr",
34
+ ]
35
+
36
+ [project.urls]
37
+ Homepage = "https://code.xeze.org/xeze/xeze-dbr-core"
38
+ Repository = "https://code.xeze.org/xeze/xeze-dbr-core"
39
+ "Bug Tracker" = "https://code.xeze.org/xeze/xeze-dbr-core/issues"
40
+
41
+ [tool.setuptools.packages.find]
42
+ where = ["."]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,15 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="xeze-dbr-core",
5
+ version="0.1.0",
6
+ description="Official unified database wrapper for the Xeze infrastructure.",
7
+ packages=find_packages(),
8
+ install_requires=[
9
+ "hvac>=1.1.0",
10
+ "grpcio>=1.50.0",
11
+ "protobuf>=4.21.0",
12
+ "xeze-dbr" # Your underlying gRPC router SDK
13
+ ],
14
+ python_requires=">=3.8",
15
+ )
@@ -0,0 +1,3 @@
1
+ from .client import XezeCoreClient
2
+
3
+ __all__ = ["XezeCoreClient"]
@@ -0,0 +1,137 @@
1
+ import os
2
+ import hvac
3
+ import grpc
4
+ from xeze_dbr import connect
5
+ from google.protobuf import struct_pb2
6
+
7
+
8
+ class XezeCoreClient:
9
+ """
10
+ Unified client for Postgres, MongoDB, and Redis over mTLS via HashiCorp Vault.
11
+ Enforces database isolation per application namespace.
12
+ """
13
+
14
+ def __init__(self, app_namespace):
15
+ if not app_namespace or not isinstance(app_namespace, str):
16
+ raise ValueError("A strict app_namespace (e.g., 'xms', 'selfnote') is required.")
17
+
18
+ self.app_namespace = app_namespace
19
+ # Automatic isolated routing paths
20
+ self.pg_db = f"{app_namespace}_pg"
21
+ self.mongo_db = f"{app_namespace}_mongo"
22
+ self.redis_prefix = f"{app_namespace}:"
23
+
24
+ self._connect_via_vault()
25
+
26
+ def _connect_via_vault(self):
27
+ """Silently handles Vault authentication and memory-only cert loading."""
28
+ vault_addr = os.environ.get("VAULT_ADDR", "http://127.0.0.1:8200")
29
+ vault_token = os.environ.get("VAULT_TOKEN", "dev-root-token")
30
+ host = os.environ.get("DB_ROUTER_HOST", "db.0.xeze.org:443")
31
+
32
+ vault = hvac.Client(url=vault_addr, token=vault_token)
33
+ if not vault.is_authenticated():
34
+ raise Exception("Critical: Vault authentication failed.")
35
+
36
+ secret = vault.secrets.kv.v2.read_secret_version(path="dbrouter/certs")
37
+ cert_data = secret["data"]["data"]["client_cert"].encode()
38
+ key_data = secret["data"]["data"]["client_key"].encode()
39
+
40
+ self.client = connect(host=host, cert_data=cert_data, key_data=key_data)
41
+
42
+ def init_workspace(self):
43
+ """
44
+ Attempts to create the isolated Postgres database for this namespace.
45
+ Safe to call on application startup.
46
+ """
47
+ try:
48
+ req = self.client.pb2.CreateDatabaseRequest(name=self.pg_db)
49
+ self.client.postgres.CreateDatabase(req)
50
+ print(f"[OK] Provisioned workspace: {self.pg_db}")
51
+ except grpc.RpcError as e:
52
+ if "already exists" in e.details().lower():
53
+ pass # Expected behavior if already provisioned
54
+ else:
55
+ print(f"[WARN] Workspace check failed: {e.details()}")
56
+
57
+ def _pack_pg_dict(self, data_dict):
58
+ """Internal helper for PostgreSQL Protobuf typing."""
59
+ packed = {}
60
+ for k, v in data_dict.items():
61
+ if isinstance(v, str):
62
+ packed[k] = struct_pb2.Value(string_value=v)
63
+ elif isinstance(v, bool):
64
+ packed[k] = struct_pb2.Value(bool_value=v)
65
+ elif isinstance(v, (int, float)):
66
+ packed[k] = struct_pb2.Value(number_value=float(v))
67
+ else:
68
+ packed[k] = struct_pb2.Value(string_value=str(v))
69
+ return packed
70
+
71
+ # --- POSTGRESQL API -------------------------------------------------------
72
+
73
+ def pg_query(self, query):
74
+ """Executes raw SQL returning a list of native Python dictionaries."""
75
+ req = self.client.pb2.ExecuteQueryRequest(database=self.pg_db, query=query)
76
+ resp = self.client.postgres.ExecuteQuery(req)
77
+
78
+ results = []
79
+ for row in resp.rows:
80
+ row_data = {}
81
+ for key, val in row.fields.items():
82
+ if val.HasField("string_value"):
83
+ row_data[key] = val.string_value
84
+ elif val.HasField("number_value"):
85
+ row_data[key] = val.number_value
86
+ elif val.HasField("bool_value"):
87
+ row_data[key] = val.bool_value
88
+ results.append(row_data)
89
+ return results
90
+
91
+ def pg_insert(self, table, data_dict):
92
+ """Inserts a native Python dict into PostgreSQL."""
93
+ req = self.client.pb2.InsertDataRequest(
94
+ database=self.pg_db,
95
+ table=table,
96
+ data=self._pack_pg_dict(data_dict)
97
+ )
98
+ resp = self.client.postgres.InsertData(req)
99
+ return resp.inserted_id
100
+
101
+ # --- MONGODB API ----------------------------------------------------------
102
+
103
+ def mongo_insert(self, collection, doc_dict):
104
+ """Inserts a native Python dictionary into MongoDB."""
105
+ doc = struct_pb2.Struct()
106
+ doc.update(doc_dict)
107
+
108
+ req = self.client.pb2.InsertDocumentRequest(
109
+ database=self.mongo_db,
110
+ collection=collection,
111
+ document=doc
112
+ )
113
+ resp = self.client.mongo.InsertDocument(req)
114
+ return resp.inserted_id
115
+
116
+ # --- REDIS API ------------------------------------------------------------
117
+
118
+ def redis_set(self, key, value, ttl=3600):
119
+ """Sets a prefixed key with a default 1-hour TTL."""
120
+ namespaced_key = f"{self.redis_prefix}{key}"
121
+ req = self.client.pb2.SetValueRequest(key=namespaced_key, value=str(value), ttl=ttl)
122
+ self.client.redis.SetValue(req)
123
+
124
+ def redis_get(self, key):
125
+ """Fetches a prefixed key gracefully."""
126
+ namespaced_key = f"{self.redis_prefix}{key}"
127
+ try:
128
+ req = self.client.pb2.GetValueRequest(key=namespaced_key)
129
+ return self.client.redis.GetValue(req).value
130
+ except grpc.RpcError as e:
131
+ if "not found" in e.details().lower():
132
+ return None
133
+ raise e
134
+
135
+ def close(self):
136
+ """Closes the underlying gRPC connection."""
137
+ self.client.close()
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.4
2
+ Name: xeze-dbr-core
3
+ Version: 0.1.0
4
+ Summary: Official unified database wrapper for the Xeze infrastructure.
5
+ Author-email: Xeze <dev@xeze.org>
6
+ License: MIT
7
+ Project-URL: Homepage, https://code.xeze.org/xeze/xeze-dbr-core
8
+ Project-URL: Repository, https://code.xeze.org/xeze/xeze-dbr-core
9
+ Project-URL: Bug Tracker, https://code.xeze.org/xeze/xeze-dbr-core/issues
10
+ Keywords: xeze,database,grpc,postgres,mongodb,redis,vault
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Database
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.8
23
+ Description-Content-Type: text/markdown
24
+ Requires-Dist: hvac>=1.1.0
25
+ Requires-Dist: grpcio>=1.50.0
26
+ Requires-Dist: protobuf>=4.21.0
27
+ Requires-Dist: xeze-dbr
28
+ Dynamic: requires-python
29
+
30
+ # xeze-dbr-core
31
+
32
+ Official unified database wrapper for the Xeze infrastructure. Provides a single, heavily-abstracted client for **PostgreSQL**, **MongoDB**, and **Redis** over mTLS via HashiCorp Vault.
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install git+https://code.xeze.org/xeze/xeze-dbr-core.git
38
+ ```
39
+
40
+ Or install locally for development:
41
+
42
+ ```bash
43
+ pip install .
44
+ ```
45
+
46
+ ## Quick Start
47
+
48
+ ```python
49
+ from xeze_core import XezeCoreClient
50
+
51
+ db = XezeCoreClient(app_namespace="xms")
52
+ db.init_workspace() # Ensures the 'xms_pg' database exists
53
+
54
+ # Postgres
55
+ db.pg_insert("students", {"name": "Ayush", "grade": "A"})
56
+
57
+ # MongoDB
58
+ db.mongo_insert("audit_logs", {"action": "student_added", "timestamp": "2026-04-05"})
59
+
60
+ # Redis
61
+ db.redis_set("cache:student:latest", "Ayush", ttl=300)
62
+ ```
63
+
64
+ ## Environment Variables
65
+
66
+ | Variable | Default | Description |
67
+ | ------------------ | -------------------------- | -------------------------- |
68
+ | `VAULT_ADDR` | `http://127.0.0.1:8200` | HashiCorp Vault address |
69
+ | `VAULT_TOKEN` | `dev-root-token` | Vault authentication token |
70
+ | `DB_ROUTER_HOST` | `db.0.xeze.org:443` | Database Router gRPC host |
71
+
72
+ ## Architecture
73
+
74
+ - **Database-per-Service isolation** — each `app_namespace` gets its own `{ns}_pg`, `{ns}_mongo`, and `{ns}:` Redis prefix.
75
+ - **Vault mTLS** — client certs are fetched from Vault KV at `dbrouter/certs` and loaded in-memory only.
76
+ - **gRPC/Protobuf abstraction** — all Protobuf packing is handled internally; developers work with native Python dicts.
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ xeze_core/__init__.py
5
+ xeze_core/client.py
6
+ xeze_dbr_core.egg-info/PKG-INFO
7
+ xeze_dbr_core.egg-info/SOURCES.txt
8
+ xeze_dbr_core.egg-info/dependency_links.txt
9
+ xeze_dbr_core.egg-info/requires.txt
10
+ xeze_dbr_core.egg-info/top_level.txt
@@ -0,0 +1,4 @@
1
+ hvac>=1.1.0
2
+ grpcio>=1.50.0
3
+ protobuf>=4.21.0
4
+ xeze-dbr
@@ -0,0 +1,3 @@
1
+ build
2
+ dist
3
+ xeze_core