Pre-release
This release is a pre-release and may not be stable for production use.
samod
Python bindings for Automerge via samod.
Development
pip install maturin
cd samod-py
maturin develop --release
Usage
import asyncio
import samod
async def main():
repo = samod.Repo()
print(f"Peer ID: {repo.peer_id()}")
# Connect to sync server
await repo.connect_websocket("ws://localhost:3030")
# Create a document
doc = await repo.create()
await doc.set_string("title", "Hello World")
# Read it back
title = await doc.get_string("title")
print(f"Title: {title}")
url = await doc.url()
print(f"Automerge URL: {url}")
# Find an existing document
existing = await repo.find("automerge:...")
if existing:
keys = await existing.get_keys()
print(f"Keys: {keys}")
await repo.stop()
asyncio.run(main())
API
Repo
Repository managing documents, storage, and sync.
Methods:
Repo()- Create repo with in-memory storagepeer_id() -> str- Get this peer's IDasync connect_websocket(url: str)- Connect to WebSocket sync serverasync when_connected(peer_id: str)- Block until connected to specific peerasync find(doc_id: str) -> Optional[DocHandle]- Find document by AutomergeUrlasync create() -> DocHandle- Create new documentasync stop()- Stop repo and abort background connections
Connection handling:
connect_websocket() spawns connections in the background. Use when_connected(peer_id) to wait for a specific peer, or asyncio.sleep() as a workaround when the peer ID is unknown.
DocHandle
Handle to an Automerge document.
Methods:
async document_id() -> str- Get document ID (AutomergeUrl)async dump() -> bytes- Serialize document to bytesasync get_keys() -> List[str]- List all root-level keysasync get_string(key: str) -> Optional[str]- Get string fieldasync set_string(key: str, value: str)- Set string field
Development
# Development build
maturin develop
# Release build
maturin develop --release
# Build wheel
maturin build --release
Architecture Notes
This package relies on PyO3 and pyo3-async-runtimes to bind the core automerge/samod Rust code in Python with native async await support.
License
MIT
Metadata
Release files for samod 0.5.0a3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| samod-0.5.0a3.tar.gz | 144.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| samod-0.5.0a3-cp38-abi3-macosx_11_0_arm64.whl | CPython 3.8 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 2.2 MB
Release files / samod-0.5.0a3.tar.gz
| Download URL | samod-0.5.0a3.tar.gz |
|---|---|
| Size | 144.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aac32aadc1fdee73be9b8a6b72836799624d07941b54f10ae1dd97c80a3981e9
|
|
BLAKE2b-256 checksum How to use checksums |
c3bd99996e7d6f2b12b9eba51604505af7df1228b21f3837db2559614e3e1a07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.1
|
Release files / samod-0.5.0a3-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | samod-0.5.0a3-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
96edfc3a24c5e0c89b3b2067382bf8916e5fd423a4f9d607ffb192a432ed1f42
|
|
BLAKE2b-256 checksum How to use checksums |
a1c13789df042fccea5289ee35b8bc794fbad8913a13d07e0c810a76edde6c68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.1
|