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.2.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.2-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: afribase-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 de06a652de594c8d8c01382dd894aed7afea0253220634a70c1780152d1c1c0a
MD5 f09465b4e63a229aba7740ee3328087c
BLAKE2b-256 d330589de95fec4171d483d8e5a7709e08f062e31b1e73e6333af45ef6ff5b82

See more details on using hashes here.

File details

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

File metadata

  • Download URL: afribase-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 19.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 face9c91127a12d0ebd29321b237b686a71b8f7e812e3cacfdd93dd8e4169b02
MD5 a56a35049d5c6f3b7426d4955b21c305
BLAKE2b-256 fb9493494682e969e72fa2ec7bcbbeb26667f4b3a2e0166d2e5948739cd3e7c3

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