Python Client
Python client for ezAuth. Only dependency is httpx. Python 3.11+.
Installation
pip install ezauth-client
Initialization
from ezauth_client import EZAuth
# Backend (secret key)
ez = EZAuth(
base_url="https://auth.example.com",
secret_key="sk_live_...",
)
# Frontend (publishable key)
ez = EZAuth(
base_url="https://auth.example.com",
publishable_key="pk_live_...",
)
Constructor Parameters
| Parameter | Type | Description |
|---|---|---|
base_url | str | EZAuth instance URL |
secret_key | str | None | Secret key for admin operations |
publishable_key | str | None | Publishable key for frontend auth |
access_token | str | None | Access token for user-scoped operations |
Error Handling
from ezauth_client import EZAuth, EZAuthError
try:
ez.users.get("nonexistent")
except EZAuthError as e:
print(e.message) # "User not found"
print(e.status) # 404
print(e.code) # error code string, if provided
ez.auth (Publishable Key)
sign_up(email, *, password=None, redirect_url=None, hashcash=None)
ez.auth.sign_up("[email protected]", password="s3cret")
# Returns: {"status": "verification_sent", "user_id": "uuid"}
sign_in(email, *, password=None, strategy=None, redirect_url=None)
# Password
session = ez.auth.sign_in("[email protected]", password="s3cret")
# Magic link
ez.auth.sign_in("[email protected]", redirect_url="https://myapp.com")
verify_code(email, code)
session = ez.auth.verify_code("[email protected]", "482917")
# Returns: {"access_token": "...", "refresh_token": "...", "user_id": "...", "session_id": "..."}
get_session(*, access_token=None)
me = ez.auth.get_session(access_token="eyJhbG...")
# Returns: {"user_id": "...", "email": "...", "email_verified": true}
sign_out(*, access_token=None)
ez.auth.sign_out(access_token="eyJhbG...")
refresh_token(refresh_token)
new_session = ez.auth.refresh_token("rt_...")
sso_exchange(token)
session = ez.auth.sso_exchange("sso_token")
sign_in_with_oauth(provider, redirect_url)
result = ez.auth.sign_in_with_oauth("google", "https://myapp.com/callback")
# result["authorization_url"] — redirect the user here
request_challenge()
challenge = ez.auth.request_challenge()
# {"challenge": "...", "difficulty": 5, "algorithm": "argon2id", "params": {...}}
ez.users (Secret Key)
list(*, limit=None, offset=None, email=None)
result = ez.users.list(limit=10)
# result["users"], result["total"]
create(email, *, password=None)
user = ez.users.create("[email protected]", password="optional")
get(user_id)
user = ez.users.get("user-uuid")
ez.sessions (Secret Key)
revoke(session_id)
ez.sessions.revoke("session-uuid")
create_sign_in_token(user_id, *, expires_in_seconds=None)
result = ez.sessions.create_sign_in_token("user-uuid", expires_in_seconds=300)
ez.tables
create(name, *, columns=None)
table = ez.tables.create("contacts", columns=[
{"name": "name", "type": "text", "required": True},
{"name": "age", "type": "int"},
])
list() / get(table_id) / delete(table_id)
tables = ez.tables.list()
table = ez.tables.get("table-uuid")
ez.tables.delete("table-uuid")
tables.columns.add / update / delete
col = ez.tables.columns.add("table-uuid", "email", "text", required=True)
ez.tables.columns.update("table-uuid", "col-uuid", name="full_name")
ez.tables.columns.delete("table-uuid", "col-uuid")
tables.rows.insert / get / update / delete / query
row = ez.tables.rows.insert("table-uuid", {"name": "Alice", "age": 30})
row = ez.tables.rows.get("table-uuid", "row-uuid")
ez.tables.rows.update("table-uuid", "row-uuid", {"age": 31})
ez.tables.rows.delete("table-uuid", "row-uuid")
result = ez.tables.rows.query(
"table-uuid",
filter={"field": "age", "op": "gte", "value": 18},
sort={"field": "name", "dir": "asc"},
limit=50,
)
ez.buckets
create(name) / list() / get(bucket_id) / delete(bucket_id)
bucket = ez.buckets.create("avatars")
buckets = ez.buckets.list()
bucket = ez.buckets.get("bucket-uuid")
ez.buckets.delete("bucket-uuid")
buckets.objects.put(bucket_id, key, data, content_type=None, *, user_id=None)
ez.buckets.objects.put("bucket-uuid", "alice.png", image_bytes, "image/png")
buckets.objects.get(bucket_id, key, *, user_id=None)
data, content_type = ez.buckets.objects.get("bucket-uuid", "alice.png")
# Returns: (bytes, str)
buckets.objects.delete(bucket_id, key, *, user_id=None)
ez.buckets.objects.delete("bucket-uuid", "alice.png")
buckets.objects.list(bucket_id, *, user_id=None, limit=None, cursor=None)
result = ez.buckets.objects.list("bucket-uuid", limit=50)
# result["objects"], result["next_cursor"]
ez.storage
tables() / objects()
table_usage = ez.storage.tables()
object_usage = ez.storage.objects()
# {"used_bytes": 1048576, "limit_bytes": 104857600, "used_percent": 1.0}