Skip to main content

The official Python SDK for Afribase — an open-source backend-as-a-service platform.

Project description

Afribase Python SDK

The official Python client for Afribase — an open-source backend-as-a-service platform.

Installation

pip install afribase

Quick Start

from afribase import create_client

client = create_client("https://your-project.useafribase.app", "your-anon-key")

Authentication

# Sign up
res = client.auth.sign_up(email="user@example.com", password="secret123")

# Sign in
res = client.auth.sign_in_with_password(email="user@example.com", password="secret123")

# OAuth
url = client.auth.sign_in_with_oauth(provider="google")

# OTP / Magic Link
client.auth.sign_in_with_otp(email="user@example.com")
res = client.auth.verify_otp(email="user@example.com", token="123456")

# Sign out
client.auth.sign_out()

# Listen for auth changes
def on_change(event, session):
    print(f"Auth event: {event}")

unsubscribe = client.auth.on_auth_state_change(on_change)

Database (PostgREST Query Builder)

# Select
data = client.from_("posts").select("*").eq("published", "true").execute()

# Insert
data = client.from_("posts").insert({"title": "Hello", "body": "World"}).execute()

# Update
data = client.from_("posts").update({"title": "Updated"}).eq("id", "1").execute()

# Delete
data = client.from_("posts").delete().eq("id", "1").execute()

# Filters
data = (
    client.from_("posts")
    .select("*")
    .gte("likes", "10")
    .order("created_at", desc=True)
    .limit(20)
    .execute()
)

# RPC (Postgres functions)
result = client.rpc("my_function", {"arg": "value"}).execute()

Storage

# Upload
client.storage.from_("avatars").upload("avatar.png", file_bytes)

# Download
data = client.storage.from_("avatars").download("avatar.png")

# Signed URL
url = client.storage.from_("avatars").create_signed_url("avatar.png", expires_in=3600)

# Public URL (with optional transforms)
url = client.storage.from_("avatars").get_public_url("avatar.png", transform={"width": 200})

# List files
files = client.storage.from_("avatars").list(path="folder/")

# Move / Copy
client.storage.from_("avatars").move("old.png", "new.png")
client.storage.from_("avatars").copy("source.png", "dest.png")

# Bucket management
buckets = client.storage.list_buckets()
client.storage.create_bucket("my-bucket", public=True)

Edge Functions

result = client.functions.invoke("my-function", body={"name": "world"})

Realtime

# Create a channel
channel = client.channel("room1")

# Listen for broadcast messages
channel.on_broadcast("message", callback=lambda payload: print(payload))

# Listen for Postgres changes
channel.on_postgres_changes(
    "INSERT",
    schema="public",
    table="messages",
    callback=lambda payload: print(payload),
)

# Presence
channel.on_presence_sync(callback=lambda state: print(state))

# Subscribe
channel.subscribe()

# Send broadcast
channel.send_broadcast("message", {"text": "Hello!"})

# Track presence
channel.track({"user": "alice", "status": "online"})

Requirements

  • Python 3.9+
  • httpx >= 0.25.0
  • websockets >= 12.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

afribase-0.2.3.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

afribase-0.2.3-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file afribase-0.2.3.tar.gz.

File metadata

  • Download URL: afribase-0.2.3.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for afribase-0.2.3.tar.gz
Algorithm Hash digest
SHA256 c4de8ce6d214482cddd7df187098db7b75d1b2ed1873c63448486dd87108e3c5
MD5 b162bcfb0f715ab0767079207f1662bb
BLAKE2b-256 2a67ae96c3204f1a3aa2f9a1534306e1ba784d2120c2ee5e9cfa8a5ffcb9e4f7

See more details on using hashes here.

File details

Details for the file afribase-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: afribase-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for afribase-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2d8cdad301747861ef4723a6c15e5bc212587838634baf358b0b151bbd55f4c0
MD5 b59e751489070596e99661668616cd46
BLAKE2b-256 77a22f8b2deb47824e88227646fb1d36ff3a8aa514a916f2481fa2f2f0adfe1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page