SDK Reference
Official SDKs for TypeScript, Python, and Go. Type-safe, fully-featured, and production-ready.
Overview
Lubes provides official SDKs for the most popular languages. Each SDK provides full access to all Lubes features with type-safe APIs.
TypeScript SDK
Installation
npm install @lubes/sdk
# or
yarn add @lubes/sdk
# or
pnpm add @lubes/sdkInitialization
import { Lubes } from '@lubes/sdk'
const lubes = new Lubes({
projectId: process.env.LUBES_PROJECT_ID!,
apiKey: process.env.LUBES_API_KEY!,
})
// Destructure services
const { db, storage, auth, functions, realtime } = lubesDatabase
// Query with tagged template literals (auto-parameterized)
const users = await db.query`
SELECT * FROM users WHERE status = ${'active'}
`
// Single result
const user = await db.queryOne`
SELECT * FROM users WHERE id = ${userId}
`
// Transactions
await db.transaction(async (tx) => {
await tx.query`UPDATE accounts SET balance = balance - ${amount} WHERE id = ${fromId}`
await tx.query`UPDATE accounts SET balance = balance + ${amount} WHERE id = ${toId}`
})
// Real-time subscriptions
const subscription = db.subscribe('messages', { event: 'INSERT' }, (payload) => {
console.log('New message:', payload.new)
})
// Unsubscribe
subscription.unsubscribe()Storage
// Upload file
const { url, key } = await storage.upload('avatars', {
file: fileBlob,
contentType: 'image/png',
public: true,
})
// Download file
const data = await storage.download('avatars/user-123.png')
// Create signed URL
const signedUrl = await storage.createSignedUrl('documents/report.pdf', {
expiresIn: 3600, // 1 hour
})
// List files
const files = await storage.list('avatars', {
prefix: 'user-',
limit: 100,
})
// Delete file
await storage.remove('avatars/old-avatar.png')Authentication
// Sign up
const { user, session } = await auth.signUp({
email: 'user@example.com',
password: 'secure-password',
metadata: { name: 'John Doe' },
})
// Sign in
const { user, session } = await auth.signIn({
email: 'user@example.com',
password: 'secure-password',
})
// OAuth sign in
await auth.signInWithOAuth({
provider: 'github',
redirectTo: 'https://myapp.com/auth/callback',
})
// Get current user
const user = await auth.getUser()
// Sign out
await auth.signOut()SSH Keys
// List SSH keys
const { keys } = await lubes.listSshKeys()
// Add SSH key
const key = await lubes.createSshKey({
name: 'MacBook Pro',
publicKey: 'ssh-ed25519 AAAA...',
})
// Delete SSH key
await lubes.deleteSshKey(keyId)Git Repository
// Get repository info
const repo = await lubes.getRepository()
console.log(repo.ssh_url) // git@git.lubes.dev:org/project.git
console.log(repo.clone_url) // https://git.lubes.dev/org/project.git
// List branches
const { branches } = await lubes.listRepositoryBranches()
// List commits
const { commits } = await lubes.listRepositoryCommits({
branch: 'main',
limit: 20,
})Python SDK
Installation
pip install lubes
# or
poetry add lubesSynchronous Client
from lubes import Lubes
client = Lubes(
project_id="your-project-id",
api_key="your-api-key"
)
# Database queries
users = client.db.query("SELECT * FROM users WHERE status = %s", ["active"])
user = client.db.query_one("SELECT * FROM users WHERE id = %s", [user_id])
# Storage
url = client.storage.upload("avatars", file_data, content_type="image/png")
data = client.storage.download("avatars/user-123.png")
# Auth
user = client.auth.sign_up(
email="user@example.com",
password="secure-password"
)Async Client
from lubes import AsyncLubes
import asyncio
async def main():
client = AsyncLubes(
project_id="your-project-id",
api_key="your-api-key"
)
# Async database queries
users = await client.db.query("SELECT * FROM users")
# Async storage upload
url = await client.storage.upload("avatars", file_data)
# Real-time subscriptions
async def on_message(payload):
print(f"New message: {payload['new']}")
await client.realtime.subscribe("messages", on_message)
asyncio.run(main())Pydantic Models
from lubes.models import User, Project, Function
from pydantic import BaseModel
# Built-in models
user: User = client.auth.get_user()
print(user.email, user.created_at)
# Custom models for your data
class Task(BaseModel):
id: str
title: str
completed: bool
tasks = client.db.query("SELECT * FROM tasks", model=Task)
for task in tasks:
print(task.title, task.completed)SSH Keys & Git Repository
# SSH Keys
keys = client.list_ssh_keys()
key = client.create_ssh_key("MacBook Pro", "ssh-ed25519 AAAA...")
client.delete_ssh_key(key_id)
# Git Repository
repo = client.get_repository()
print(repo.ssh_url) # git@git.lubes.dev:org/project.git
branches = client.list_repository_branches()
commits = client.list_repository_commits(branch="main", limit=20)Go SDK
Installation
go get github.com/ailubes/lubes-goInitialization
package main
import (
"context"
"log"
lubes "github.com/ailubes/lubes-go"
)
func main() {
client, err := lubes.NewClient(
lubes.WithProjectID("your-project-id"),
lubes.WithAPIKey("your-api-key"),
)
if err != nil {
log.Fatal(err)
}
defer client.Close()
}Database
ctx := context.Background()
// Query rows
type User struct {
ID string `db:"id"`
Email string `db:"email"`
Name string `db:"name"`
CreatedAt time.Time `db:"created_at"`
}
var users []User
err := client.DB.Query(ctx, &users, "SELECT * FROM users WHERE status = $1", "active")
// Single row
var user User
err := client.DB.QueryOne(ctx, &user, "SELECT * FROM users WHERE id = $1", userID)
// Execute (insert, update, delete)
result, err := client.DB.Exec(ctx, `
INSERT INTO users (email, name) VALUES ($1, $2)
`, email, name)
// Transactions
err := client.DB.Transaction(ctx, func(tx *lubes.Tx) error {
_, err := tx.Exec(ctx, "UPDATE accounts SET balance = balance - $1 WHERE id = $2", amount, fromID)
if err != nil {
return err
}
_, err = tx.Exec(ctx, "UPDATE accounts SET balance = balance + $1 WHERE id = $2", amount, toID)
return err
})Storage
ctx := context.Background()
// Upload file
result, err := client.Storage.Upload(ctx, "avatars", file, &lubes.UploadOptions{
ContentType: "image/png",
Public: true,
})
// Download file
data, err := client.Storage.Download(ctx, "avatars/user-123.png")
// Create signed URL
url, err := client.Storage.CreateSignedURL(ctx, "documents/report.pdf", &lubes.SignedURLOptions{
ExpiresIn: time.Hour,
})
// List files
files, err := client.Storage.List(ctx, "avatars", &lubes.ListOptions{
Prefix: "user-",
Limit: 100,
})SSH Keys & Git Repository
ctx := context.Background()
// SSH Keys
keys, err := client.ListSshKeys(ctx)
key, err := client.CreateSshKey(ctx, "MacBook Pro", "ssh-ed25519 AAAA...")
err = client.DeleteSshKey(ctx, keyID)
// Git Repository
repo, err := client.GetRepository(ctx)
fmt.Println(repo.SshURL) // git@git.lubes.dev:org/project.git
branches, err := client.ListRepositoryBranches(ctx)
commits, err := client.ListRepositoryCommits(ctx, &lubes.CommitOptions{
Branch: "main",
Limit: 20,
})Common Types
All SDKs provide consistent type definitions:
TypeScript Types
interface User {
id: string
email: string
name?: string
avatar_url?: string
created_at: string
updated_at: string
}
interface Session {
access_token: string
refresh_token: string
expires_at: number
user: User
}
interface Project {
id: string
name: string
slug: string
organization_id: string
created_at: string
}
interface Function {
id: string
name: string
slug: string
runtime: 'deno' | 'node'
status: 'active' | 'inactive'
url: string
}
interface Bucket {
id: string
name: string
public: boolean
file_size_limit?: number
allowed_mime_types?: string[]
}
interface SshKey {
id: string
name: string
fingerprint: string
key_type: string
created_at: string
last_used_at?: string
}
interface Repository {
id: string
provider: string
ssh_url?: string
clone_url?: string
default_branch: string
status: string
}
interface GitBranch {
name: string
commit_sha: string
is_default: boolean
protected: boolean
}
interface GitCommit {
sha: string
message: string
author: string
timestamp: string
}