Skip to main content

Official Python SDK for Lubes

Project description

lubes

Official Python SDK for Lubes.

Installation

pip install lubes

Quick Start

from lubes import Lubes

# Initialize with API key
client = Lubes(
    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 = Lubes(
    api_key="lb_your_api_key_here",
    org="my-org",
    project="my-project",
)

Email/Password Authentication

client = Lubes(api_url="https://api.lubes.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 lubes import AsyncLubes

async def main():
    async with AsyncLubes(
        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")

SSH Keys

# List SSH keys
keys = client.list_ssh_keys()

# Add SSH key
key = client.add_ssh_key(
    name="My Laptop",
    public_key="ssh-ed25519 AAAA..."
)

# Delete SSH key
client.delete_ssh_key(key.id)

Repositories

# Get repository info
repo = client.get_repository()
print(f"Clone URL: {repo.ssh_url}")

# List branches
branches = client.list_repository_branches()

# List commits
commits = client.list_repository_commits(branch="main", limit=10)

Error Handling

from lubes import Lubes, LubesError

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

Configuration Options

client = Lubes(
    api_url="https://api.lubes.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 Lubes(api_key="key", org="org", project="project") as client:
    tables = client.list_tables()

# Asynchronous
async with AsyncLubes(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 lubes import (
    User,
    Organization,
    Project,
    TableSchema,
    QueryResult,
    ServerlessFunction,
    Deployment,
    EnvVar,
    Bucket,
    StorageObject,
    Webhook,
    SshKey,
    RepositoryInfo,
)

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.1.tar.gz (18.2 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.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lubes-0.1.1.tar.gz
  • Upload date:
  • Size: 18.2 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.1.tar.gz
Algorithm Hash digest
SHA256 838b9cf7af32e11e2a653961d6b06c4d659c462764d555d44294fa6ff035e148
MD5 361478dec54d3c8ff5e756814eb302d4
BLAKE2b-256 c3a19e5d94337db30d85322815d27767102f09c59e1e16694b3b887059898055

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lubes-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c842bca00d31957a1fc59c9511647a945f8bcc938f4054498c111f2426ca3849
MD5 e13026a15c5f0f5f3e7412c606dbf0dc
BLAKE2b-256 a3f628d86edd2983911c334a822556072be99626a8796538508bb902ee74b24a

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