onecli-sdk 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.
Files changed (32) hide show
  1. onecli_sdk-0.1.0/LICENSE +21 -0
  2. onecli_sdk-0.1.0/PKG-INFO +354 -0
  3. onecli_sdk-0.1.0/README.md +320 -0
  4. onecli_sdk-0.1.0/pyproject.toml +183 -0
  5. onecli_sdk-0.1.0/pyproject.toml.orig +136 -0
  6. onecli_sdk-0.1.0/src/onecli/__init__.py +97 -0
  7. onecli_sdk-0.1.0/src/onecli/_agent_env.py +238 -0
  8. onecli_sdk-0.1.0/src/onecli/_async/__init__.py +1 -0
  9. onecli_sdk-0.1.0/src/onecli/_async/_client.py +431 -0
  10. onecli_sdk-0.1.0/src/onecli/_async/_connected_agent.py +184 -0
  11. onecli_sdk-0.1.0/src/onecli/_async/_http.py +330 -0
  12. onecli_sdk-0.1.0/src/onecli/_async/_io.py +118 -0
  13. onecli_sdk-0.1.0/src/onecli/_async/_resources.py +1293 -0
  14. onecli_sdk-0.1.0/src/onecli/_errors.py +106 -0
  15. onecli_sdk-0.1.0/src/onecli/_js.py +122 -0
  16. onecli_sdk-0.1.0/src/onecli/_keys.py +101 -0
  17. onecli_sdk-0.1.0/src/onecli/_lifetime.py +110 -0
  18. onecli_sdk-0.1.0/src/onecli/_retry.py +116 -0
  19. onecli_sdk-0.1.0/src/onecli/_sync/__init__.py +1 -0
  20. onecli_sdk-0.1.0/src/onecli/_sync/_client.py +426 -0
  21. onecli_sdk-0.1.0/src/onecli/_sync/_connected_agent.py +185 -0
  22. onecli_sdk-0.1.0/src/onecli/_sync/_http.py +329 -0
  23. onecli_sdk-0.1.0/src/onecli/_sync/_io.py +110 -0
  24. onecli_sdk-0.1.0/src/onecli/_sync/_resources.py +1286 -0
  25. onecli_sdk-0.1.0/src/onecli/_url.py +264 -0
  26. onecli_sdk-0.1.0/src/onecli/_version.py +19 -0
  27. onecli_sdk-0.1.0/src/onecli/_wire.py +469 -0
  28. onecli_sdk-0.1.0/src/onecli/gateway.py +454 -0
  29. onecli_sdk-0.1.0/src/onecli/py.typed +0 -0
  30. onecli_sdk-0.1.0/src/onecli/types/__init__.py +229 -0
  31. onecli_sdk-0.1.0/src/onecli/types/_base.py +42 -0
  32. onecli_sdk-0.1.0/src/onecli/types/_openapi.py +1590 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ChartDB, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,354 @@
