Skip to main content

Official Python SDK for SafeNode — zero-knowledge credential vault

Project description

SafeNode Python SDK

Official Python SDK for SafeNode — zero-knowledge credential vault.

Installation

pip install safenode

Quick Start

MCP Token (recommended)

from safenode import SafeNode

client = SafeNode(token="kvt_your_token_here")

Or use the environment variable:

export SAFENODE_TOKEN=kvt_your_token_here
import os
from safenode import SafeNode

client = SafeNode()  # reads SAFENODE_TOKEN automatically

Email + Password

from safenode import SafeNode

client = SafeNode(
    email="user@example.com",
    password="your-password",
    passphrase="your-vault-passphrase",
    vault_id="your-vault-uuid",
)

Usage

Proxy Requests

Forward HTTP requests through a stored credential:

response = client.proxy.request(
    credential="my-api-key",
    method="GET",
    path="/users",
    query_params={"page": "1"},
)

print(response.status_code)   # 200
print(response.body)          # parsed JSON body
print(response.response_time_ms)

POST with body and headers:

response = client.proxy.request(
    credential="my-api-key",
    method="POST",
    path="/messages",
    body={"content": "Hello"},
    headers={"X-Custom-Header": "value"},
    timeout=60,
)

SSH Commands

Execute commands on remote servers:

result = client.ssh.exec(
    credential="my-server",
    command="df -h",
    timeout=30,
)

print(result.stdout)
print(result.stderr)
print(result.exit_code)
print(result.execution_time_ms)

Database Queries

Run SQL queries through stored database credentials:

result = client.db.query(
    credential="my-database",
    sql="SELECT * FROM users WHERE active = %s",
    params=[True],
    timeout=30,
)

print(result.columns)     # ["id", "name", "email"]
print(result.rows)        # [[1, "Alice", "alice@example.com"], ...]
print(result.row_count)   # 42

Credentials Management

List credentials:

credentials = client.credentials.list()
credentials = client.credentials.list(type="api_key", environment="production")
credentials = client.credentials.list(search="github")

Get a credential:

cred = client.credentials.get("credential-uuid")

Create a credential:

cred = client.credentials.create(
    name="my-new-api",
    type="api_key",
    data={"api_key": "secret-value"},
    environment="production",
    tags=["external", "payments"],
    base_url="https://api.example.com",
    description="Payment provider API key",
)

Update a credential:

cred = client.credentials.update(
    "credential-uuid",
    description="Updated description",
    tags=["external"],
)

Delete a credential:

client.credentials.delete("credential-uuid")

Error Handling

from safenode import (
    SafeNode,
    SafeNodeError,
    AuthError,
    VaultLockedError,
    RateLimitError,
    NotFoundError,
    ProxyError,
    TimeoutError,
)
import time

client = SafeNode(token="kvt_your_token")

try:
    response = client.proxy.request("my-api", "GET", "/data")
except VaultLockedError:
    print("Vault is locked — re-authentication required")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
    time.sleep(e.retry_after)
except NotFoundError:
    print("Credential not found")
except ProxyError as e:
    print(f"Upstream error: {e}")
except TimeoutError as e:
    print(f"Request timed out: {e}")
except AuthError as e:
    print(f"Authentication failed: {e}")
except SafeNodeError as e:
    print(f"SafeNode error {e.status_code}: {e}")

Context Manager

with SafeNode(token="kvt_your_token") as client:
    result = client.db.query("my-db", "SELECT 1")

Environment Variables

Variable Description
SAFENODE_TOKEN MCP token (kvt_xxx) for auth

Requirements

  • Python 3.9+
  • httpx >= 0.27

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

safenode-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

safenode-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file safenode-0.1.1.tar.gz.

File metadata

  • Download URL: safenode-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for safenode-0.1.1.tar.gz
Algorithm Hash digest
SHA256 be22db9d7dc72bf9612fbb241991547cde3632309f1f2d7916b1c53c97f0437e
MD5 6e8dcfc490d68f9b507c6b13c6e2baae
BLAKE2b-256 80c7166b8a00ef342ec77b5fcb9e39a7c2d581482306ede463fbc24349235dcc

See more details on using hashes here.

File details

Details for the file safenode-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: safenode-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for safenode-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c0f0b5322482d738dc4b2d92c038342be2d32156a04a4ed3e451a63fa3a4be51
MD5 df6802937912af28ed216699c4d558c6
BLAKE2b-256 c3a34ca5c7cf02e976cf05774f2ede95b573170937f4a07e31f1a9247fb65dae

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