Metadata-Version: 2.4
Name: mizan-sdk
Version: 0.11.3
Summary: MIZAN is the second ledger of the economy. Payment networks record what was paid; MIZAN records whether it was earned. check(subject) before you pay, hire or allocate; every answer is an Ed25519-signed verdict you verify offline. Free. Standard library only.
Author-email: MIZAN <muavia@mizan.market>
License-Expression: MIT
Project-URL: Homepage, https://mizan.market
Project-URL: Documentation, https://mizan.market/developers/
Project-URL: Verdict format, https://mizan.market/verdict/
Project-URL: OpenAPI, https://mizan.market/skill/openapi.json
Project-URL: MCP, https://studio.mizan.market/mcp
Project-URL: Source, https://github.com/muaviamohammed/mizan
Project-URL: Issues, https://github.com/muaviamohammed/mizan/issues
Project-URL: Changelog, https://mizan.market/verdict/changelog/
Keywords: mizan,ai-agents,agent-payments,x402,ap2,mcp,a2a,erc-8004,verification,ed25519,signed-verdict,zero-knowledge,proof-of-performance,zkvm,stark,deflated-sharpe,backtest-overfitting,algorithmic-trading
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: fast
Requires-Dist: cryptography>=41; extra == "fast"
Dynamic: license-file

# mizan-sdk

**MIZAN is the second ledger of the economy. Payment networks record what was paid; MIZAN records whether it was earned.**

Before you pay, hire or allocate to anyone, ask MIZAN. Every answer is an Ed25519-signed verdict you verify on your own machine, offline, with the published keys. Free, no key, no account. Python 3.9+, standard library only.

```bash
pip install mizan-sdk
```

```python
import mizan
v = mizan.check("try-me")                                   # 1. signed verdict: v.decision, v.grade, v.why, v.token
assert mizan.verify_token(v.token)["ok"]                    # 2. offline: Ed25519 against https://mizan.market/.well-known/mizan-keys.json
pay = mizan.guard(pay, rule="at least 90% of at least 50 settled jobs", mode="enforce")   # 3. REFUSE raises mizan.Refused
```

`try-me` is the sandbox subject (always ALLOW); any `stranger-*.example` is REFUSE. Same call over HTTP: `curl https://studio.mizan.market/api/check/try-me`.

## The three things you can do

### check — before money moves

```python
v = mizan.check("acme-agent.example")          # an agent id, a domain, an API/MCP/A2A URL, github:<user>, npm:<pkg>, pypi:<project>, a wallet
v.decision                                     # "ALLOW" | "REFUSE"
v.grade                                        # "PROVEN" | "RECORDED" | None
v.why                                          # one line: what was met, or why not
v.allow                                        # True only when MIZAN said ALLOW AND the token verified here, offline
v.next                                         # on a REFUSE: the proof request to forward; the next check returns ALLOW when it is met
v.token                                        # "mzv1.…" — staple it to the payment; the payee verifies it offline
```

Bind the verdict to one payment: `mizan.check(subject, payee=subject, amount=5, currency="USD")`. Carry it on x402 as `accepts[i].extra.mizan = {"token", "kid"}`, or as the HTTP header `Mizan-Verdict: mzv1.…`. `check()` never raises on a network problem: the Verdict is REFUSE with `.why` and `.next`.

### require — say what you need, in plain words

```python
rule = mizan.require("at least 90% of at least 50 settled jobs")
rule.id          # "sha256:…" for a compiled rule, "req_…@1" for a published one
rule.readback    # MIZAN's own reading of your words — checking under it means you accept that reading
mizan.check("acme-agent.example", rule)        # the verdict under YOUR rule
```

`require()` fails closed: a word or number MIZAN did not understand raises `RequirementNotUnderstood` with MIZAN's reasons and did-you-mean suggestions. Nothing is rewritten for you. Starter rules: `mizan.templates()`, `mizan.template("allocator-diligence", sharpe=1.5)`.

### guard — wrap the function that pays

```python
pay = mizan.guard(pay)                                        # advise (default): logs every verdict, always proceeds
pay = mizan.guard(pay, rule=rule, mode="enforce")             # enforce: raises mizan.Refused on anything but a verified ALLOW

@mizan.guard(mode="enforce")
def release(payee: str, amount: float): ...
```

The payee is `payee=` / `subject=` when given, else the first positional argument (a URL is reduced to its host). `pay.last_verdict` holds the most recent Verdict; `on_decision=` receives every one. Pay-rail specific guards (x402 402 terms, release/escrow) live in `mizan.x402guard` and `mizan.release`.

### verify — offline, forever

```python
r = mizan.verify_token(token)                 # {"ok", "code", "reason", "claims"}; no network
r = mizan.verify_token(token, payee="0xabc…", rule="sha256:…", amount=5, currency="USD")
```

Codes: `valid · malformed · unknown_kid · bad_signature · expired · payee_mismatch · rule_mismatch · amount_mismatch · key_retired · revoked · superseded`. The signing key is compiled in (`kid 2266fb495f83b0a0`); a token under a newer key fetches the published key set once and caches it for 24 h, pinned by key id. `MIZAN_OFFLINE=1` never fetches; `MIZAN_PINNED_KEYS` pins your own copy. With `pip install "mizan-sdk[fast]"` verification runs in well under a millisecond; without it a pure-Python RFC 8032 verifier gives the same answer.

## Keys (only when you want to be identified)

`check`, `require`, `guard` and `verify_token` need no key. A key identifies *you* (your record, listing, published rules):

```python
mizan.login()                 # self-serve: POST /api/agents/claim → key shown once, kept in MIZAN_API_KEY and ~/.mizan/sdk/api_key
mizan.login(api_key="mzn_…")  # a key you already hold (or set MIZAN_API_KEY)
```

Every error is a `MizanError` with `.code` and `.next` (the one action that fixes it).

## Prove your own record (the other side of the ledger)

```python
cred = mizan.prove(positions, markets=["btc_4h", "eth_4h"], alias="my-agent")   # free preview, then a real STARK proof on the GPU prover
mizan.verify(cred.bundle)                                                        # the public verifier binary, sha256-pinned; exit 0 = verified
```

`positions` is one column per market, one row per bar-move, values are leverages. The prover sees positions, never code; the credential reveals neither. Command line: `mizan verify <file|0x…>` (free gate preview, every check shown), `mizan check <subject>` (exit 0 ALLOW / 1 REFUSE, CI-ready). A credential attests to the honesty of a past record, never to future returns.

## Reference

- Developers: https://mizan.market/developers/ · verdict format: https://mizan.market/verdict/ · codes: https://mizan.market/verdict/codes/
- OpenAPI 3.1: https://mizan.market/skill/openapi.json · MCP: `https://studio.mizan.market/mcp` (`check(subject, rule)`) · A2A: https://studio.mizan.market/.well-known/agent-card.json
- Keys: https://mizan.market/.well-known/mizan-keys.json · one map: https://mizan.market/.well-known/mizan.json · status: https://mizan.market/status/
- Source and issues: https://github.com/muaviamohammed/mizan · TypeScript: `npm install mizan-agent-tools`

Environment: `MIZAN_BASE` (API origin, default `https://studio.mizan.market`), `MIZAN_API_KEY`, `MIZAN_HOME` (default `~/.mizan/sdk`), `MIZAN_OFFLINE`, `MIZAN_PINNED_KEYS`, `MIZAN_CHECK_BEFORE_PAY` / `MIZAN_REQUIRE` (zero-config `mizan.auto(pay)`).

MIT. The verifier and this client are open; the prover is not part of this package.
