Notifications
In-app notifications and email notification settings. Each cell prints the request line (→) and the backend’s JSON reply.
The test email is off: set SEND_EMAILS = True to send one.
Config
Add your settings to the repo .env (local) or Colab Secrets — this cell reads them with get(...):
INDOX_API_KEY (your ak_… key) and INDOX_BASE_URL (https://indox.org; the SDK adds /api/v1/… itself). A missing key stops here with its name.
import json, logging, re, sys, tempfile
from pathlib import Path
REPO = Path.cwd().parents[1]
sys.path[:0] = [str(REPO), str(REPO / "languages" / "python")]
try:
from google.colab import userdata
get = userdata.get
except ImportError:
from tools.env import require_env as get
from indox_client import Indox
logging.basicConfig(format="→ %(message)s", force=True)
logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)
def _mask(record):
record.msg = re.sub(r"/(public|sign)/[^/ ]+", r"/\1/***", record.getMessage())
record.args = ()
return True
logging.getLogger("urllib3.connectionpool").addFilter(_mask)
def show(data, limit=2500):
print(json.dumps(data, indent=2, default=str)[:limit])
client = Indox(api_key=get("INDOX_API_KEY"), base_url=get("INDOX_BASE_URL"))
start_credits = client.billing.credits_balance()["credit_amount"]
SAMPLES = REPO / "colab"
out = Path(tempfile.mkdtemp())notes = client.notifications.list(page_size=3)
assert notes["count"] >= len(notes["results"])
show({**notes, "results": [{k: v for k, v in n.items() if k != "message"} for n in notes["results"]]})unread = client.notifications.unread_count()
assert unread["unread_count"] >= 0
show(unread)marked = client.notifications.mark_all_read()
assert client.notifications.unread_count()["unread_count"] == 0
show(marked)settings = client.notifications.settings()
flipped = client.notifications.update_settings(storage_warnings=not settings["storage_warnings"])
assert flipped["storage_warnings"] != settings["storage_warnings"]
show([settings, flipped])restored = client.notifications.update_settings(storage_warnings=settings["storage_warnings"])
assert restored == settings
show(restored)SEND_EMAILS = False
if SEND_EMAILS:
show(client.notifications.send_test_email())
else:
print("skipped")Usage
now = client.billing.credits_balance()["credit_amount"]
print(f"credits used by this notebook: {start_credits - now} (balance {now})")
show(client.billing.usage_by_feature())