Memory + Wallet for AI Agents. Give any agent persistent memory and micropayment capabilities.
Project description
MnemoPay Python SDK
The governance layer for AI agents that handle money — Python edition. Mirrors the TypeScript @mnemopay/sdk shape so the same agent identity, score, charter, and audit chain work across both runtimes.
from mnemopay import MnemoPay
agent = MnemoPay("my-agent")
agent.remember("user prefers Python")
tx = agent.charge(10.00, "API call")
agent.settle(tx.id)
Install
pip install mnemopay # stdlib-only core
pip install "mnemopay[stripe]" # + StripeRail (peer-loaded `stripe>=12.0`)
What MnemoPay is NOT: not a bank, not a money transmitter, not a Stripe replacement, not an agent framework. It sits above the rail and below the runtime — declares the rules, enforces the budget, produces the evidence.
Features
- Payment rails (v1.0.0b4 — parity with TS v1.6.x):
MockRail+StripeRailwith manual-capture two-phase commit, threading-safe capture race-protection, idempotency-key forwarding - Cognitive Memory: Ebbinghaus decay, Hebbian reinforcement, auto-scoring, Layer 2 semantic recall + RL feedback
- Micropayments: escrow-based charges with volume-tiered fees (1.9% / 1.5% / 1.0%)
- Agent FICO: agent credit scoring (300-850 range; not consumer FICO, not FCRA-regulated)
- Behavioral Finance: prospect theory, cooling-off periods, regret prediction
- Merkle Integrity: SHA-256 tamper detection for agent memory
- Anomaly Detection: EWMA streaming detector, behavioral fingerprinting, canary honeypots
- Commerce: autonomous shopping engine with mandates + escrow
- Circuit Breaker: AIMD rate limiting, anti-gaming, PSI drift detection
- Stdlib core: zero required dependencies — peer-deps only when you opt in (e.g.
stripe) - Python 3.9+: full type hints, dataclasses, sync API (matches the rest of the SDK)
Modules
| Module | Class | Description |
|---|---|---|
mnemopay.core |
MnemoPay |
Memory + payments + reputation |
mnemopay.rails |
PaymentRail, MockRail, StripeRail |
Payment rail abstraction (v1.0.0b4) |
mnemopay.fico |
AgentFICO |
Credit scoring (300-850) |
mnemopay.behavioral |
BehavioralEngine |
Behavioral finance tools |
mnemopay.integrity |
MerkleTree |
SHA-256 tamper detection |
mnemopay.anomaly |
EWMADetector, BehaviorMonitor, CanarySystem |
Anomaly detection |
mnemopay.commerce |
CommerceEngine, CommerceProvider, Mandate |
Autonomous shopping |
mnemopay.circuit_breaker |
CircuitBreaker, AIMDRateLimiter, AntiGamingEngine, PSIDriftDetector |
Adaptive defense |
Payment rails (v1.0.0b4)
Mirrors the TypeScript PaymentRail interface. Same shape (create_hold / capture_payment / reverse_payment), same drop-in-swap semantics. Sync API to match the rest of the Python SDK — no asyncio.
from mnemopay.rails import StripeRail, MockRail, HoldOptions
# Default — no infra, in-memory ledger, used in tests + dev
rail = MockRail()
# Production — real Stripe PaymentIntents with manual-capture two-phase commit
rail = StripeRail(secret_key="sk_test_...")
# Two-phase commit (hold → capture)
hold = rail.create_hold(
amount=25.00,
reason="Monthly access",
agent_id="agent-1",
opts=HoldOptions(
customer_id="cus_real",
payment_method_id="pm_real",
off_session=True,
metadata={"idempotencyKey": "req_abc"},
),
)
capture = rail.capture_payment(hold.external_id, 25.00)
# capture.status == "succeeded"
# capture.receipt_id == "ch_..." # Stripe charge id
# Or reverse (cancel the hold) instead of capturing
rail.reverse_payment(hold.external_id, 25.00)
StripeRail includes onboarding helpers for off-session charges:
result = rail.create_customer("user@example.com", name="Jerry O")
# {"customer_id": "cus_..."}
result = rail.create_setup_intent(customer_id="cus_...")
# {"setup_intent_id": "seti_...", "client_secret": "..."}
For tests, inject a mock client:
from unittest.mock import MagicMock
rail = StripeRail.from_client(MagicMock(), currency="usd")
Compatibility with @mnemopay/sdk (TypeScript)
| Feature | TypeScript v1.6.0-alpha.1 | Python v1.0.0b4 |
|---|---|---|
MockRail |
yes | yes |
StripeRail |
yes | yes |
PaystackRail |
yes | not yet |
LightningRail |
yes | not yet |
StripeMPPRail (alpha) |
yes | not yet |
X402Rail (alpha) |
yes | not yet |
GoogleAP2Rail (alpha) |
yes | not yet |
| Charter / FiscalGate / Article 12 (governance) | yes | not yet |
| Agent Credit Score | yes | yes |
| Behavioral Finance | yes | yes |
| Merkle integrity | yes | yes |
| Anomaly detection (EWMA + canary) | yes | yes |
| Commerce engine | yes | yes |
| Circuit breaker | yes | yes |
The Python SDK ships behind the TypeScript SDK — port priorities track agent-developer demand. Open an issue if you need a specific rail or governance primitive in Python.
Tests
pip install -e ".[dev,stripe]"
pytest # 422 tests across 9 modules
pytest tests/test_rails.py -v # 29 rail-specific tests
License
MIT — see LICENSE.
Copyright 2026 J&B Enterprise LLC.
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 mnemopay-1.0.0b4.tar.gz.
File metadata
- Download URL: mnemopay-1.0.0b4.tar.gz
- Upload date:
- Size: 68.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a3f0cdca10a9f8c05c75364d2c292f9bb338bfdf0df5abdf19400ec52890d70
|
|
| MD5 |
19a5c479cf86a260c1dab28828e92cde
|
|
| BLAKE2b-256 |
874e8cfa052acc201382f0ef6ac03ff9eb31e9ecf68c9d5941455b021f8f49bd
|
File details
Details for the file mnemopay-1.0.0b4-py3-none-any.whl.
File metadata
- Download URL: mnemopay-1.0.0b4-py3-none-any.whl
- Upload date:
- Size: 49.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee5c0b8ed7d3736bb7aad5ee07a3e24b8b5549a289fc2afa53eea219aac37017
|
|
| MD5 |
f8649207ee67105f7a2279ac8f5db717
|
|
| BLAKE2b-256 |
c51ab455b76346556da1c681e6d81d309ef02f42719a62611fee0f6b67c32bb5
|