Python bindings for samod - Rust implementation of automerge-repo
Project description
samod-py
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file samod-0.5.0a2.tar.gz.
File metadata
- Download URL: samod-0.5.0a2.tar.gz
- Upload date:
- Size: 143.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6033336b8d6d39dd11274fe5a68a66b384b4b2e2d3db09983dd798cc5ad93dbc
|
|
| MD5 |
35656badc9e1ded281a1691c3781c4e1
|
|
| BLAKE2b-256 |
a2ffe1c9088e83a73e93620a82e42fde06cd0bce00548809a64e375b6a122fda
|
File details
Details for the file samod-0.5.0a2-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: samod-0.5.0a2-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6666fdee3c3e36496d31a7e5ab514bdfebf5bf0e52bd5cd6c2a26af258c07ed0
|
|
| MD5 |
03e56250b1ee8db0edc3a25f368d61cd
|
|
| BLAKE2b-256 |
9e1a3c1c8915c4f10f9091cea0d5a93ccbb9b3da4f2f0f9d9d7e909dd0306497
|