Metadata-Version: 2.4
Name: ankhdb
Version: 2.0.1
Summary: The official Python SDK for AnkhDB - Real-time Multi-tenant BaaS.
Author-email: KemetSoft <yusufsameh347@gmail.com>
Project-URL: Homepage, https://github.com/ankhdb/ankhdb-python
Project-URL: Bug Tracker, https://github.com/ankhdb/ankhdb-python/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28.0
Dynamic: license-file

# ankhdb

[![PyPI version](https://img.shields.io/pypi/v/ankhdb.svg)](https://pypi.org/project/ankhdb/)

The official Python SDK for **AnkhDB** — a self-hosted, multi-tenant Backend-as-a-Service with Auth, Database, Storage, and Edge Functions.

## Installation

```bash
pip install ankhdb
```

## Quick Start

Find your **Project ID** and **API Key** in the AnkhDB Dashboard → **Settings**.

```python
from ankhdb import AnkhDB

db = AnkhDB("YOUR_PROJECT_ID", "YOUR_API_KEY")

# Self-hosted / local override:
# db = AnkhDB("YOUR_PROJECT_ID", "YOUR_API_KEY", server_url="http://localhost:5000")
```

---

## Authentication

Manage your app's end-users. Enable **Require Email Verification** in the dashboard to gate logins behind email confirmation.

```python
# Register a new user
res = db.register("user@example.com", "securepassword")
# res["token"] is set automatically (or absent if email verification is required)

# Login
db.login("user@example.com", "securepassword")

# Check current session
session = db.get_session()

# Logout (clears local token)
db.logout()
```

---

## Database

Schema-free NoSQL collections with optional Row-Level Security (RLS) policies.

```python
posts = db.from_collection("posts")

# Insert
doc = posts.insert({"title": "Hello AnkhDB", "author": "Alice"})

# Read all
all_posts = posts.select()

# Read one
one = posts.get(doc["id"])

# Update
posts.update(doc["id"], {"title": "Updated Title"})

# Delete
posts.delete(doc["id"])
```

---

## Storage

Upload and manage files up to 50 MB per file.

```python
# Upload a local file
uploaded = db.storage_upload("/path/to/image.png")
print(uploaded["url"])  # Public URL

# List all files
files = db.storage_list()

# Get file metadata
meta = db.storage_get(uploaded["id"])

# Delete
db.storage_delete(uploaded["id"])
```

---

## Edge Functions

Invoke serverless JavaScript functions you write in the AnkhDB Dashboard.

```python
# Invoke a function named "greet"
res = db.invoke_function("greet", {"name": "Alice"})
print(res["result"])  # Whatever the function set on `result`
```

**Example function code (written in the dashboard):**
```javascript
result = { greeting: `Hello, ${payload.name}!` };
```

---

## API Reference

| Method | Description |
|---|---|
| `AnkhDB(project_id, api_key, server_url?, token?)` | Create a client. |
| `db.register(email, password)` | Register a new end-user. |
| `db.login(email, password)` | Login and auto-store JWT. |
| `db.logout()` | Clear the local token. |
| `db.get_session()` | Verify token, get user info. |
| `db.from_collection(name)` | Get a query builder for a collection. |
| `db.get_collections()` | List all collections. |
| `db.storage_upload(filepath, filename?)` | Upload a local file. |
| `db.storage_list()` | List all uploaded files. |
| `db.storage_get(id)` | Get file metadata + URL. |
| `db.storage_delete(id)` | Delete a file. |
| `db.invoke_function(name, payload?)` | Invoke an edge function. |

---

## License

MIT © KemetSoft
