API Reference¶
CloudSyncClient¶
The primary entry point for the SDK.
Constructor¶
CloudSyncClient(
api_key: str,
region: str = "us-east-1",
transport: str = "websocket",
**kwargs
) -> CloudSyncClient
Methods¶
connect()¶
Establishes a connection to the CloudSync relay server. Blocks until disconnected.
connect_async()¶
Non-blocking connection. Returns a Future.
disconnect()¶
Gracefully terminates the connection and flushes pending operations.
document(key: str) -> Document¶
Opens or creates a synchronized document.
| Parameter | Type | Description |
|---|---|---|
key |
str |
Unique document identifier. Supports / for namespacing. |
collection(prefix: str) -> Collection¶
Returns a queryable collection of documents sharing a key prefix.
status() -> ConnectionStatus¶
Returns the current connection state.
ping() -> float¶
Measures round-trip latency to the relay server in milliseconds.
Document¶
Represents a single synchronized document.
Methods¶
set(data: dict) -> None¶
Replaces the document contents.
get(field: str = None) -> Any¶
Reads the full document or a specific field.
update(field: str, value: Any) -> None¶
Updates a single field without replacing the entire document.
delete(field: str = None) -> None¶
Deletes a specific field, or the entire document if no field is given.
on(event: str, callback: Callable) -> None¶
Registers an event listener.
Supported events:
| Event | Description |
|---|---|
change |
A field was created, updated, or deleted |
sync |
Full document state received from remote |
conflict |
A merge conflict was detected |
error |
An error occurred on this document |
snapshot() -> dict¶
Returns a point-in-time copy of the document state.
history(limit: int = 50) -> list[Revision]¶
Returns the revision history.
revisions = doc.history(limit=10)
for rev in revisions:
print(f"{rev.timestamp} | {rev.author} | {rev.delta}")
Collection¶
A queryable set of documents sharing a key prefix.
Methods¶
find(query: dict = None) -> list[Document]¶
Queries documents in the collection.
count(query: dict = None) -> int¶
Returns the number of matching documents.
watch() -> AsyncIterator[Event]¶
Watches for changes across the entire collection.
Data Types¶
from cloudsync.types import Counter, Register, Set
# CRDT Counter — safe concurrent increment/decrement
views = Counter(0)
views.increment(1)
views.decrement(1)
# CRDT Last-Write-Wins Register
status = Register("active")
status.set("inactive")
# CRDT Observed-Remove Set
tags = Set()
tags.add("python")
tags.add("sdk")
tags.remove("sdk")
Next: Authentication →