1
+ Metadata-Version: 2.4
2
+ Name: onecli-sdk
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for OneCLI: manage vaults, items and agents, and let an agent see what it can use.
5
+ Keywords: onecli,sdk,proxy,ai-agents,secrets,vault
6
+ Author: OneCLI
7
+ Author-email: OneCLI <hello@onecli.sh>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Framework :: AnyIO
12
+ Classifier: Framework :: Pydantic :: 2
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Programming Language :: Python :: 3.15
22
+ Classifier: Topic :: Security
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Dist: anyio>=4.10,<5
26
+ Requires-Dist: httpx2>=2.17.1,<3
27
+ Requires-Dist: pydantic>=2.11,<3
28
+ Requires-Python: >=3.11
29
+ Project-URL: Homepage, https://onecli.sh
30
+ Project-URL: Repository, https://github.com/onecli/python-sdk
31
+ Project-URL: Issues, https://github.com/onecli/python-sdk/issues
32
+ Project-URL: Changelog, https://github.com/onecli/python-sdk/blob/main/CHANGELOG.md
33
+ Description-Content-Type: text/markdown
34
+
35
+ <h1 align="center">
36
+ <code>onecli-sdk</code>
37
+ </h1>
38
+
39
+ <p align="center">
40
+ Official Python SDK for <a href="https://onecli.sh">OneCLI</a>. Keep credentials in vaults, connect agents to them, and let agents call APIs through the OneCLI gateway without ever seeing a secret.
41
+ </p>
42
+
43
+ <p align="center">
44
+ <a href="https://onecli.sh/docs">Documentation</a> &nbsp;|&nbsp;
45
+ <a href="https://onecli.sh">Website</a> &nbsp;|&nbsp;
46
+ <a href="https://github.com/onecli/python-sdk">GitHub</a>
47
+ </p>
48
+
49
+ <p align="center">
50
+ <a href="https://pypi.org/project/onecli-sdk/">
51
+ <img src="https://img.shields.io/pypi/v/onecli-sdk.svg" alt="PyPI version" />
52
+ </a>
53
+ <a href="https://github.com/onecli/python-sdk/blob/main/LICENSE">
54
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License" />
55
+ </a>
56
+ <a href="https://pypi.org/project/onecli-sdk/">
57
+ <img src="https://img.shields.io/pypi/pyversions/onecli-sdk.svg" alt="Python versions" />
58
+ </a>
59
+ </p>
60
+
61
+ ---
62
+
63
+ ## Installation
64
+
65
+ ```bash
66
+ pip install onecli-sdk
67
+ ```
68
+
69
+ You install `onecli-sdk` and import `onecli` (`from onecli import OneCLI`). Python 3.11 or later. It needs `httpx2`, `anyio` and `pydantic` 2. Every call is there twice: `OneCLI` blocks, `AsyncOneCLI` is the same with `await`, on asyncio or trio. This is the Python twin of the Node SDK, [`@onecli-sh/sdk`](https://github.com/onecli/node-sdk) 4.1: the same calls, checks, retries and errors, with Python names.
70
+
71
+ ## Two parts, one package
72
+
73
+ The SDK has an **owner part** and an **agent part**. The key you hold picks the part.
74
+
75
+ | Part | Made with | Key | Can |
76
+ | --- | --- | --- | --- |
77
+ | Owner | `OneCLI(key=...)` | a managing key (`oc_key_...`) | manage vaults, items, agents and approvals |
78
+ | Agent | `OneCLI.agent()` | the agent's credential (`oc_agent_...`) | see its own vault's items, check a call, ask for an item |
79
+
80
+ A key of the wrong kind raises at once, before any network call, and the message names the right part. The server checks every call anyway: an agent credential never reaches an owner call.
81
+
82
+ ## Owner part
83
+
84
+ ```python
85
+ import os
86
+
87
+ from onecli import OneCLI
88
+
89
+ with OneCLI(key=os.environ["ONECLI_API_KEY"]) as onecli:
90
+ vault = onecli.vaults.create(name="ci")
91
+
92
+ onecli.items.create(
93
+ vault.id,
94
+ kind="api_key",
95
+ name="Stripe test key",
96
+ value=os.environ["STRIPE_TEST_KEY"],
97
+ host_pattern="api.stripe.com",
98
+ injection_config={"header_name": "Authorization", "value_format": "Bearer {value}"},
99
+ )
100
+ ```
101
+
102
+ No answer ever carries an item's value. Answers are pydantic models with Python names (`vault.created_at`). `model_dump(by_alias=True)` gives the API's own names, and a field this version does not know yet is kept in `model_extra`. A nested input, such as `injection_config` or a rule's `targets`, takes a model from `onecli.types` or a plain dict, with Python or API names. Every owner call is in the [table below](#owner-calls).
103
+
104
+ `with` closes the client's connections at the end (or call `close()`, `aclose()` for `AsyncOneCLI`).
105
+
106
+ The same with `AsyncOneCLI`:
107
+
108
+ ```python
109
+ import asyncio
110
+
111
+ from onecli import AsyncOneCLI
112
+
113
+
114
+ async def main() -> None:
115
+ async with AsyncOneCLI() as onecli: # the key from ONECLI_API_KEY
116
+ vault = await onecli.vaults.create(name="ci")
117
+ async for item in onecli.items.iterate(vault.id):
118
+ print(item.name)
119
+
120
+
121
+ asyncio.run(main())
122
+ ```
123
+
124
+ ## An agent for a sandbox
125
+
126
+ `agents.create` answers everything a sandbox needs to call APIs through the gateway. `Sandbox` below stands for your sandbox provider's own SDK. Each one has its own names for the two options.
127
+
128
+ ```python
129
+ with onecli.agents.create(vault_name="ci", ttl_seconds=3600) as agent:
130
+ sandbox = Sandbox.create(
131
+ env=agent.env, # proxy settings, certificate paths and the agent's credential
132
+ allowed_hosts=agent.allow_hosts, # the gateway and the API, nothing else
133
+ )
134
+ sandbox.run(agent.setup_command) # once, before the first call
135
+ sandbox.run("curl https://api.stripe.com/v1/balance") # the gateway adds the key
136
+
137
+ # Leaving the block disconnects the agent.
138
+ ```
139
+
140
+ With `AsyncOneCLI`: `async with await onecli.agents.create(...) as agent:`. Without a `with` block, call `agent.disconnect()` in a `finally`.
141
+
142
+ | Member | What it is |
143
+ | --- | --- |
144
+ | `agent.env` | The environment variables for the sandbox, as a new `dict` on each read. It holds the credential: do not log it. |
145
+ | `agent.setup_command` | One shell line to run once in the sandbox. It writes the certificate files that `env` points at. It holds no secret, and running it again is safe. Where a command is a list of arguments: `["sh", "-c", agent.setup_command]`. |
146
+ | `agent.allow_hosts` | The hosts the sandbox must reach: the gateway and the API. Enough for an allow list. |
147
+ | `agent.base_url(host)` | A base URL on the gateway for one API, for a client that cannot use the proxy settings. See [below](#a-client-that-cannot-use-a-proxy). |
148
+ | `agent.disconnect()` | Disconnects the agent, and its credential stops working. Safe to call twice, and from two threads or tasks at once. An agent already gone counts as disconnected. |
149
+ | `agent.credential` | The credential itself (`oc_agent_...`). It cannot be read again later. |
150
+
151
+ Good to know:
152
+
153
+ - Give `agent.env` when the sandbox is made, so every command in it has the settings.
154
+ - Until `setup_command` has run, HTTPS calls in the sandbox fail with a certificate error.
155
+ - The sandbox needs `sh`, `curl` and the system's root certificates (the `ca-certificates` package).
156
+ - `repr(agent)` shows `'[redacted]'` for the credential and leaves `env` out. `str(agent)` is `ConnectedAgent(<id>)`. An agent, like a client, cannot be pickled.
157
+ - When disconnecting fails as the `with` block ends, that error is raised, with the block's own error as its context. When the block was cancelled or interrupted, the cancel goes on and the failure is added to it as a note.
158
+ - The certificate files go to `/tmp/onecli` in the sandbox. For another folder, pass `home="/an/absolute/path"` to `agents.create`.
159
+ - The sandbox must be able to reach the API address your client uses. `agent.env` passes it on as `ONECLI_API_HOST`.
160
+
161
+ ### What works through the gateway
162
+
163
+ Checked with the hosted gateway, in a sandbox that allows only `agent.allow_hosts`:
164
+
165
+ | Client | Works |
166
+ | --- | --- |
167
+ | `curl`, `git`, `pip`, `uv`, Python `requests`, `httpx2` | Yes |
168
+ | `wget`, Python `urllib` | No. They cannot use an HTTPS proxy. Use `agent.base_url(host)`. |
169
+
170
+ The SDK itself goes straight to the API: `agent.env` names the API in `NO_PROXY`. The Node SDK's README covers the clients of other languages.
171
+
172
+ Call `https://` addresses. The gateway refuses a plain `http://` call to a host that has an item (403 `cleartext_refused`), so a key never travels in clear text.
173
+
174
+ ### How long the agent lives
175
+
176
+ ```python
177
+ onecli.agents.create(vault_id=vault_id) # stops by itself after 1 hour
178
+ onecli.agents.create(vault_id=vault_id, ttl_seconds=4 * 3600) # 5 minutes to 90 days
179
+ onecli.agents.create(vault_id=vault_id, expires_at=run_ends) # an aware datetime, or ISO 8601
180
+ onecli.agents.create(vault_id=vault_id, no_expiry=True) # until it is disconnected
181
+ ```
182
+
183
+ Give at most one of the three. Set the lifetime above your longest run: when it ends, the sandbox's calls start to fail. With `ttl_seconds` the agent lives at least that long, and a few seconds more. A `datetime` with no timezone is refused: it could be any of 24 moments.
184
+
185
+ An agent that has ended (its lifetime ran out, or it was disconnected) fails the same way everywhere, from the next call on:
186
+
187
+ - Through the proxy, the gateway refuses the tunnel with 407. `curl` exits with code 56 (`CONNECT tunnel failed, response 407`).
188
+ - `agent.base_url(host)` and the API answer 401 `unauthenticated`.
189
+ - `onecli.agents.get(agent_id)` shows `status="expired"` for one that ran out, until it is disconnected.
190
+
191
+ Make a new agent to go on.
192
+
193
+ ### A vault by name
194
+
195
+ `vault_name` takes the vault's exact name, capital letters too. `onecli.vaults.get_by_name(name)` is the same lookup on its own. Both raise when no vault has the name, and when more than one has it: names are not unique, ids are. Give `vault_id` or `vault_name`, never both.
196
+
197
+ ### Words that describe an agent
198
+
199
+ These show in the dashboard and in the activity list. None of them decides what the agent may do: its vault does.
200
+
201
+ | Field | What it is |
202
+ | --- | --- |
203
+ | `name` | The agent's name. Left out: the agent is named after `host`, or the server picks a name. |
204
+ | `runtime` | What the agent runs on: `docker`, `linux`, `macos` or `windows`. |
205
+ | `host` | The machine's host name. |
206
+ | `provider` | Where it runs: a short label in small letters, such as `e2b`. |
207
+ | `kind` | Which agent it is: a short label in small letters, such as `claude` or `codex`. |
208
+
209
+ ### A client that cannot use a proxy
210
+
211
+ `agent.base_url("api.example.com")` gives `https://<gateway>/r/api.example.com`. Set it as the client's base URL and send the agent's credential as `Authorization: Bearer`. The gateway takes the credential off and adds the real key, as it does through the proxy. No certificate and no setup command are needed, and `agent.env` lets a call to the gateway skip the proxy.
212
+
213
+ - The client must be able to send `Authorization: Bearer`. One that can only send its key in another header, such as `x-api-key`, cannot use this.
214
+ - A host with no item in the agent's vault answers 403. The body's error is `credential_not_found`, with a `secret_url` for adding the item, and `parse_gateway_error(body)` reads it. The `X-OneCLI-Decision` header says `no_credential`.
215
+
216
+ ## Owner calls
217
+
218
+ Ids, and the one value a call is about (a key's new value, a version), come first. Every other argument is keyword-only.
219
+
220
+ | Call | Route |
221
+ | --- | --- |
222
+ | `vaults.list(q=, limit=, cursor=)`, `vaults.iterate(q=)` | `GET /v2/vaults` |
223
+ | `vaults.get(id)`, `vaults.create(name=)`, `vaults.rename(id, name=)`, `vaults.delete(id)` | `/v2/vaults/:id` |
224
+ | `vaults.get_by_name(name)` (the one vault with exactly this name) | `GET /v2/vaults?q=` |
225
+ | `vaults.connect_token.get(id)`, `.create(id)`, `.disable(id)` | `/v2/vaults/:id/connect-token` |
226
+ | `vaults.connect_tokens.list(id, limit=, cursor=)`, `.iterate(id)` (one-use tokens, never a token itself) | `GET /v2/vaults/:id/connect-tokens` |
227
+ | `vaults.connect_tokens.create(id, name=, provider=, expires_in_minutes=)` (connects one agent, shown once) | `POST /v2/vaults/:id/connect-tokens` |
228
+ | `vaults.connect_tokens.revoke(id, token_id)` | `DELETE /v2/vaults/:id/connect-tokens/:tokenId` |
229
+ | `items.list(vault_id, deleted=)`, `items.iterate(vault_id)` | `GET /v2/vaults/:id/items` |
230
+ | `items.create(vault_id, kind=, ...)` (an API key or an LLM key) | `POST /v2/vaults/:id/items` |
231
+ | `items.get(id)`, `items.update(id, ..., if_match=)`, `items.delete(id, destroy=)`, `items.restore(id)` | `/v2/items/:id` |
232
+ | `items.set_value(id, value, if_match=)` | `PUT /v2/items/:id/value` |
233
+ | `items.versions(id)`, `items.restore_version(id, version)` | `/v2/items/:id/versions` |
234
+ | `items.get_permissions(id)`, `items.set_permissions(id, item=, tools=)` | `/v2/items/:id/permissions` |
235
+ | `agents.list(vault=, q=)`, `agents.iterate()` | `GET /v2/agents` |
236
+ | `agents.create(vault_id= or vault_name=, name=, runtime=, host=, provider=, kind=, ttl_seconds= or expires_at= or no_expiry=, home=)` | `POST /v2/agents` |
237
+ | `agents.get(id)`, `agents.rename(id, name=)`, `agents.disconnect(id)` | `/v2/agents/:id` |
238
+ | `agents.create(..., held_credential=, replace=)` | `POST /v2/agents` with `OneCLI-Agent-Credential` |
239
+ | `OneCLI.connect(connect_token, name=, runtime=, expires_at=, held_credential=, replace=)` | `POST /v2/agents` with a vault's connect token |
240
+ | `approvals.list(vault=)`, `approvals.decide(id, vault=, decision=)` (a key needs the `approve` permission) | `/v2/approvals` |
241
+ | `keys.list()`, `keys.iterate()`, `keys.get(id)`, `keys.revoke(id)` (a key cannot make a key) | `/v2/keys` |
242
+ | `org_rules.list()`, `.get(id)`, `.create(name=, action=, ...)`, `.update(id, ...)`, `.delete(id)` | `/v2/org/rules` |
243
+ | `activity.list(vault=, agent=, result=, from_=, to=)`, `activity.iterate()` | `GET /v2/activity` |
244
+ | `activity.usage(days=, vault=, agent=)` | `GET /v2/usage` |
245
+ | `health()` | `GET /v2/health` |
246
+
247
+ `list` gives one page (`page.data`, `page.next_cursor`). `iterate` walks every page: a `for` loop, or `async for` with `AsyncOneCLI`. In `org_rules.update`, `None` clears `conditions`, `description`, `rate_limit` and `rate_limit_window`. Leave one out to keep it.
248
+
249
+ ## Retries, timeouts and request ids
250
+
251
+ A call that failed is tried again only when that cannot do its work twice.
252
+
253
+ | Call | Tried again on |
254
+ | --- | --- |
255
+ | Reads, `PUT` and `DELETE` | no answer (network, timeout), 429, 502, 503, 504 |
256
+ | Creates that take an `Idempotency-Key`: `vaults.create`, `items.create`, `items.restore`, `items.restore_version`, `org_rules.create` | The same. The SDK sends the key itself, one key for every try of a call. |
257
+ | Every other call: `agents.create`, a new connect token, a rename or another `PATCH`, the agent part's `check` | 429 only. After a lost answer the call may have run, and a second run could make a second agent. |
258
+
259
+ ```python
260
+ from onecli import OneCLI, ResponseInfo
261
+
262
+
263
+ def log(info: ResponseInfo) -> None:
264
+ print(info.method, info.path, info.status, info.request_id, info.attempt)
265
+
266
+
267
+ with OneCLI(max_retries=3, on_response=log) as onecli:
268
+ onecli.vaults.list(timeout=5.0, max_retries=0) # this call: 5 seconds, one try
269
+ ```
270
+
271
+ - `max_retries` (default 2, at most 10) is how many more tries a call gets. `0` turns retries off.
272
+ - `timeout` (default 10) is the seconds one try may take. A whole call never takes longer than `timeout` times `max_retries + 1`, the waits between tries included.
273
+ - The wait before the next try is random: up to half a second, then up to 1, 2, 4 and at most 8 seconds. When the server sends `Retry-After`, the SDK waits that long if it fits in the call's time. If it does not fit, the call fails at once and the error carries `retry_after`.
274
+ - Every method of both parts takes `timeout=` and `max_retries=` (`OneCLI.connect` takes them as settings, as a client does).
275
+ - To stop an `AsyncOneCLI` call at once, cancel it the usual way: cancel its task, or run it in `asyncio.timeout()` or an anyio cancel scope. It stops during a wait too, and nothing is left open. This is the Node SDK's `signal`.
276
+ - `idempotency_key=` on a create makes two calls count as one: `vaults.create(name=..., idempotency_key=...)` with the same key gives the first answer again for 24 hours. A key is 1 to 255 letters, digits or signs, with no space.
277
+ - `on_response` is called after every answer with a `ResponseInfo`: `method`, `path`, `status`, `request_id`, `attempt` and `duration_ms`, never a header or a body. Use it to log request ids. Errors carry `request_id` too. What it raises is ignored.
278
+ - A write that is tried again after a lost answer can fail when its first try did the work: a `DELETE` with 404, a write with `if_match` with a version conflict.
279
+ - `http_client=` takes an `httpx2.Client` (an `httpx2.AsyncClient` for `AsyncOneCLI`) of your own, for a proxy or certificates. It stays yours to close.
280
+
281
+ ## Agent part
282
+
283
+ Inside a sandbox that has `ONECLI_AGENT_CREDENTIAL` and `ONECLI_API_HOST` (`agent.env` holds both, and the `onecli connect` command writes them):
284
+
285
+ ```python
286
+ from onecli import OneCLI
287
+
288
+ with OneCLI.agent() as me:
289
+ me_now = me.status() # onecli status: me_now.vault, me_now.gateway
290
+ for item in me.iterate_items(): # onecli items
291
+ print(item.name, item.hosts, item.allows, item.state)
292
+ verdict = me.check("POST", "https://api.stripe.com/v1/charges") # onecli check
293
+ # verdict.decision: allowed | blocked | needs_approval | no_item | destination_refused | unknown
294
+
295
+ ask = me.request("github") # onecli request
296
+ print(ask.message, ask.url) # a link for the agent's person: GitHub's connect step in the vault
297
+ ```
298
+
299
+ The agent part has these four calls and nothing else. It sees the items of its own vault, never a value. `AsyncOneCLI.agent()` gives the same with `await`.
300
+
301
+ ## Environment variables
302
+
303
+ | Variable | Used by |
304
+ | --- | --- |
305
+ | `ONECLI_API_KEY` | owner part, when `key` is not given |
306
+ | `ONECLI_AGENT_CREDENTIAL` | agent part, when `credential` is not given |
307
+ | `ONECLI_URL` | both (default `https://api.onecli.sh`) |
308
+ | `ONECLI_API_HOST` | agent part and `OneCLI.connect`, when `url` and `ONECLI_URL` are not given |
309
+
310
+ A setting given as an argument wins, an empty string too, as in the Node SDK. An empty environment variable counts as not set.
311
+
312
+ ## Errors
313
+
314
+ A failed call raises `OneCLIApiError` (a `OneCLIRequestError`) with `status_code`, `code` (for example `not_found`), `reason`, `details`, `request_id`, `retry_after` and `url`. A network failure or a wrong key raises `OneCLIError`. Both of the others are `OneCLIError` too, so one `except OneCLIError` catches everything the SDK raises. Messages never contain a key, a credential or a proxy address with a credential in it, and an error from a network failure does not chain the underlying error, which could show one.
315
+
316
+ ```python
317
+ from onecli import OneCLIApiError
318
+
319
+ try:
320
+ onecli.vaults.get("vault_1")
321
+ except OneCLIApiError as error:
322
+ if error.code != "not_found":
323
+ raise
324
+ ```
325
+
326
+ The gateway's own error bodies, on the agent's proxied calls, are typed in `onecli.gateway`: `parse_gateway_error(body)` narrows one, and `error["error"]` tells them apart.
327
+
328
+ Every call sends `OneCLI-Client: python-sdk/<version>`.
329
+
330
+ ## Not in the Python SDK
331
+
332
+ What the Node SDK keeps only for its 3.x users: the `apiKey` option, the `VaultDetail` type and the deprecated `/v1` call `v1.getGatewaySkill` (so no `ONECLI_PROJECT_ID`). This SDK has no earlier users.
333
+
334
+ ## Development
335
+
336
+ ```bash
337
+ uv sync # Install the dependencies (uv.lock)
338
+ uv run ruff format && uv run ruff check # Format and lint
339
+ uv run ty check && uv run pyright # Type-check, with both checkers
340
+ uv run pytest # Unit tests, with a 100% coverage gate
341
+ uv run python scripts/gen_sync.py # Write src/onecli/_sync and tests/_sync from the async code
342
+ uv run python scripts/gen_types.py # Write src/onecli/types/_openapi.py from openapi/v2.json
343
+ uv build && bash scripts/check-package.sh # Build, install the wheel in an empty virtualenv, load and type-check it
344
+ bash scripts/sync-spec.sh # Copy openapi/v2.json from ../onecli-cloud (origin/main) and regenerate
345
+ CHECK=1 bash scripts/sync-spec.sh # Exit 1 when the copy is out of date
346
+ bash scripts/sync-fixtures.sh [CHECK] # Copy (or check) node-sdk's agent-env cases from ../node-sdk
347
+ ONECLI_LIVE_URL=... ONECLI_LIVE_KEY=... uv run pytest tests/live --no-cov # Live test, deletes what it makes
348
+ ```
349
+
350
+ The async code in `src/onecli/_async` is written by hand. The sync code is made from it, so the two cannot drift: edit `_async`, then run `gen_sync.py`. `openapi/v2.json` is the server's API description, and the public types are made from it, so a change there shows up as a type error.
351
+
352
+ ## License
353
+
354
+ MIT. See [LICENSE](LICENSE).