The official Python SDK for AnkhDB - Real-time Multi-tenant BaaS.
Project description
ankhdb
The official Python SDK for AnkhDB — a self-hosted, multi-tenant Backend-as-a-Service with Auth, Database, Storage, and Edge Functions.
Installation
pip install ankhdb
Quick Start
from ankhdb import AnkhDB
db = AnkhDB("YOUR_PROJECT_ID", "YOUR_API_KEY")
# Self-hosted: AnkhDB("proj_...", "ankh_sec_...", server_url="http://localhost:5000")
Error Handling
All errors raise typed exceptions derived from AnkhDBError:
from ankhdb import AuthError, NotFoundError, RateLimitError
try:
db.login("user@example.com", "wrong")
except AuthError as e:
print("Bad credentials", e.status)
except RateLimitError:
print("Slow down!")
| Class | HTTP Status |
|---|---|
AnkhDBError |
base (all errors) |
ValidationError |
400 |
AuthError |
401 |
PermissionError |
403 |
NotFoundError |
404 |
RateLimitError |
429 |
ServerError |
5xx |
Authentication
db.register("user@example.com", "password")
db.login("user@example.com", "password")
session = db.get_session()
db.logout()
Database — Query Builder
db.from_collection(name) returns a chainable AnkhQuery:
posts = db.from_collection("posts")
# Basic CRUD
doc = posts.insert({"title": "Hello", "views": 0})
all = posts.select()
one = posts.get(doc["id"])
posts.update(doc["id"], {"views": 1})
posts.delete(doc["id"])
# Filters
popular = (db.from_collection("posts")
.gt("views", 100)
.eq("status", "published")
.select())
# Pagination
page2 = db.from_collection("posts").limit(10).offset(10).select()
# Join (embed related collection)
with_comments = (db.from_collection("posts")
.join("comments", "postId") # embed where comments.postId == post.id
.select())
# Realtime subscription (blocking)
def on_event(event):
print(event["event"], event["data"]) # INSERT / UPDATE / DELETE
db.from_collection("posts").subscribe(on_event)
Storage
uploaded = db.storage_upload("/path/to/image.png")
print(uploaded["url"])
files = db.storage_list()
db.storage_delete(uploaded["id"])
Edge Functions
res = db.invoke_function("greet", {"name": "Alice"})
print(res["result"])
License
MIT © KemetSoft
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 ankhdb-2.0.2.tar.gz.
File metadata
- Download URL: ankhdb-2.0.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
431d8d95c96cd3773194acf8c059dcb311d98f28dc9dacfe4b5240b29c6ebdac
|
|
| MD5 |
805653f13c15b8b8858f97b6ac918f57
|
|
| BLAKE2b-256 |
8463191d7e394cf469095fe7d7aee6afcdf6e43703742929b001e8379e419be6
|
File details
Details for the file ankhdb-2.0.2-py3-none-any.whl.
File metadata
- Download URL: ankhdb-2.0.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e914433d94e8531c723dfd61a6edf42c3c6d21deefea5f1f4fed04147461d26
|
|
| MD5 |
465f60047920c6e6cd3b6467a5c8a902
|
|
| BLAKE2b-256 |
1d0b25e3554bca9f52ad8b884e615e44aebc4b841c0ee730580a140004439535
|