Architecture
How calimero-client-py is structured internally
Overview
calimero-client-py is a Python extension module built with PyO3 and Maturin. The Python API is a thin synchronous wrapper around an async Rust client — each method call spins up a Tokio runtime internally to drive async requests to completion before returning a result to Python.
Python layer
calimero/ package re-exports all types from the compiled Rust extension calimero_client_py.so.
PyO3 bindings
src/*.rs wraps every Rust type with a #[pyclass] and every function with #[pyfunction] for seamless Python interop.
Rust core
calimero_client crate provides the actual HTTP transport, auth, and serialization, shared with other Calimero tooling.
Module Structure
Async Model
Python code calls synchronous methods — no async/await needed. Internally, each method creates or reuses a Tokio runtime (Runtime::block_on) that runs the async Rust future to completion before handing the result back to Python.
Simpler Python ergonomics
Python users benefit from straightforward synchronous calls without needing to manage event loops. The Rust layer handles all async complexity internally.
Thread safety
PyO3 acquires the GIL for all Python object creation (Python::with_gil). The async Rust work runs outside the GIL via block_on, allowing other threads to run during network I/O.
Authentication Flow
detect_auth_mode()
Call conn.detect_auth_mode() to probe the node. Returns AuthMode("none") for open nodes or AuthMode("required") for authenticated ones.
CliAuthenticator
When auth is required, the CliAuthenticator prompts the user in the terminal for credentials, obtains JWT tokens from the node, and stores them via MeroboxFileStorage.
Token cache
Tokens are cached at ~/.merobox/auth_cache/{node_name}-{hash}.json. Subsequent calls reuse cached tokens and refresh automatically before expiry.