Skip to main content

Official Python SDK for Lubes

Project description

agentbase

Official Python SDK for AgentBase.

Installation

pip install agentbase

Quick Start

from agentbase import AgentBase

# Initialize with API key
client = AgentBase(
    api_key="your-api-key",
    org="your-org",
    project="your-project",
)

# List tables
tables = client.list_tables()
for table in tables:
    print(table.name)

# Execute a query
result = client.execute_query("SELECT * FROM users LIMIT 10")
for row in result.rows:
    print(row)

Authentication

API Key Authentication

client = AgentBase(
    api_key="ab_your_api_key_here",
    org="my-org",
    project="my-project",
)

Email/Password Authentication

client = AgentBase(api_url="https://api.agentbase.dev")

# Login
user, tokens = client.login(
    email="user@example.com",
    password="password",
)

# Set org and project
client.set_org("my-org").set_project("my-project")

Async Support

import asyncio
from agentbase import AsyncAgentBase

async def main():
    async with AsyncAgentBase(
        api_key="your-api-key",
        org="my-org",
        project="my-project",
    ) as client:
        # List tables
        tables = await client.list_tables()

        # Execute query
        result = await client.execute_query("SELECT * FROM users")
        print(result.rows)

asyncio.run(main())

Database Operations

List Tables

tables = client.list_tables()
for table in tables:
    print(f"{table.name}: {table.row_count} rows")

Get Table Schema

schema = client.get_table_schema("users")
for column in schema.columns:
    print(f"{column.name}: {column.type}")

Execute Queries

# Simple query
result = client.execute_query("SELECT * FROM users WHERE active = true")

# Parameterized query
result = client.execute_query(
    "SELECT * FROM users WHERE email = $1",
    params=["user@example.com"]
)

print(f"Found {result.row_count} rows")
for row in result.rows:
    print(row)

Database Branches

# List branches
branches = client.list_branches()

# Create branch
branch = client.create_branch(name="feature-branch")

# Delete branch
client.delete_branch("feature-branch")

Functions

List Functions

functions = client.list_functions()
for fn in functions:
    print(f"{fn.name} ({fn.runtime})")

Invoke Function

result = client.invoke_function("my-function", payload={"input": "data"})
print(result.result)
print(f"Execution time: {result.execution_time_ms}ms")

Function Logs

logs = client.get_function_logs("my-function", limit=50)
for log in logs:
    print(f"[{log.level}] {log.message}")

Deployments

# List deployments
deployments = client.list_deployments()

# Create deployment
deployment = client.create_deployment(description="New feature release")

# Rollback
client.rollback_deployment(deployment.id)

Environment Variables

# List env vars
env_vars = client.list_env_vars()

# Create env var
env_var = client.create_env_var(
    key="API_KEY",
    value="secret-value",
    is_secret=True,
)

# Reveal secret value
revealed = client.reveal_env_var(env_var.id)
print(revealed.value)

Storage

Buckets

# List buckets
buckets = client.list_buckets()

# Create bucket
bucket = client.create_bucket(name="my-bucket", is_public=False)

Objects

# List objects
objects, total, has_more = client.list_objects(bucket.id, prefix="uploads/")

# Get signed URL for download
signed_url = client.get_signed_url(
    bucket.id,
    key="uploads/file.pdf",
    expires_in=3600,
)
print(signed_url.url)

# Delete object
client.delete_object(bucket.id, "uploads/file.pdf")

Webhooks

# Create webhook
webhook = client.create_webhook(
    name="My Webhook",
    url="https://example.com/webhook",
    events=["deployment.created", "deployment.completed"],
)

# Get deliveries
deliveries, total = client.get_webhook_deliveries(webhook.id)

Organization Management

# List organizations
orgs = client.list_organizations()

# Create organization
org = client.create_organization(name="My Org", slug="my-org")

# Invite member
member = client.invite_member(email="teammate@example.com", role="member")

Error Handling

from agentbase import AgentBase, AgentBaseError

try:
    result = client.execute_query("INVALID SQL")
except AgentBaseError as e:
    print(f"Error: {e.code} - {e.message}")
    if e.details:
        print(f"Details: {e.details}")

Configuration Options

client = AgentBase(
    api_url="https://api.agentbase.dev",  # API URL (default)
    api_key="your-api-key",               # API key authentication
    access_token="jwt-token",             # JWT token authentication
    org="your-org",                       # Organization slug
    project="your-project",               # Project slug
    timeout=30.0,                         # Request timeout in seconds (default: 30)
)

Context Manager

# Synchronous
with AgentBase(api_key="key", org="org", project="project") as client:
    tables = client.list_tables()

# Asynchronous
async with AsyncAgentBase(api_key="key", org="org", project="project") as client:
    tables = await client.list_tables()

Type Hints

Full type hints are provided via Pydantic models:

from agentbase import (
    User,
    Organization,
    Project,
    TableSchema,
    QueryResult,
    ServerlessFunction,
    Deployment,
    EnvVar,
    Bucket,
    StorageObject,
    Webhook,
)

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

lubes-0.1.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

lubes-0.1.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file lubes-0.1.0.tar.gz.

File metadata

  • Download URL: lubes-0.1.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for lubes-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed9c3612800e1fc94784eec9e5cf1f75a8e1291f42eab0ee6e2c570f4c00cbeb
MD5 7b54435d6b5f263740d9b9f5db490488
BLAKE2b-256 54807ce509d7668bb39b37b5013a9d70050128182e09da446d8731bd810a718f

See more details on using hashes here.

File details

Details for the file lubes-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lubes-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for lubes-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ded119d5d245099853c50670d9fb4f00f14418e981624dc029c2eb9f756ce826
MD5 7d3e0e5a746728df30d29adb79c8702a
BLAKE2b-256 f6fc14070bbf63bfb51dfcff8bb8c8d4df2ac46767dc13b5629edf057c34dbc8

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