Skip to content

Basic python binding for samod#30

Open
rgbkrk wants to merge 8 commits intoalexjg:mainfrom
rgbkrk:python-binding
Open

Basic python binding for samod#30
rgbkrk wants to merge 8 commits intoalexjg:mainfrom
rgbkrk:python-binding

Conversation

@rgbkrk
Copy link

@rgbkrk rgbkrk commented Nov 13, 2025

This introduces a samod-py crate and a samod python module

Building and installing a dev copy:

$ maturin build --release && pip install -e .
🔗 Found pyo3 bindings with abi3 support
🐍 Found CPython 3.13 at /Users/kylekelley/.pyenv/versions/3.13.5/bin/python3
📡 Using build options features from pyproject.toml
💻 Using `MACOSX_DEPLOYMENT_TARGET=11.0` for aarch64-apple-darwin by default
warning: /Users/kylekelley/code/src/github.com/alexjg/samod/Cargo.toml: unused manifest key: workspace.edition
warning: /Users/kylekelley/code/src/github.com/alexjg/samod/samod-test-harness/Cargo.toml: unused manifest key: lib.pulish
   Compiling pyo3-build-config v0.24.2
   Compiling pyo3-macros-backend v0.24.2
   Compiling pyo3-ffi v0.24.2
   Compiling pyo3 v0.24.2
   Compiling pyo3-macros v0.24.2
   Compiling pyo3-async-runtimes v0.24.0
   Compiling samod-py v0.5.0 (/Users/kylekelley/code/src/github.com/alexjg/samod/samod-py)
    Finished `release` profile [optimized] target(s) in 5.27s
📦 Built wheel for abi3 Python ≥ 3.8 to /Users/kylekelley/code/src/github.com/alexjg/samod/target/wheels/samod-0.5.0-cp38-abi3-macosx_11_0_arm64.whl
Obtaining file:///Users/kylekelley/code/src/github.com/alexjg/samod/samod-py
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Building wheels for collected packages: samod
  Building editable for samod (pyproject.toml) ... done
  Created wheel for samod: filename=samod-0.5.0-cp38-abi3-macosx_11_0_arm64.whl size=1960285 sha256=9d105fef32bcd1beb992694c1300ddff6a1afe9f10d9ebdd19511ada9756d7ce
  Stored in directory: /private/var/folders/nr/rds9xrgx3dq8sp5f1vd4nrxm0000gn/T/pip-ephem-wheel-cache-j3ej4487/wheels/fc/7a/02/2687b6b351288a87e440302bb48ccedbe6507d8c1661f507d2
Successfully built samod
Installing collected packages: samod
  Attempting uninstall: samod
    Found existing installation: samod 0.5.0
    Uninstalling samod-0.5.0:
      Successfully uninstalled samod-0.5.0
Successfully installed samod-0.5.0

[notice] A new release of pip is available: 25.1.1 -> 25.3
[notice] To update, run: pip install --upgrade pip

Usage via IPython (top level await for demo usage):

In [1]: import samod

In [2]: repo = samod.Repo()

In [3]: await repo.connect_websocket("ws://localhost:3030")

In [4]: repo
Out[4]: Repo(peer_id='peer-1786318232826254744')

In [5]: doc = await repo.create()

In [6]: doc
Out[6]: DocHandle(url='automerge:2NTndzsvyj3rEZgYDBBKbjZhiAmg')

In [7]: await doc.set_string("title", "Hello from Python (via Rust)")

In [8]: doc.url()
Out[8]: 'automerge:2NTndzsvyj3rEZgYDBBKbjZhiAmg'

In [9]:
Do you really want to exit ([y]/n)? y

Session 2

In [1]: import samod

In [2]: repo = samod.Repo()

In [3]: await repo.connect_websocket("ws://localhost:3030")

In [4]: doc = await repo.find('automerge:2NTndzsvyj3rEZgYDBBKbjZhiAmg')

In [5]: await doc.get_string('title')
Out[5]: 'Hello from Python (via Rust)'

Also hi from SyncConf. If you're here at the conference today let me know!

@rgbkrk rgbkrk changed the title Basic samod binding for python via PyO3 Basic python binding for samod Nov 13, 2025
}
}

impl std::fmt::Display for AutomergeUrl {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight, I should probably just use this and not pluck out the document ID.

@rgbkrk
Copy link
Author

rgbkrk commented Nov 13, 2025

Apparently I need to build TLS support in as well.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant