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

Uploaded Python 3

File details

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

File metadata

  • Download URL: afribase-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 00d9b75eaf2bc0850f12b93e8289029f0e4ec93c1edef58d311184234e0a1d74
MD5 9370f79b195cb058b8ba03b3fe3c5306
BLAKE2b-256 0399dc530e09a44c559f8f894c2c4852e56d1d83747ac014b797696d7c3b77f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: afribase-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16bf04de7fb6931bc4055a7a4ef67e9a8a07f06140d1544a4cca322ce9a23f08
MD5 e060bb01717c97a0e82727371d3f4fcc
BLAKE2b-256 1a7def5a7fb21c19ba2f063b10637196cf38f4866585eee085387a375638113b

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