Skip to main content

Call your own Redis, Postgres, and MySQL from any Python runtime over HTTPS.

Project description

zedgi (Python)

Call your own Redis, Postgres, and MySQL from any Python runtime over HTTPS — no TCP sockets required. Built on the standard library only (zero dependencies).

pip install zedgi

Quick Start

import os
from zedgi import create_client

zedgi = create_client(url="https://dev123.zedgi.app", key=os.environ["ZEDGI_KEY"])

# Redis
redis = zedgi.redis()
redis.set("hello", "world")
print(redis.get("hello"))            # 'world'
redis.call("HSET", "user:1", "name", "Ada")

# Postgres
pg = zedgi.postgres()
result = pg.query("SELECT NOW() AS ts")
print(result["rows"])

# MySQL
mysql = zedgi.mysql()
print(mysql.query("SELECT 1 AS n")["rows"])

Installation

pip install zedgi

Requires Python 3.8+.

Creating a Client

from zedgi import create_client, ZedgiClient

client: ZedgiClient = create_client(
    url="https://YOUR_SUBDOMAIN.zedgi.app",
    key="zk_...",           # your API key
    timeout=10.0,          # seconds (default)
)

With zero-knowledge credential linking and signed header metadata:

client = create_client(
    url="https://YOUR_SUBDOMAIN.zedgi.app",
    key="zk_...",
    signing_secret=os.environ["ZEDGI_SECRET"],
    credential={
        "host": "db.example.com",
        "user": "app",
        "password": os.environ["DB_PASSWORD"],
        "database": "main",
        "header": {
            "x-firewall-token": os.environ["DB_FIREWALL_TOKEN"],
        },
    },
)

credential["header"] is excluded from ECIES encryption and sent as signed plaintext metadata for proxy/firewall integrations.

Redis

The Redis client exposes many common commands and a generic call() escape hatch. Unknown method names are forwarded as custom hooks.

redis = zedgi.redis()

redis.ping()                          # 'PONG'
redis.set("key", "value", "EX", 60)
redis.get("key")
redis.delete("key1", "key2")
redis.hset("user:1", "name", "Ada")
redis.lrange("queue", 0, -1)
redis.zadd("scores", 100, "player1")

# Generic command
redis.call("ZREVRANGE", "leaderboard", 0, 9, "WITHSCORES")

# Pipeline / MULTI
redis.pipeline([("SET", ["a", "1"]), ("INCR", ["a"])])
redis.multi([...])

Postgres & MySQL

pg = zedgi.postgres()
mysql = zedgi.mysql()

# Query
result = pg.query("SELECT * FROM users WHERE id = $1", [42])
# {"rows": [...], "rowCount": 1, "fields": [...] }

# Transaction
pg.transaction([
    {"sql": "UPDATE accounts SET balance = balance - $1 WHERE id = $2", "params": [100, 1]},
    {"sql": "UPDATE accounts SET balance = balance + $1 WHERE id = $2", "params": [100, 2]},
])

MySQL returns a slightly different shape: {"rows": [...], "fields": [...]} (fields are plain strings).

Custom Hooks (paid feature)

Register hooks in your ZedGi dashboard, then invoke them by name.

# Redis Lua hook (KEYS + ARGV)
redis.hook("topUsers", keys=["leaderboard"], args=[10])

# SQL hook
pg.hook("activeUsers", params=[30])

# Magic proxy — call unregistered names directly
redis.topUsers("leaderboard", 10)
pg.activeUsers(30)

See the Custom Hooks documentation for registration details.

Error Handling

All RPC errors raise zedgi.RpcError:

from zedgi import RpcError

try:
    redis.hook("notRegistered")
except RpcError as e:
    print(e.code)     # e.g. "ZEDGI_HOOK_NOT_FOUND"
    print(e.status)   # HTTP status
    print(e.details)
    print(str(e))

Low-level Transport

If you need full control you can use the transport directly:

from zedgi.client import Transport

t = Transport(url="https://...", key="zk_...", timeout=10)
result = t.call("redis", "get", {"args": ["mykey"]})

Package Contents

  • create_client
  • ZedgiClient
  • RedisClient, PostgresClient, MySQLClient
  • RpcError

All clients are thin (stdlib only) for the RPC facade. For the full zero-knowledge "link" (client-side ECIES encryption of your DB credentials into x-zedgi-cred + request signing), supply your secret + credential (and optionally public_key). If credential["header"] is present, it is signed and forwarded separately instead of being public-key encrypted. The packages will perform encryption + signing for you when those values are provided. See the JS client docs and https://zedgi.app/docs for the exact options and the auto public-key pull behavior.

Related

License

MIT licensed. Part of the ZedGi platform.

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

zedgi-1.0.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

zedgi-1.0.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zedgi-1.0.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for zedgi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f7a949924d1b027c5ee778d0dc7b16d83453360381f3de2675cbbb101a33ddb5
MD5 c41a9fcdea9635133bc5333733b5ec93
BLAKE2b-256 95051bd67e6f0ee262f9fb4d2c5b116254dec1c4a98f15819872e409b96ee7b0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zedgi-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for zedgi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 718b1b17a3193022b47877f537cd493253c28180c9ffaded78ee4fa276961916
MD5 fc8428af81572c704d151266ef651132
BLAKE2b-256 3757b2f524d99cf72e01a65efc90971516d6a5d1df591afe56f25c1f1919e0b8

See more details on using hashes here.

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