Python SDK
The Python SDK is generated from the OpenAPI spec. All endpoints are available, but the ergonomics are more verbose than the TypeScript or Go SDKs.
Install
pip install aerostackInitialize
from aerostack import AerostackClient
client = AerostackClient(
project_id="your-project-id",
api_key="your-api-key",
base_url="https://api.aerostack.ai/v1"
)Authentication
# Verify a token
user = await client.auth.verify_token(token)
if not user:
raise Exception("Unauthorized")
# Register
result = await client.auth.register(
email="[email protected]",
password="password123",
name="Jane Doe"
)
# Login
result = await client.auth.login(
email="[email protected]",
password="password123"
)
access_token = result.access_tokenDatabase
# Query
users = await client.db.query("SELECT * FROM users WHERE active = 1")
# Single row
user = await client.db.query_one(
"SELECT * FROM users WHERE id = ?",
[user_id]
)
# Insert
await client.db.query(
"INSERT INTO posts (id, title, user_id) VALUES (?, ?, ?)",
[post_id, title, user_id]
)Realtime
channel = client.realtime.channel("orders")
@channel.on("INSERT")
async def on_insert(payload):
print(f"New order: {payload.data}")
channel.subscribe()
# Server-side broadcast
client.socket.emit("order:updated", {"id": order_id}, f"orders/{order_id}")Cache
# Set with TTL (seconds)
await client.cache.set("user:123", user_data, ttl=300)
# Get
user = await client.cache.get("user:123")
if not user:
# cache miss
passSee API Reference for the full method listing.