feat(python-sdk): add Python SDK with async client, signing, and AI m…#80
Open
harrymove-ctrl wants to merge 3 commits intodevfrom
Open
feat(python-sdk): add Python SDK with async client, signing, and AI m…#80harrymove-ctrl wants to merge 3 commits intodevfrom
harrymove-ctrl wants to merge 3 commits intodevfrom
Conversation
| import pytest | ||
|
|
||
| from memwal.client import MemWal, MemWalError, MemWalSync | ||
| from memwal.utils import bytes_to_hex |
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import json |
|
|
||
| import asyncio | ||
| import json | ||
| from typing import Any, List |
| import asyncio | ||
| import json | ||
| from typing import Any, List | ||
| from unittest.mock import AsyncMock, MagicMock, patch |
|
|
||
| import httpx | ||
| import nacl.signing | ||
| import pytest |
Collaborator
|
Hi @harrymove-ctrl please adjust this part to match the sdk part of the current typescript. |
PR #121 made remember/analyze async on the server: client gets HTTP 202 + job_id back in ~500ms instead of waiting ~18s for the full Walrus upload + chain commit. Update the Python SDK to match the new TypeScript SDK contract so all four downstream targets (Python apps, FastAPI, AI middleware, OpenClaw plugin) get the same UX win. Surface (mirrors TS): - remember() / remember_async() now return RememberAcceptedResult - wait_for_remember_job() polls /api/remember/{id} with jittered exp backoff + transient retry (matches TS pollingDelayMs + isTransientPollingStatus) - remember_and_wait() convenience wraps both - Bulk family: remember_bulk[_async] / get_remember_bulk_status / wait_for_remember_jobs / remember_bulk_and_wait - analyze() returns job_ids + fact_count; analyze_and_wait() polls every fact's remember job to completion - embed() exposes /api/embed for raw vectors - New typed exceptions: MemWalRememberJobNotFound / Failed / Timeout - MemWalSync wrapper exposes every new async method Signing: - build_signature_message() now includes the nonce + account_id segments the server requires (MED-1 replay protection + LOW-23 account-hint binding). Client generates a UUID nonce per request and sends x-nonce header; without this the server rejects with HTTP 426 "unsupported legacy SDK". Verified end-to-end against a local server (testnet): - remember() returned 202 in 58ms (the PR #121 win) - wait_for_remember_job() settled blob_id after ~30s of upload+commit - recall() returned decrypted plaintext via SEAL - remember_bulk_and_wait() handled 3 items across 3 wallets, all done - See packages/python-sdk-memwal/examples/interactive_demo.py for the reproducible demo and the full server-log evidence.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Port the MemWal SDK to Python mirrors the TypeScript client exactly with the same methods, same
relayer, same auth flow.
Why
Currently only a TypeScript SDK exists.
What changed
MemWal.create()withremember,recall,analyze,ask,restore,health. Sync wrapperMemWalSyncincluded for scripts and notebooks.{timestamp}.{METHOD}.{path}.{sha256(body)}. Includesdelegate_key_to_sui_address()anddelegate_key_to_public_key()utils.with_memwal_langchain(llm, ...)wraps anyBaseChatModel. Recallsrelevant memories before each call, injects them as a
SystemMessagebefore the last user message,and fire-and-forgets
analyze()after each call.with_memwal_openai(client, ...)works with bothAsyncOpenAIandOpenAI. Patcheschat.completions.createwith the same inject-before + analyze-after pattern.OpenAI), and integration tests against a live relayer.
docs/sdk/overview.md: Python SDK section added.Types of Changes
Testing
relayer.dev.memwal.ai)