tracelock 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ Metadata-Version: 2.4
2
+ Name: tracelock
3
+ Version: 0.1.0
4
+ Summary: Python SDK and tlock CLI for TraceLock deterministic tool-call replay
5
+ Project-URL: Homepage, https://tracelock-pied.vercel.app
6
+ Project-URL: Documentation, https://tracelock-pied.vercel.app/docs
7
+ Keywords: idempotency,ai-agents,tool-calls,replay,audit,llmops
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Topic :: Security
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: httpx<1,>=0.27
19
+ Requires-Dist: cryptography<51,>=42
20
+
21
+ # TraceLock SDK
22
+
23
+ Guard side-effecting tool calls before they happen, then replay production traces offline.
24
+
25
+ ```bash
26
+ pip install tracelock
27
+ export TRACELOCK_API_KEY="tlk_..."
28
+ ```
29
+
30
+ For a local checkout, install with `pip install ./TraceLock/sdk`.
31
+
32
+ ## One-line wrapper
33
+
34
+ ```python
35
+ from tracelock import TraceLockClient, guard_call
36
+
37
+ client = TraceLockClient()
38
+
39
+ result = guard_call(
40
+ client,
41
+ "refund_user",
42
+ {"user_id": "u_123", "amount": 50},
43
+ lambda args: stripe.Refund.create(**args),
44
+ idempotency_fields=["user_id", "amount"],
45
+ )
46
+ ```
47
+
48
+ If TraceLock returns `replay`, `in_progress`, `awaiting_approval`, or `denied`, the
49
+ side effect is not executed. If it returns `execute`, the wrapper runs the call and
50
+ records the result/latency automatically.
51
+
52
+ ## CLI
53
+
54
+ ```bash
55
+ tlock --api-key "$TRACELOCK_API_KEY" guard \
56
+ --tool refund_user \
57
+ --args '{"user_id":"u_123","amount":50,"reason":"retry"}' \
58
+ --fields user_id,amount
59
+
60
+ tlock result --guard-id g_... --result '{"refund_id":"rf_1"}'
61
+ tlock export --trace-id tr_... --out trace.json
62
+ tlock replay --file trace.json
63
+ tlock statement
64
+ ```
65
+
66
+ `replay` is fully offline: it verifies the Ed25519 signature using the public key
67
+ embedded in the bundle (or `--public-key`) and never contacts a live API.
68
+
69
+ ## Notes
70
+
71
+ - API key env: `TRACELOCK_API_KEY`
72
+ - Base URL env: `TRACELOCK_BASE_URL` (default `https://tracelock-pied.vercel.app`)
73
+ - `tlock verify` stores the API key in `.tlock_key`; add that file to `.gitignore`.
@@ -0,0 +1,53 @@
1
+ # TraceLock SDK
2
+
3
+ Guard side-effecting tool calls before they happen, then replay production traces offline.
4
+
5
+ ```bash
6
+ pip install tracelock
7
+ export TRACELOCK_API_KEY="tlk_..."
8
+ ```
9
+
10
+ For a local checkout, install with `pip install ./TraceLock/sdk`.
11
+
12
+ ## One-line wrapper
13
+
14
+ ```python
15
+ from tracelock import TraceLockClient, guard_call
16
+
17
+ client = TraceLockClient()
18
+
19
+ result = guard_call(
20
+ client,
21
+ "refund_user",
22
+ {"user_id": "u_123", "amount": 50},
23
+ lambda args: stripe.Refund.create(**args),
24
+ idempotency_fields=["user_id", "amount"],
25
+ )
26
+ ```
27
+
28
+ If TraceLock returns `replay`, `in_progress`, `awaiting_approval`, or `denied`, the
29
+ side effect is not executed. If it returns `execute`, the wrapper runs the call and
30
+ records the result/latency automatically.
31
+
32
+ ## CLI
33
+
34
+ ```bash
35
+ tlock --api-key "$TRACELOCK_API_KEY" guard \
36
+ --tool refund_user \
37
+ --args '{"user_id":"u_123","amount":50,"reason":"retry"}' \
38
+ --fields user_id,amount
39
+
40
+ tlock result --guard-id g_... --result '{"refund_id":"rf_1"}'
41
+ tlock export --trace-id tr_... --out trace.json
42
+ tlock replay --file trace.json
43
+ tlock statement
44
+ ```
45
+
46
+ `replay` is fully offline: it verifies the Ed25519 signature using the public key
47
+ embedded in the bundle (or `--public-key`) and never contacts a live API.
48
+
49
+ ## Notes
50
+
51
+ - API key env: `TRACELOCK_API_KEY`
52
+ - Base URL env: `TRACELOCK_BASE_URL` (default `https://tracelock-pied.vercel.app`)
53
+ - `tlock verify` stores the API key in `.tlock_key`; add that file to `.gitignore`.
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tracelock"
7
+ version = "0.1.0"
8
+ description = "Python SDK and tlock CLI for TraceLock deterministic tool-call replay"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ keywords = ["idempotency", "ai-agents", "tool-calls", "replay", "audit", "llmops"]
12
+ classifiers = [
13
+ "Development Status :: 3 - Alpha",
14
+ "Intended Audience :: Developers",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Topic :: Security",
20
+ "Topic :: Software Development :: Libraries :: Python Modules",
21
+ ]
22
+ dependencies = [
23
+ "httpx>=0.27,<1",
24
+ "cryptography>=42,<51",
25
+ ]
26
+
27
+ [project.urls]
28
+ Homepage = "https://tracelock-pied.vercel.app"
29
+ Documentation = "https://tracelock-pied.vercel.app/docs"
30
+
31
+ [project.scripts]
32
+ tlock = "tracelock.cli:main"
33
+
34
+ [tool.setuptools.packages.find]
35
+ include = ["tracelock*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,8 @@
1
+ """TraceLock Python SDK and one-line tool-call guard."""
2
+ from __future__ import annotations
3
+
4
+ from .client import TraceLockClient, TraceLockError
5
+ from .wrap import guard_call
6
+
7
+ __all__ = ["TraceLockClient", "TraceLockError", "guard_call"]
8
+ __version__ = "0.1.0"
@@ -0,0 +1,145 @@
1
+ """Command line interface for TraceLock: `tlock`."""
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import json
6
+ import os
7
+ import sys
8
+ from typing import Any
9
+
10
+ from .client import DEFAULT_BASE_URL, TraceLockClient, TraceLockError
11
+ from .replay import load_bundle, replay_bundle
12
+
13
+
14
+ def _json(value: str | None, default: Any) -> Any:
15
+ if not value:
16
+ return default
17
+ try:
18
+ return json.loads(value)
19
+ except json.JSONDecodeError as exc:
20
+ raise argparse.ArgumentTypeError(f"Invalid JSON: {exc}") from exc
21
+
22
+
23
+ def _fields(value: str) -> list[str]:
24
+ return [item.strip() for item in value.split(",") if item.strip()]
25
+
26
+
27
+ def build_parser() -> argparse.ArgumentParser:
28
+ parser = argparse.ArgumentParser(prog="tlock", description="TraceLock CLI")
29
+ parser.add_argument("--base-url", default=os.environ.get("TRACELOCK_BASE_URL", DEFAULT_BASE_URL))
30
+ parser.add_argument("--api-key", default=os.environ.get("TRACELOCK_API_KEY", ""))
31
+ sub = parser.add_subparsers(dest="command", required=True)
32
+
33
+ register = sub.add_parser("register", help="Register a client and request email verification")
34
+ register.add_argument("--email", required=True)
35
+ register.add_argument("--client-id")
36
+
37
+ verify = sub.add_parser("verify", help="Verify email and save the returned API key locally")
38
+ verify.add_argument("--client-id", required=True)
39
+ verify.add_argument("--code", required=True)
40
+
41
+ sub.add_parser("whoami", help="Show current client identity and usage")
42
+
43
+ guard = sub.add_parser("guard", help="Guard a tool call before executing it")
44
+ guard.add_argument("--tool", required=True)
45
+ guard.add_argument("--args", required=True, help="JSON object of tool arguments")
46
+ guard.add_argument("--fields", default="", help="Comma-separated idempotency fields")
47
+ guard.add_argument("--window", type=int, default=300)
48
+ guard.add_argument("--workflow", default="")
49
+ guard.add_argument("--trace-id")
50
+ guard.add_argument("--risk", default="")
51
+ guard.add_argument("--metadata", default="")
52
+
53
+ result = sub.add_parser("result", help="Record execution result or error")
54
+ result.add_argument("--guard-id", required=True)
55
+ result.add_argument("--result", default="")
56
+ result.add_argument("--error", default="")
57
+ result.add_argument("--latency-ms", type=int, default=0)
58
+
59
+ status = sub.add_parser("status", help="Check a guard decision")
60
+ status.add_argument("--guard-id", required=True)
61
+
62
+ trace = sub.add_parser("trace", help="Fetch an immutable trace")
63
+ trace.add_argument("--trace-id", required=True)
64
+
65
+ export = sub.add_parser("export", help="Export a signed replay bundle")
66
+ export.add_argument("--trace-id", required=True)
67
+ export.add_argument("--out", help="Write bundle to a file")
68
+
69
+ replay = sub.add_parser("replay", help="Replay a saved bundle offline")
70
+ replay.add_argument("--file", required=True)
71
+ replay.add_argument("--public-key", default="")
72
+
73
+ public_key = sub.add_parser("public-key", help="Fetch the current signing public key")
74
+ public_key.set_defaults(command="public-key")
75
+
76
+ sub.add_parser("statement", help="Show current billing statement")
77
+ return parser
78
+
79
+
80
+ def main(argv: list[str] | None = None) -> int:
81
+ args = build_parser().parse_args(argv)
82
+ client = TraceLockClient(api_key=args.api_key, base_url=args.base_url)
83
+ try:
84
+ if args.command == "register":
85
+ output = client.register(args.email, args.client_id)
86
+ elif args.command == "verify":
87
+ output = client.verify_email(args.client_id, args.code)
88
+ if output.get("api_key"):
89
+ path = os.path.join(os.getcwd(), ".tlock_key")
90
+ with open(path, "w", encoding="utf-8") as handle:
91
+ handle.write(output["api_key"] + "\n")
92
+ os.chmod(path, 0o600)
93
+ output = {**output, "api_key": "<saved to .tlock_key>", "key_file": path}
94
+ elif args.command == "whoami":
95
+ output = client.me()
96
+ elif args.command == "guard":
97
+ output = client.guard(
98
+ args.tool,
99
+ _json(args.args, {}),
100
+ idempotency_fields=_fields(args.fields),
101
+ window_seconds=args.window,
102
+ workflow_id=args.workflow,
103
+ trace_id=args.trace_id,
104
+ risk=_json(args.risk, {}),
105
+ metadata=_json(args.metadata, {}),
106
+ )
107
+ elif args.command == "result":
108
+ output = client.result(
109
+ args.guard_id,
110
+ result=_json(args.result, None),
111
+ error=args.error,
112
+ latency_ms=args.latency_ms,
113
+ )
114
+ elif args.command == "status":
115
+ output = client.guard_status(args.guard_id)
116
+ elif args.command == "trace":
117
+ output = client.trace(args.trace_id)
118
+ elif args.command == "export":
119
+ output = client.export(args.trace_id)
120
+ if args.out:
121
+ with open(args.out, "w", encoding="utf-8") as handle:
122
+ json.dump(output, handle, indent=2, sort_keys=True)
123
+ output = {"saved": args.out, "trace_id": args.trace_id}
124
+ elif args.command == "replay":
125
+ output = replay_bundle(load_bundle(args.file), args.public_key)
126
+ elif args.command == "public-key":
127
+ output = client.public_key()
128
+ elif args.command == "statement":
129
+ output = client.statement()
130
+ else: # pragma: no cover
131
+ parser = build_parser()
132
+ parser.print_help()
133
+ return 2
134
+ print(json.dumps(output, indent=2, sort_keys=True, default=str))
135
+ return 0
136
+ except TraceLockError as exc:
137
+ print(json.dumps({"error": exc.detail, "status": exc.status_code}, indent=2), file=sys.stderr)
138
+ return 1
139
+ except (OSError, ValueError) as exc:
140
+ print(json.dumps({"error": str(exc)}, indent=2), file=sys.stderr)
141
+ return 1
142
+
143
+
144
+ if __name__ == "__main__":
145
+ raise SystemExit(main())
@@ -0,0 +1,140 @@
1
+ """Small synchronous HTTP client for the TraceLock API."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import os
6
+ from typing import Any
7
+
8
+ import httpx
9
+
10
+ DEFAULT_BASE_URL = "https://tracelock-pied.vercel.app"
11
+
12
+
13
+ class TraceLockError(RuntimeError):
14
+ def __init__(self, status_code: int, detail: Any):
15
+ self.status_code = status_code
16
+ self.detail = detail
17
+ super().__init__(f"TraceLock error {status_code}: {detail}")
18
+
19
+
20
+ class TraceLockClient:
21
+ def __init__(
22
+ self,
23
+ api_key: str | None = None,
24
+ base_url: str | None = None,
25
+ timeout: float = 30.0,
26
+ ) -> None:
27
+ self.api_key = api_key or os.environ.get("TRACELOCK_API_KEY", "")
28
+ self.base_url = (base_url or os.environ.get("TRACELOCK_BASE_URL", DEFAULT_BASE_URL)).rstrip("/")
29
+ self.timeout = timeout
30
+
31
+ def _headers(self) -> dict[str, str]:
32
+ if not self.api_key:
33
+ return {}
34
+ return {"X-TraceLock-API-Key": self.api_key}
35
+
36
+ def _request(
37
+ self,
38
+ method: str,
39
+ path: str,
40
+ *,
41
+ payload: dict[str, Any] | None = None,
42
+ params: dict[str, Any] | None = None,
43
+ authenticated: bool = True,
44
+ ) -> Any:
45
+ headers = self._headers() if authenticated else {}
46
+ with httpx.Client(base_url=self.base_url, timeout=self.timeout, headers=headers) as session:
47
+ response = session.request(method, path, json=payload, params=params)
48
+ if response.status_code >= 400:
49
+ try:
50
+ detail = response.json().get("detail", response.text)
51
+ except ValueError:
52
+ detail = response.text
53
+ raise TraceLockError(response.status_code, detail)
54
+ if not response.content:
55
+ return None
56
+ return response.json()
57
+
58
+ def register(self, email: str, client_id: str | None = None) -> dict[str, Any]:
59
+ payload: dict[str, Any] = {"email": email}
60
+ if client_id:
61
+ payload["client_id"] = client_id
62
+ return self._request("POST", "/v1/clients/register", payload=payload, authenticated=False)
63
+
64
+ def verify_email(self, client_id: str, code: str) -> dict[str, Any]:
65
+ result = self._request(
66
+ "POST",
67
+ "/v1/clients/verify-email",
68
+ payload={"client_id": client_id, "code": code},
69
+ authenticated=False,
70
+ )
71
+ if result and "api_key" in result:
72
+ self.api_key = result["api_key"]
73
+ return result
74
+
75
+ def me(self) -> dict[str, Any]:
76
+ return self._request("GET", "/v1/clients/me")
77
+
78
+ def public_key(self) -> dict[str, Any]:
79
+ return self._request("GET", "/v1/public-key", authenticated=False)
80
+
81
+ def guard(
82
+ self,
83
+ tool_name: str,
84
+ args: dict[str, Any],
85
+ *,
86
+ idempotency_fields: list[str] | None = None,
87
+ window_seconds: int = 300,
88
+ workflow_id: str = "",
89
+ trace_id: str | None = None,
90
+ risk: dict[str, Any] | None = None,
91
+ metadata: dict[str, Any] | None = None,
92
+ ) -> dict[str, Any]:
93
+ payload: dict[str, Any] = {
94
+ "tool_name": tool_name,
95
+ "args": args,
96
+ "idempotency_fields": idempotency_fields or [],
97
+ "window_seconds": window_seconds,
98
+ "workflow_id": workflow_id,
99
+ "risk": risk or {},
100
+ "metadata": metadata or {},
101
+ }
102
+ if trace_id:
103
+ payload["trace_id"] = trace_id
104
+ return self._request("POST", "/v1/tools/guard", payload=payload)
105
+
106
+ def result(
107
+ self,
108
+ guard_id: str,
109
+ *,
110
+ result: Any = None,
111
+ error: str = "",
112
+ latency_ms: int = 0,
113
+ state_transition: str = "executed",
114
+ ) -> dict[str, Any]:
115
+ return self._request(
116
+ "POST",
117
+ "/v1/tools/result",
118
+ payload={
119
+ "guard_id": guard_id,
120
+ "result": result,
121
+ "error": error,
122
+ "latency_ms": latency_ms,
123
+ "state_transition": state_transition,
124
+ },
125
+ )
126
+
127
+ def guard_status(self, guard_id: str) -> dict[str, Any]:
128
+ return self._request("GET", f"/v1/guards/{guard_id}")
129
+
130
+ def trace(self, trace_id: str) -> dict[str, Any]:
131
+ return self._request("GET", f"/v1/traces/{trace_id}")
132
+
133
+ def export(self, trace_id: str) -> dict[str, Any]:
134
+ return self._request("GET", f"/v1/traces/{trace_id}/export")
135
+
136
+ def statement(self) -> dict[str, Any]:
137
+ return self._request("GET", "/v1/billing/statement")
138
+
139
+ def dump(self, value: Any) -> str:
140
+ return json.dumps(value, indent=2, sort_keys=True)
@@ -0,0 +1,36 @@
1
+ """Offline verification helpers shared by the SDK and replay command."""
2
+ from __future__ import annotations
3
+
4
+ import base64
5
+ import json
6
+ from typing import Any
7
+
8
+ from cryptography.hazmat.primitives import serialization
9
+ from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
10
+
11
+
12
+ def b64e(data: bytes) -> str:
13
+ return base64.urlsafe_b64encode(data).decode("ascii").rstrip("=")
14
+
15
+
16
+ def b64d(value: str) -> bytes:
17
+ return base64.urlsafe_b64decode(value + "=" * (-len(value) % 4))
18
+
19
+
20
+ def canonical_bytes(payload: dict[str, Any]) -> bytes:
21
+ return json.dumps(
22
+ payload,
23
+ sort_keys=True,
24
+ separators=(",", ":"),
25
+ ensure_ascii=False,
26
+ allow_nan=False,
27
+ ).encode("utf-8")
28
+
29
+
30
+ def verify_payload(payload: dict[str, Any], signature_b64: str, key_b64: str) -> bool:
31
+ try:
32
+ key = Ed25519PublicKey.from_public_bytes(b64d(key_b64))
33
+ key.verify(b64d(signature_b64), canonical_bytes(payload))
34
+ return True
35
+ except Exception:
36
+ return False
@@ -0,0 +1,46 @@
1
+ """Offline replay of signed TraceLock bundles. No live APIs, no tokens."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from .core import verify_payload
9
+
10
+
11
+ def replay_bundle(bundle: dict[str, Any], public_key: str | None = None) -> dict[str, Any]:
12
+ """Verify and return a deterministic replay summary for a saved bundle."""
13
+ signature = bundle.get("signature", "")
14
+ payload = {key: value for key, value in bundle.items() if key != "signature"}
15
+ key = public_key or payload.get("public_key", "")
16
+ if not key:
17
+ raise ValueError("No public key supplied and bundle has no embedded key.")
18
+ if not verify_payload(payload, signature, key):
19
+ raise ValueError("Bundle signature is invalid.")
20
+
21
+ events = payload.get("events", [])
22
+ guard = payload.get("guard", {})
23
+ return {
24
+ "trace_id": payload.get("trace_id"),
25
+ "tool": guard.get("tool"),
26
+ "args": guard.get("args", {}),
27
+ "semantic_args": guard.get("semantic_args", {}),
28
+ "state": guard.get("state"),
29
+ "result": guard.get("result"),
30
+ "error": guard.get("error"),
31
+ "approval": payload.get("approval"),
32
+ "events": [
33
+ {
34
+ "sequence": event.get("sequence"),
35
+ "event_type": event.get("event_type"),
36
+ "tool": event.get("tool"),
37
+ "payload": event.get("payload", {}),
38
+ }
39
+ for event in events
40
+ ],
41
+ "verified": True,
42
+ }
43
+
44
+
45
+ def load_bundle(path: str | Path) -> dict[str, Any]:
46
+ return json.loads(Path(path).read_text(encoding="utf-8"))
@@ -0,0 +1,60 @@
1
+ """One-line guard + execution + result recording wrapper."""
2
+ from __future__ import annotations
3
+
4
+ import time
5
+ from typing import Any, Callable
6
+
7
+ from .client import TraceLockClient
8
+
9
+
10
+ def guard_call(
11
+ client: TraceLockClient,
12
+ tool_name: str,
13
+ args: dict[str, Any],
14
+ execute: Callable[[dict[str, Any]], Any],
15
+ *,
16
+ idempotency_fields: list[str] | None = None,
17
+ window_seconds: int = 300,
18
+ workflow_id: str = "",
19
+ trace_id: str | None = None,
20
+ risk: dict[str, Any] | None = None,
21
+ metadata: dict[str, Any] | None = None,
22
+ ) -> Any:
23
+ """Guard a side effect, execute it only when allowed, and record the result.
24
+
25
+ If TraceLock returns ``replay``, ``in_progress``, ``awaiting_approval`` or
26
+ ``denied``, the side effect is not executed and the guard decision is
27
+ returned instead. This keeps the caller safe by default.
28
+ """
29
+ decision = client.guard(
30
+ tool_name,
31
+ args,
32
+ idempotency_fields=idempotency_fields,
33
+ window_seconds=window_seconds,
34
+ workflow_id=workflow_id,
35
+ trace_id=trace_id,
36
+ risk=risk,
37
+ metadata=metadata,
38
+ )
39
+ verdict = decision.get("decision")
40
+ if verdict != "execute":
41
+ return decision
42
+
43
+ guard_id = decision["guard_id"]
44
+ started = time.monotonic()
45
+ try:
46
+ value = execute(args)
47
+ except Exception as exc:
48
+ client.result(
49
+ guard_id,
50
+ error=str(exc),
51
+ latency_ms=int((time.monotonic() - started) * 1000),
52
+ )
53
+ raise
54
+
55
+ client.result(
56
+ guard_id,
57
+ result=value,
58
+ latency_ms=int((time.monotonic() - started) * 1000),
59
+ )
60
+ return value
@@ -0,0 +1,73 @@
1
+ Metadata-Version: 2.4
2
+ Name: tracelock
3
+ Version: 0.1.0
4
+ Summary: Python SDK and tlock CLI for TraceLock deterministic tool-call replay
5
+ Project-URL: Homepage, https://tracelock-pied.vercel.app
6
+ Project-URL: Documentation, https://tracelock-pied.vercel.app/docs
7
+ Keywords: idempotency,ai-agents,tool-calls,replay,audit,llmops
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Topic :: Security
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: httpx<1,>=0.27
19
+ Requires-Dist: cryptography<51,>=42
20
+
21
+ # TraceLock SDK
22
+
23
+ Guard side-effecting tool calls before they happen, then replay production traces offline.
24
+
25
+ ```bash
26
+ pip install tracelock
27
+ export TRACELOCK_API_KEY="tlk_..."
28
+ ```
29
+
30
+ For a local checkout, install with `pip install ./TraceLock/sdk`.
31
+
32
+ ## One-line wrapper
33
+
34
+ ```python
35
+ from tracelock import TraceLockClient, guard_call
36
+
37
+ client = TraceLockClient()
38
+
39
+ result = guard_call(
40
+ client,
41
+ "refund_user",
42
+ {"user_id": "u_123", "amount": 50},
43
+ lambda args: stripe.Refund.create(**args),
44
+ idempotency_fields=["user_id", "amount"],
45
+ )
46
+ ```
47
+
48
+ If TraceLock returns `replay`, `in_progress`, `awaiting_approval`, or `denied`, the
49
+ side effect is not executed. If it returns `execute`, the wrapper runs the call and
50
+ records the result/latency automatically.
51
+
52
+ ## CLI
53
+
54
+ ```bash
55
+ tlock --api-key "$TRACELOCK_API_KEY" guard \
56
+ --tool refund_user \
57
+ --args '{"user_id":"u_123","amount":50,"reason":"retry"}' \
58
+ --fields user_id,amount
59
+
60
+ tlock result --guard-id g_... --result '{"refund_id":"rf_1"}'
61
+ tlock export --trace-id tr_... --out trace.json
62
+ tlock replay --file trace.json
63
+ tlock statement
64
+ ```
65
+
66
+ `replay` is fully offline: it verifies the Ed25519 signature using the public key
67
+ embedded in the bundle (or `--public-key`) and never contacts a live API.
68
+
69
+ ## Notes
70
+
71
+ - API key env: `TRACELOCK_API_KEY`
72
+ - Base URL env: `TRACELOCK_BASE_URL` (default `https://tracelock-pied.vercel.app`)
73
+ - `tlock verify` stores the API key in `.tlock_key`; add that file to `.gitignore`.
@@ -0,0 +1,14 @@
1
+ README.md
2
+ pyproject.toml
3
+ tracelock/__init__.py
4
+ tracelock/cli.py
5
+ tracelock/client.py
6
+ tracelock/core.py
7
+ tracelock/replay.py
8
+ tracelock/wrap.py
9
+ tracelock.egg-info/PKG-INFO
10
+ tracelock.egg-info/SOURCES.txt
11
+ tracelock.egg-info/dependency_links.txt
12
+ tracelock.egg-info/entry_points.txt
13
+ tracelock.egg-info/requires.txt
14
+ tracelock.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ tlock = tracelock.cli:main
@@ -0,0 +1,2 @@
1
+ httpx<1,>=0.27
2
+ cryptography<51,>=42
@@ -0,0 +1 @@
1
+ tracelock