codex-local-sdk-python 0.1.0__py3-none-any.whl

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.
Files changed (46) hide show
  1. codex_local_sdk/__init__.py +34 -0
  2. codex_local_sdk/client.py +1776 -0
  3. codex_local_sdk/exceptions.py +19 -0
  4. codex_local_sdk/models.py +77 -0
  5. codex_local_sdk/session_store.py +447 -0
  6. codex_local_sdk/telemetry.py +24 -0
  7. codex_local_sdk_python-0.1.0.dist-info/METADATA +36 -0
  8. codex_local_sdk_python-0.1.0.dist-info/RECORD +46 -0
  9. codex_local_sdk_python-0.1.0.dist-info/WHEEL +5 -0
  10. codex_local_sdk_python-0.1.0.dist-info/entry_points.txt +2 -0
  11. codex_local_sdk_python-0.1.0.dist-info/top_level.txt +2 -0
  12. codex_sdk_python/__init__.py +5 -0
  13. codex_sdk_python/cli.py +131 -0
  14. codex_sdk_python/data/docs/documentation/AGENTS.md +35 -0
  15. codex_sdk_python/data/docs/documentation/README.md +20 -0
  16. codex_sdk_python/data/docs/documentation/architecture_starter.md +51 -0
  17. codex_sdk_python/data/docs/documentation/automation_ci_cd.md +35 -0
  18. codex_sdk_python/data/docs/documentation/codex_core_docs.md +43 -0
  19. codex_sdk_python/data/docs/documentation/configuration.md +35 -0
  20. codex_sdk_python/data/docs/documentation/enterprise_governance.md +33 -0
  21. codex_sdk_python/data/docs/documentation/mcp_and_skills.md +39 -0
  22. codex_sdk_python/data/docs/documentation/model_pricing_notes.md +24 -0
  23. codex_sdk_python/data/docs/documentation/programmatic_integration.md +30 -0
  24. codex_sdk_python/data/docs/documentation/security_permissions.md +47 -0
  25. codex_sdk_python/data/docs/documentation/setup_auth.md +42 -0
  26. codex_sdk_python/data/docs/html documentation/api-reference.html +218 -0
  27. codex_sdk_python/data/docs/html documentation/assets/styles.css +265 -0
  28. codex_sdk_python/data/docs/html documentation/examples.html +203 -0
  29. codex_sdk_python/data/docs/html documentation/getting-started.html +189 -0
  30. codex_sdk_python/data/docs/html documentation/index.html +161 -0
  31. codex_sdk_python/data/docs/html documentation/live-threads.html +180 -0
  32. codex_sdk_python/data/docs/html documentation/testing-and-quality.html +110 -0
  33. codex_sdk_python/data/skills/codex-local-sdk-usage/SKILL.md +41 -0
  34. codex_sdk_python/data/skills/codex-local-sdk-usage/agents/openai.yaml +4 -0
  35. codex_sdk_python/data/skills/codex-local-sdk-usage/assets/template_async_run.py +36 -0
  36. codex_sdk_python/data/skills/codex-local-sdk-usage/assets/template_live_stream.py +28 -0
  37. codex_sdk_python/data/skills/codex-local-sdk-usage/assets/template_resume_named_session.py +35 -0
  38. codex_sdk_python/data/skills/codex-local-sdk-usage/assets/template_schema_output.py +41 -0
  39. codex_sdk_python/data/skills/codex-local-sdk-usage/assets/template_sync_run.py +24 -0
  40. codex_sdk_python/data/skills/codex-local-sdk-usage/assets/template_telemetry_and_retry.py +56 -0
  41. codex_sdk_python/data/skills/codex-local-sdk-usage/assets/template_thread_session.py +29 -0
  42. codex_sdk_python/data/skills/codex-local-sdk-usage/references/guardrails-and-failure-modes.md +55 -0
  43. codex_sdk_python/data/skills/codex-local-sdk-usage/references/sdk-api-cheatsheet.md +72 -0
  44. codex_sdk_python/data/skills/codex-local-sdk-usage/references/task-routing.md +26 -0
  45. codex_sdk_python/data/skills/codex-local-sdk-usage/scripts/preflight_check.py +132 -0
  46. codex_sdk_python/data/skills/codex-local-sdk-usage/scripts/scaffold_usage_template.py +66 -0
