Official Python SDK for HydrousDB — records, auth, and analytics.
Project description
hydrousdb · Python SDK
Official Python client for HydrousDB — records, auth, and analytics in one package.
Installation
pip install hydrousdb
Requires Python 3.8+. Zero mandatory third-party dependencies — uses only the standard library.
Quick start
from hydrousdb import create_client
db = create_client(
auth_key="your-auth-key", # auth service key
bucket_key="your-bucket-key", # records, analytics & buckets key
)
Environment variable pattern (recommended)
import os from hydrousdb import create_client db = create_client( auth_key=os.environ["HYDROUS_AUTH_KEY"], bucket_key=os.environ["HYDROUS_BUCKET_KEY"], )
Records
Get a record
result = db.records.get("rec_abc123")
print(result["data"]["name"])
# With version history
result = db.records.get("rec_abc123", show_history=True)
print(result["history"])
Query a collection
# Simple query
result = db.records.query(limit=50, sort_order="desc")
# Filtered query
result = db.records.query(
filters=[{"field": "status", "op": "==", "value": "active"}],
time_scope="7d",
)
for record in result["data"]:
print(record)
# Paginate manually
cursor = None
while True:
result = db.records.query(limit=100, cursor=cursor)
process(result["data"])
cursor = result["meta"].get("nextCursor")
if not cursor:
break
# Or fetch everything automatically
all_records = db.records.query_all(
filters=[{"field": "type", "op": "==", "value": "invoice"}]
)
Supported filter operators: == != > < >= <= contains
Maximum 3 filters per query.
Insert a record
result = db.records.insert(
values={"name": "Alice", "score": 99},
queryable_fields=["name"],
)
print(result["meta"]["id"]) # rec_...
Update a record
db.records.update(
"rec_abc123",
values={"score": 100},
track_history=True,
)
Delete a record
db.records.delete("rec_abc123")
Check existence (HEAD)
info = db.records.exists("rec_abc123")
if info:
print("Found, updated at", info["updated_at"])
else:
print("Not found")
Batch operations
# Batch insert (up to 500)
result = db.records.batch_insert(
[{"name": "Alice"}, {"name": "Bob"}],
queryable_fields=["name"],
)
print(result["meta"]["successful"])
# Batch update
db.records.batch_update([
{"recordId": "rec_1", "values": {"status": "archived"}},
{"recordId": "rec_2", "values": {"status": "archived"}},
])
# Batch delete
db.records.batch_delete(["rec_1", "rec_2", "rec_3"])
Auth
Sign up / Sign in
# Sign up
result = db.auth.sign_up(
"alice@example.com",
"Str0ngP@ss!",
full_name="Alice Smith",
)
session_id = result["session"]["sessionId"]
refresh_token = result["session"]["refreshToken"]
# Sign in
result = db.auth.sign_in("alice@example.com", "Str0ngP@ss!")
session_id = result["session"]["sessionId"]
Session management
# Validate session (use on every protected request)
try:
result = db.auth.validate_session(session_id)
user = result["data"]
except HydrousError as e:
if e.status == 401:
# Session expired
pass
# Refresh session
result = db.auth.refresh_session(refresh_token)
new_session = result["session"]
# Sign out (single device)
db.auth.sign_out(session_id=session_id)
# Sign out (all devices)
db.auth.sign_out(all_devices=True, user_id="user_abc")
User management
# Get user
result = db.auth.get_user("user_abc123")
print(result["data"]["email"])
# List users (paginated)
result = db.auth.list_users(limit=50)
users = result["data"]
cursor = result["meta"].get("nextCursor")
# Fetch all users automatically
all_users = db.auth.list_all_users()
# Update user
db.auth.update_user("user_abc", {"fullName": "Bob Smith"})
# Delete user
db.auth.delete_user("user_abc123")
Password management
# Change password
db.auth.change_password("user_abc", "Old@Pass1", "New@Pass2")
# Request reset email
db.auth.request_password_reset("alice@example.com")
# Confirm reset
db.auth.confirm_password_reset("tok_...", "New@Pass2")
Account control
# Lock for 30 minutes
db.auth.lock_account("user_abc", duration_ms=30 * 60 * 1000)
# Unlock
db.auth.unlock_account("user_abc")
Analytics
Count
result = db.analytics.count()
print(result["data"]["count"]) # 1234
# Scoped to date range
result = db.analytics.count(
date_range={"startDate": "2025-01-01", "endDate": "2025-12-31"}
)
Distribution (histogram)
result = db.analytics.distribution("status")
for item in result["data"]:
print(item["value"], item["count"])
Sum
result = db.analytics.sum("revenue", group_by="region")
print(result["data"]["total"])
Time series
result = db.analytics.time_series(granularity="day")
for point in result["data"]:
print(point["date"], point["count"])
Field time series
result = db.analytics.field_time_series(
"revenue",
aggregation="sum",
granularity="month",
)
Top N
result = db.analytics.top_n("country", 5)
for item in result["data"]:
print(item["label"], item["count"])
Stats (min/max/avg/stddev/percentiles)
result = db.analytics.stats("score")
data = result["data"]
print(data["avg"], data["p99"])
Multi-metric (dashboard stat cards)
result = db.analytics.multi_metric([
{"name": "totalRevenue", "field": "amount", "aggregation": "sum"},
{"name": "avgScore", "field": "score", "aggregation": "avg"},
{"name": "userCount", "field": "userId", "aggregation": "count"},
])
data = result["data"]
print(data["totalRevenue"], data["avgScore"])
Storage stats
result = db.analytics.storage_stats()
print(result["data"]["totalRecords"], result["data"]["totalBytes"])
Cross-bucket comparison
result = db.analytics.cross_bucket(
bucket_keys=["sales", "refunds", "trials"],
field="amount",
aggregation="sum",
)
Error handling
from hydrousdb import HydrousError, HydrousNetworkError, HydrousTimeoutError
try:
result = db.records.get("rec_missing")
except HydrousError as e:
print(e.status) # 404
print(e.code) # "RECORD_NOT_FOUND"
print(e.message) # Human-readable message
print(e.details) # List of validation details
print(e.request_id) # Server request ID for support
except HydrousTimeoutError as e:
print(f"Timed out after {e.timeout_ms}ms")
except HydrousNetworkError as e:
print(f"Network failure: {e.message}")
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
auth_key |
str |
required | Auth service key |
bucket_key |
str |
required | Bucket key (records, analytics, buckets) |
base_url |
str |
https://db-api-82687684612.us-central1.run.app |
Override the API base URL |
timeout |
float |
30.0 |
Request timeout in seconds |
retries |
int |
2 |
Auto-retries on transient errors |
Type hints
All response values are plain Python dicts at runtime. The hydrousdb.types module
exports TypedDict definitions for IDE autocompletion and static analysis:
from hydrousdb.types import GetRecordResponse, SignInResponse, AnalyticsResult
License
MIT © HydrousDB
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hydrousdb-1.0.0.tar.gz.
File metadata
- Download URL: hydrousdb-1.0.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5aa2f86c76c83a9d6893bbd27672e3d8628b77f1de886080537ad2c2cd217aab
|
|
| MD5 |
f68e2aa26d920745965a6638f574fe9d
|
|
| BLAKE2b-256 |
1f3c4bcd8ab355a1f3926bf734a5a21877d350144b3d8e09c25681ce2973a1f5
|
File details
Details for the file hydrousdb-1.0.0-py3-none-any.whl.
File metadata
- Download URL: hydrousdb-1.0.0-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2293c2a9d96410310c537551c28e7e4d62b06d91a74738ea950a2ca5aba07c84
|
|
| MD5 |
b9e39302197af74720a1694660db4324
|
|
| BLAKE2b-256 |
a56c88bfead98debd3997bf92d9e98727c4cebd5213c1832f34e49cd0b234482
|