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.0.tar.gz (15.3 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.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: afribase-0.2.0.tar.gz
  • Upload date:
  • Size: 15.3 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.0.tar.gz
Algorithm Hash digest
SHA256 90012b9da1d37685261ac6cfced37137d7637dac75eed1ee0b583d95ff31411c
MD5 a74476ce00aca90d82918ce8d6f7b245
BLAKE2b-256 c610325e34171832f987373660fa9c9da8afe529e59bf53fc5812a982a16ddcf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: afribase-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99458b8cc04dc18e295b8b11a78f1f9df1e09c64b0f3216e43d8ecadad4be4c7
MD5 95d21e02579ccb86298f4e18341ba1ba
BLAKE2b-256 d606f9ea5f9cc79451a711a272ef188e8933f548e28438ab5a5229249a896167

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