@@ -0,0 +1,218 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>API Reference - SpawnCodex Python SDK Docs</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com">
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
+ <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
10
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
11
+ <link href="assets/styles.css" rel="stylesheet">
12
+ </head>
13
+ <body>
14
+ <div class="layout">
15
+ <aside class="sidebar">
16
+ <span class="logo">SpawnCodex</span>
17
+ <h1 class="title">Python SDK Docs</h1>
18
+ <p class="subtitle">Local Codex non-interactive client</p>
19
+
20
+ <div class="nav-group">
21
+ <p class="nav-group-label">Overview</p>
22
+ <a class="nav-link" href="index.html">Home</a>
23
+ <a class="nav-link" href="getting-started.html">Getting Started</a>
24
+ <a class="nav-link active" href="api-reference.html">API Reference</a>
25
+ <a class="nav-link" href="live-threads.html">Live Runs & Threads</a>
26
+ <a class="nav-link" href="examples.html">Examples Cookbook</a>
27
+ <a class="nav-link" href="testing-and-quality.html">Testing & Quality</a>
28
+ </div>
29
+
30
+ <div class="nav-group">
31
+ <p class="nav-group-label">On This Page</p>
32
+ <a class="nav-link" href="#exports">Exports</a>
33
+ <a class="nav-link" href="#core-models">Core Models</a>
34
+ <a class="nav-link" href="#session-stores">Session Stores</a>
35
+ <a class="nav-link" href="#core-client">CodexLocalClient</a>
36
+ <a class="nav-link" href="#telemetry">Telemetry</a>
37
+ <a class="nav-link" href="#live-run">Live Handles</a>
38
+ <a class="nav-link" href="#thread-session">Thread Session</a>
39
+ <a class="nav-link" href="#errors">Errors</a>
40
+ </div>
41
+ </aside>
42
+
43
+ <main class="main">
44
+ <section class="hero">
45
+ <span class="badge">Reference</span>
46
+ <h1>Python SDK API Reference</h1>
47
+ <p>Canonical interface for sync + async execution, retry/timeout control, session metadata persistence, and telemetry hooks.</p>
48
+ </section>
49
+
50
+ <section class="section" id="exports">
51
+ <h2>Package Exports</h2>
52
+ <pre><code>from codex_local_sdk import (
53
+ AsyncCodexLiveRun,
54
+ CodexClientEvent,
55
+ CodexLiveRun,
56
+ CodexLocalClient,
57
+ CodexThreadSession,
58
+ CodexError,
59
+ CodexExecFailedError,
60
+ CodexNotInstalledError,
61
+ CodexEvent,
62
+ CodexExecRequest,
63
+ CodexExecResult,
64
+ RetryPolicy,
65
+ SandboxMode,
66
+ SessionStore,
67
+ InMemorySessionStore,
68
+ JsonFileSessionStore,
69
+ SessionRecord,
70
+ SessionTurnRecord,
71
+ )</code></pre>
72
+ </section>
73
+
74
+ <section class="section" id="core-models">
75
+ <h2>Core Models</h2>
76
+
77
+ <h3>CodexExecRequest</h3>
78
+ <p>Describes <code>codex exec</code> CLI options (prompt, sandbox, model/profile, schema/output flags, images, extra args).</p>
79
+
80
+ <h3>RetryPolicy</h3>
81
+ <div class="table-wrap">
82
+ <table>
83
+ <thead>
84
+ <tr><th>Field</th><th>Type</th><th>Description</th></tr>
85
+ </thead>
86
+ <tbody>
87
+ <tr><td><code>max_attempts</code></td><td>int</td><td>Total attempts (initial + retries).</td></tr>
88
+ <tr><td><code>initial_backoff_seconds</code></td><td>float</td><td>Base retry delay.</td></tr>
89
+ <tr><td><code>backoff_multiplier</code></td><td>float</td><td>Exponential growth factor.</td></tr>
90
+ <tr><td><code>max_backoff_seconds</code></td><td>float</td><td>Delay cap.</td></tr>
91
+ <tr><td><code>retry_on_exit_codes</code></td><td>tuple[int, ...] | None</td><td><code>None</code> retries any non-zero exit code.</td></tr>
92
+ <tr><td><code>jitter_ratio</code></td><td>float</td><td>Random jitter fraction applied to backoff delay.</td></tr>
93
+ <tr><td><code>max_total_retry_seconds</code></td><td>float | None</td><td>Caps total time spent retrying.</td></tr>
94
+ <tr><td><code>retry_on_timeouts</code></td><td>bool</td><td>Controls retry behavior for timeout failures.</td></tr>
95
+ </tbody>
96
+ </table>
97
+ </div>
98
+
99
+ <h3>CodexExecResult</h3>
100
+ <p>Command result with return code, stdout/stderr, final message, events, thread id, turn status, usage, and duration.</p>
101
+ </section>
102
+
103
+ <section class="section" id="session-stores">
104
+ <h2>Session Stores</h2>
105
+ <p>Session stores map logical names to Codex session IDs and persist metadata/history records.</p>
106
+
107
+ <h3>SessionStore Interface</h3>
108
+ <ul>
109
+ <li><code>get(name)</code>, <code>set(name, session_id)</code>, <code>delete(name)</code>, <code>all()</code></li>
110
+ <li><code>get_record(name)</code>, <code>set_record(name, record)</code>, <code>list_records()</code></li>
111
+ </ul>
112
+
113
+ <h3>SessionRecord / SessionTurnRecord</h3>
114
+ <ul>
115
+ <li><code>SessionRecord</code>: session id/name, counters, timestamps, and bounded turn history.</li>
116
+ <li><code>SessionTurnRecord</code>: per-turn metadata (operation, prompt/message preview, return code, status, duration).</li>
117
+ </ul>
118
+
119
+ <h3>JsonFileSessionStore</h3>
120
+ <ul>
121
+ <li>Schema v2 payload with automatic migration from legacy <code>{name: session_id}</code> files.</li>
122
+ <li>Thread-safe + cross-process safe file locking.</li>
123
+ <li>Atomic writes via temp file + <code>os.replace</code>.</li>
124
+ </ul>
125
+ </section>
126
+
127
+ <section class="section" id="core-client">
128
+ <h2>CodexLocalClient</h2>
129
+
130
+ <h3>Constructor</h3>
131
+ <pre><code>CodexLocalClient(
132
+ codex_bin: str = "codex",
133
+ default_cwd: str | None = None,
134
+ default_env: dict[str, str] | None = None,
135
+ raise_on_error: bool = True,
136
+ retry_policy: RetryPolicy | None = None,
137
+ session_store: SessionStore | None = None,
138
+ event_hook: Callable[[CodexClientEvent], None] | None = None,
139
+ )</code></pre>
140
+
141
+ <h3>Execution Methods</h3>
142
+ <div class="table-wrap">
143
+ <table>
144
+ <thead>
145
+ <tr><th>Method</th><th>Returns</th><th>Notes</th></tr>
146
+ </thead>
147
+ <tbody>
148
+ <tr><td><code>run(..., timeout_seconds=None)</code></td><td>CodexExecResult</td><td>Sync run with retry policy.</td></tr>
149
+ <tr><td><code>run_async(..., timeout_seconds=None)</code></td><td>awaitable[CodexExecResult]</td><td>Async wrapper around sync behavior.</td></tr>
150
+ <tr><td><code>run_prompt(..., api_key=None, timeout_seconds=None)</code></td><td>CodexExecResult</td><td>Prompt convenience wrapper.</td></tr>
151
+ <tr><td><code>run_prompt_async(...)</code></td><td>awaitable[CodexExecResult]</td><td>Async prompt wrapper.</td></tr>
152
+ <tr><td><code>run_with_schema(..., api_key=None, timeout_seconds=None)</code></td><td>CodexExecResult</td><td>Schema-constrained output.</td></tr>
153
+ <tr><td><code>run_with_schema_async(...)</code></td><td>awaitable[CodexExecResult]</td><td>Async schema wrapper.</td></tr>
154
+ <tr><td><code>start_thread(..., session_name=None, timeout_seconds=None)</code></td><td>tuple[CodexThreadSession, CodexExecResult]</td><td>Starts JSON thread and optionally records named session metadata.</td></tr>
155
+ <tr><td><code>start_thread_async(...)</code></td><td>awaitable[tuple[CodexThreadSession, CodexExecResult]]</td><td>Async thread start.</td></tr>
156
+ <tr><td><code>resume(..., session_name=None, timeout_seconds=None)</code></td><td>CodexExecResult</td><td>Sync continuation.</td></tr>
157
+ <tr><td><code>resume_async(...)</code></td><td>awaitable[CodexExecResult]</td><td>Async continuation.</td></tr>
158
+ <tr><td><code>run_live(...)</code> / <code>resume_live(...)</code></td><td>CodexLiveRun</td><td>Sync live streaming with startup retry support.</td></tr>
159
+ <tr><td><code>run_live_async(...)</code> / <code>resume_live_async(...)</code></td><td>awaitable[AsyncCodexLiveRun]</td><td>Async live streaming with startup retry support.</td></tr>
160
+ </tbody>
161
+ </table>
162
+ </div>
163
+
164
+ <h3>Session APIs</h3>
165
+ <ul>
166
+ <li><code>save_session</code>, <code>get_session_id</code>, <code>delete_session</code>, <code>list_sessions</code></li>
167
+ <li><code>get_session_record</code>, <code>list_session_records</code>, <code>open_session</code></li>
168
+ </ul>
169
+ </section>
170
+
171
+ <section class="section" id="telemetry">
172
+ <h2>Telemetry</h2>
173
+ <p>Pass <code>event_hook</code> to receive <code>CodexClientEvent</code> records.</p>
174
+ <pre><code>def on_event(event: CodexClientEvent) -> None:
175
+ print(event.type, event.operation, event.attempt, event.return_code)
176
+
177
+ client = CodexLocalClient(event_hook=on_event)</code></pre>
178
+ <p>Event types include:</p>
179
+ <ul>
180
+ <li><code>attempt.started</code>, <code>attempt.failed</code>, <code>attempt.succeeded</code>, <code>retry.scheduled</code></li>
181
+ <li><code>live.started</code>, <code>live.startup_failed</code>, <code>live.startup_retried</code>, <code>live.event</code></li>
182
+ <li><code>session.updated</code></li>
183
+ </ul>
184
+ </section>
185
+
186
+ <section class="section" id="live-run">
187
+ <h2>Live Handles</h2>
188
+ <ul>
189
+ <li><code>CodexLiveRun</code>: <code>iter_events()</code>, <code>wait(timeout=None)</code>, <code>result()</code>, <code>terminate()</code>, <code>kill()</code>.</li>
190
+ <li><code>AsyncCodexLiveRun</code>: async equivalents <code>iter_events()</code>, <code>wait()</code>, and <code>result()</code>.</li>
191
+ </ul>
192
+ </section>
193
+
194
+ <section class="section" id="thread-session">
195
+ <h2>CodexThreadSession</h2>
196
+ <ul>
197
+ <li><code>continue_prompt(..., timeout_seconds=None)</code></li>
198
+ <li><code>continue_prompt_async(..., timeout_seconds=None)</code></li>
199
+ <li><code>continue_live(...)</code></li>
200
+ <li><code>continue_live_async(...)</code></li>
201
+ <li><code>is_last_turn_complete</code> helper property</li>
202
+ </ul>
203
+ </section>
204
+
205
+ <section class="section" id="errors">
206
+ <h2>Errors</h2>
207
+ <ul>
208
+ <li><code>CodexError</code> (base)</li>
209
+ <li><code>CodexNotInstalledError</code> (missing CLI)</li>
210
+ <li><code>CodexExecFailedError</code> (non-zero with <code>raise_on_error=True</code>)</li>
211
+ </ul>
212
+ </section>
213
+
214
+ <footer class="footer">Reference reflects current implementation in <code>codex_local_sdk/</code>.</footer>
215
+ </main>
216
+ </div>
217
+ </body>
218
+ </html>
@@ -0,0 +1,265 @@
1
+ :root {
2
+ --bg: #0b0d10;
3
+ --bg-soft: #12161c;
4
+ --panel: #151a21;
5
+ --line: #2b3340;
6
+ --text: #e7ecf3;
7
+ --muted: #9aa6b8;
8
+ --accent: #10a37f;
9
+ --code-bg: #0f141b;
10
+ }
11
+
12
+ * {
13
+ box-sizing: border-box;
14
+ }
15
+
16
+ html,
17
+ body {
18
+ margin: 0;
19
+ padding: 0;
20
+ background: radial-gradient(circle at top right, #172130 0%, var(--bg) 40%);
21
+ color: var(--text);
22
+ font-family: "IBM Plex Sans", "Segoe UI", Roboto, Arial, sans-serif;
23
+ min-height: 100%;
24
+ }
25
+
26
+ a {
27
+ color: #7cc9ff;
28
+ text-decoration: none;
29
+ }
30
+
31
+ a:hover {
32
+ text-decoration: underline;
33
+ }
34
+
35
+ .layout {
36
+ display: grid;
37
+ grid-template-columns: 280px minmax(0, 1fr);
38
+ min-height: 100vh;
39
+ }
40
+
41
+ .sidebar {
42
+ border-right: 1px solid var(--line);
43
+ background: rgba(7, 10, 14, 0.92);
44
+ padding: 24px 18px;
45
+ position: sticky;
46
+ top: 0;
47
+ max-height: 100vh;
48
+ overflow-y: auto;
49
+ }
50
+
51
+ .logo {
52
+ display: block;
53
+ font-size: 0.76rem;
54
+ font-weight: 700;
55
+ letter-spacing: 0.08em;
56
+ text-transform: uppercase;
57
+ color: var(--muted);
58
+ margin-bottom: 16px;
59
+ }
60
+
61
+ .title {
62
+ font-size: 1.02rem;
63
+ font-weight: 700;
64
+ margin: 0 0 4px;
65
+ }
66
+
67
+ .subtitle {
68
+ font-size: 0.86rem;
69
+ color: var(--muted);
70
+ margin: 0 0 20px;
71
+ }
72
+
73
+ .nav-group {
74
+ margin-bottom: 16px;
75
+ }
76
+
77
+ .nav-group-label {
78
+ font-size: 0.74rem;
79
+ text-transform: uppercase;
80
+ letter-spacing: 0.08em;
81
+ color: var(--muted);
82
+ margin: 0 0 8px;
83
+ }
84
+
85
+ .nav-link {
86
+ display: block;
87
+ padding: 8px 10px;
88
+ border-radius: 8px;
89
+ color: var(--text);
90
+ font-size: 0.9rem;
91
+ line-height: 1.25;
92
+ }
93
+
94
+ .nav-link.active {
95
+ background: linear-gradient(90deg, rgba(16, 163, 127, 0.22), rgba(16, 163, 127, 0.08));
96
+ border: 1px solid rgba(16, 163, 127, 0.34);
97
+ }
98
+
99
+ .main {
100
+ padding: 30px 38px 56px;
101
+ }
102
+
103
+ .hero {
104
+ background: linear-gradient(130deg, rgba(16, 163, 127, 0.16), rgba(26, 32, 43, 0.9));
105
+ border: 1px solid rgba(16, 163, 127, 0.28);
106
+ border-radius: 14px;
107
+ padding: 24px;
108
+ margin-bottom: 24px;
109
+ }
110
+
111
+ .hero h1 {
112
+ margin: 0 0 10px;
113
+ font-size: clamp(1.6rem, 2.4vw, 2.2rem);
114
+ }
115
+
116
+ .hero p {
117
+ margin: 0;
118
+ color: var(--muted);
119
+ max-width: 70ch;
120
+ }
121
+
122
+ .card-grid {
123
+ display: grid;
124
+ gap: 14px;
125
+ grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
126
+ margin-bottom: 24px;
127
+ }
128
+
129
+ .card {
130
+ border: 1px solid var(--line);
131
+ border-radius: 12px;
132
+ background: var(--panel);
133
+ padding: 14px;
134
+ }
135
+
136
+ .card h3 {
137
+ margin: 0 0 6px;
138
+ font-size: 1rem;
139
+ }
140
+
141
+ .card p {
142
+ margin: 0;
143
+ color: var(--muted);
144
+ font-size: 0.92rem;
145
+ }
146
+
147
+ .section {
148
+ margin: 28px 0;
149
+ }
150
+
151
+ .section h2 {
152
+ margin: 0 0 10px;
153
+ font-size: 1.45rem;
154
+ }
155
+
156
+ .section h3 {
157
+ margin: 20px 0 10px;
158
+ font-size: 1.1rem;
159
+ }
160
+
161
+ .section p,
162
+ .section li {
163
+ color: var(--text);
164
+ line-height: 1.6;
165
+ }
166
+
167
+ .section ul {
168
+ margin: 0;
169
+ padding-left: 18px;
170
+ }
171
+
172
+ .muted {
173
+ color: var(--muted);
174
+ }
175
+
176
+ .badge {
177
+ display: inline-block;
178
+ padding: 3px 8px;
179
+ border-radius: 99px;
180
+ border: 1px solid rgba(16, 163, 127, 0.45);
181
+ color: #b7f1e3;
182
+ background: rgba(16, 163, 127, 0.12);
183
+ font-size: 0.75rem;
184
+ letter-spacing: 0.02em;
185
+ }
186
+
187
+ pre {
188
+ margin: 10px 0 14px;
189
+ background: var(--code-bg);
190
+ border: 1px solid var(--line);
191
+ border-radius: 12px;
192
+ padding: 14px;
193
+ overflow: auto;
194
+ }
195
+
196
+ code,
197
+ pre {
198
+ font-family: "IBM Plex Mono", "Cascadia Code", Consolas, monospace;
199
+ font-size: 0.85rem;
200
+ }
201
+
202
+ .table-wrap {
203
+ overflow: auto;
204
+ border: 1px solid var(--line);
205
+ border-radius: 10px;
206
+ }
207
+
208
+ table {
209
+ width: 100%;
210
+ border-collapse: collapse;
211
+ min-width: 720px;
212
+ }
213
+
214
+ thead {
215
+ background: #11161e;
216
+ }
217
+
218
+ th,
219
+ td {
220
+ text-align: left;
221
+ padding: 11px;
222
+ border-bottom: 1px solid var(--line);
223
+ vertical-align: top;
224
+ }
225
+
226
+ th {
227
+ color: #d8e2ef;
228
+ font-size: 0.83rem;
229
+ letter-spacing: 0.02em;
230
+ }
231
+
232
+ td {
233
+ font-size: 0.88rem;
234
+ }
235
+
236
+ .callout {
237
+ border-left: 4px solid var(--accent);
238
+ background: rgba(16, 163, 127, 0.1);
239
+ border-radius: 8px;
240
+ padding: 12px 12px 12px 14px;
241
+ margin: 14px 0;
242
+ }
243
+
244
+ .footer {
245
+ margin-top: 42px;
246
+ color: var(--muted);
247
+ font-size: 0.83rem;
248
+ }
249
+
250
+ @media (max-width: 900px) {
251
+ .layout {
252
+ grid-template-columns: 1fr;
253
+ }
254
+
255
+ .sidebar {
256
+ position: relative;
257
+ max-height: none;
258
+ border-right: 0;
259
+ border-bottom: 1px solid var(--line);
260
+ }
261
+
262
+ .main {
263
+ padding: 22px 18px 34px;
264
+ }
265
+ }
@@ -0,0 +1,203 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Examples Cookbook - SpawnCodex Python SDK Docs</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com">
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
+ <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
10
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
11
+ <link href="assets/styles.css" rel="stylesheet">
12
+ </head>
13
+ <body>
14
+ <div class="layout">
15
+ <aside class="sidebar">
16
+ <span class="logo">SpawnCodex</span>
17
+ <h1 class="title">Python SDK Docs</h1>
18
+ <p class="subtitle">Local Codex non-interactive client</p>
19
+
20
+ <div class="nav-group">
21
+ <p class="nav-group-label">Overview</p>
22
+ <a class="nav-link" href="index.html">Home</a>
23
+ <a class="nav-link" href="getting-started.html">Getting Started</a>
24
+ <a class="nav-link" href="api-reference.html">API Reference</a>
25
+ <a class="nav-link" href="live-threads.html">Live Runs & Threads</a>
26
+ <a class="nav-link active" href="examples.html">Examples Cookbook</a>
27
+ <a class="nav-link" href="testing-and-quality.html">Testing & Quality</a>
28
+ </div>
29
+
30
+ <div class="nav-group">
31
+ <p class="nav-group-label">On This Page</p>
32
+ <a class="nav-link" href="#official-examples">Repository Examples</a>
33
+ <a class="nav-link" href="#quick-recipes">Quick Recipes</a>
34
+ <a class="nav-link" href="#async-pattern">Async Pattern</a>
35
+ <a class="nav-link" href="#retry-pattern">Retry Pattern</a>
36
+ <a class="nav-link" href="#persistent-pattern">Persistent Session Pattern</a>
37
+ <a class="nav-link" href="#telemetry-pattern">Telemetry Pattern</a>
38
+ </div>
39
+ </aside>
40
+
41
+ <main class="main">
42
+ <section class="hero">
43
+ <span class="badge">Cookbook</span>
44
+ <h1>Examples and Integration Recipes</h1>
45
+ <p>
46
+ Ready-to-run snippets from <code>examples/</code> and integration patterns for sync/async, retries, and persistent sessions.
47
+ </p>
48
+ </section>
49
+
50
+ <section class="section" id="official-examples">
51
+ <h2>Examples in This Repository</h2>
52
+ <div class="table-wrap">
53
+ <table>
54
+ <thead>
55
+ <tr><th>File</th><th>Main Method</th><th>Purpose</th></tr>
56
+ </thead>
57
+ <tbody>
58
+ <tr><td><code>examples/run_simple.py</code></td><td><code>client.run()</code></td><td>Basic prompt execution and final message output.</td></tr>
59
+ <tr><td><code>examples/run_json_events.py</code></td><td><code>json_output=True</code></td><td>Collect events, thread id, turn status, usage.</td></tr>
60
+ <tr><td><code>examples/run_live_stream.py</code></td><td><code>client.run_live()</code></td><td>Stream JSON events from a running sync process.</td></tr>
61
+ <tr><td><code>examples/run_thread_session.py</code></td><td><code>start_thread()</code></td><td>Create session and continue with follow-up prompts.</td></tr>
62
+ <tr><td><code>examples/run_with_schema.py</code></td><td><code>run_with_schema()</code></td><td>Constrain output to JSON schema and parse final JSON.</td></tr>
63
+ <tr><td><code>examples/run_async.py</code></td><td><code>run_async()</code> + <code>run_live_async()</code></td><td>Async run plus async event streaming.</td></tr>
64
+ <tr><td><code>examples/run_persistent_session_store.py</code></td><td><code>JsonFileSessionStore</code></td><td>Persist named sessions and resume by name.</td></tr>
65
+ </tbody>
66
+ </table>
67
+ </div>
68
+ </section>
69
+
70
+ <section class="section" id="quick-recipes">
71
+ <h2>Quick Recipes</h2>
72
+
73
+ <h3>1. Plain Prompt (Minimal)</h3>
74
+ <pre><code>from codex_local_sdk import CodexLocalClient
75
+
76
+ client = CodexLocalClient()
77
+ result = client.run_prompt("Summarize this project in 5 bullets.")
78
+ print(result.final_message)</code></pre>
79
+
80
+ <h3>2. Explicit Request with Sandbox</h3>
81
+ <pre><code>from codex_local_sdk import CodexExecRequest, CodexLocalClient, SandboxMode
82
+
83
+ client = CodexLocalClient()
84
+ result = client.run(
85
+ CodexExecRequest(
86
+ prompt="Find architecture risks.",
87
+ sandbox=SandboxMode.READ_ONLY,
88
+ skip_git_repo_check=True,
89
+ ),
90
+ timeout_seconds=120,
91
+ )</code></pre>
92
+ </section>
93
+
94
+ <section class="section" id="async-pattern">
95
+ <h2>Async Pattern</h2>
96
+ <pre><code>import asyncio
97
+ from codex_local_sdk import CodexExecRequest, CodexLocalClient
98
+
99
+
100
+ async def main() -> None:
101
+ client = CodexLocalClient()
102
+
103
+ result = await client.run_async(CodexExecRequest(prompt="Analyze repo"), timeout_seconds=120)
104
+ print(result.final_message)
105
+
106
+ live = await client.run_live_async(CodexExecRequest(prompt="Stream repo analysis", json_output=True))
107
+ async for event in live.iter_events():
108
+ print(event.type)
109
+ final = await live.wait()
110
+ print(final.turn_status)
111
+
112
+
113
+ asyncio.run(main())</code></pre>
114
+ </section>
115
+
116
+ <section class="section" id="retry-pattern">
117
+ <h2>Retry/Backoff Pattern</h2>
118
+ <pre><code>from codex_local_sdk import CodexExecRequest, CodexLocalClient, RetryPolicy
119
+
120
+ client = CodexLocalClient(
121
+ retry_policy=RetryPolicy(
122
+ max_attempts=3,
123
+ initial_backoff_seconds=0.5,
124
+ backoff_multiplier=2.0,
125
+ max_backoff_seconds=4.0,
126
+ retry_on_exit_codes=(7, 9),
127
+ jitter_ratio=0.2,
128
+ max_total_retry_seconds=15.0,
129
+ retry_on_timeouts=True,
130
+ )
131
+ )
132
+
133
+ result = client.run(CodexExecRequest(prompt="Run resiliently"), timeout_seconds=30)
134
+ print(result.return_code, result.ok)</code></pre>
135
+ </section>
136
+
137
+ <section class="section" id="persistent-pattern">
138
+ <h2>Persistent Session Pattern</h2>
139
+ <pre><code>from codex_local_sdk import CodexLocalClient, JsonFileSessionStore, SandboxMode
140
+
141
+ client = CodexLocalClient(session_store=JsonFileSessionStore(".codex_sessions.json"))
142
+
143
+ session, first = client.start_thread(
144
+ prompt="Create migration plan",
145
+ sandbox=SandboxMode.READ_ONLY,
146
+ session_name="migration-plan",
147
+ )
148
+ print(session.session_id, first.turn_status)
149
+
150
+ second = client.resume(
151
+ prompt="Continue with phase 1 tasks",
152
+ session_name="migration-plan",
153
+ last=False,
154
+ json_output=True,
155
+ timeout_seconds=120,
156
+ )
157
+ print(second.final_message)
158
+
159
+ same_session = client.open_session("migration-plan")
160
+ third = same_session.continue_prompt("Continue with test strategy", json_output=True)
161
+ print(third.turn_status)</code></pre>
162
+ </section>
163
+
164
+ <section class="section" id="telemetry-pattern">
165
+ <h2>Telemetry Hook Pattern</h2>
166
+ <pre><code>from codex_local_sdk import CodexClientEvent, CodexExecRequest, CodexLocalClient
167
+
168
+
169
+ def on_event(event: CodexClientEvent) -> None:
170
+ print(event.type, event.operation, event.attempt, event.return_code)
171
+
172
+
173
+ client = CodexLocalClient(event_hook=on_event)
174
+ client.run(CodexExecRequest(prompt="Analyze repo"), timeout_seconds=60)</code></pre>
175
+ </section>
176
+
177
+ <section class="section">
178
+ <h2>Service Integration Skeleton</h2>
179
+ <pre><code>class CodexService:
180
+ def __init__(self) -> None:
181
+ self.client = CodexLocalClient(default_cwd="/workspace/project")
182
+
183
+ def analyze_repo(self) -> str:
184
+ result = self.client.run_prompt(
185
+ "Provide architecture summary and top 5 technical risks.",
186
+ json_output=True,
187
+ )
188
+ return result.final_message or ""
189
+
190
+ async def analyze_repo_async(self) -> str:
191
+ result = await self.client.run_async(
192
+ CodexExecRequest(prompt="Provide async architecture summary", json_output=True)
193
+ )
194
+ return result.final_message or ""</code></pre>
195
+ </section>
196
+
197
+ <footer class="footer">
198
+ For method-level details, see <a href="api-reference.html">API Reference</a>.
199
+ </footer>
200
+ </main>
201
+ </div>
202
+ </body>
203
+ </html>