d2b-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.
- d2b_sdk-0.1.0/.gitignore +8 -0
- d2b_sdk-0.1.0/LICENSE +21 -0
- d2b_sdk-0.1.0/PKG-INFO +103 -0
- d2b_sdk-0.1.0/README.md +78 -0
- d2b_sdk-0.1.0/d2b/__init__.py +39 -0
- d2b_sdk-0.1.0/d2b/_version.py +7 -0
- d2b_sdk-0.1.0/d2b/cli.py +1399 -0
- d2b_sdk-0.1.0/d2b/client.py +913 -0
- d2b_sdk-0.1.0/d2b/py.typed +0 -0
- d2b_sdk-0.1.0/d2b/sync.py +1033 -0
- d2b_sdk-0.1.0/d2b/sync_workspace.py +464 -0
- d2b_sdk-0.1.0/d2b/workflow_template.py +143 -0
- d2b_sdk-0.1.0/pyproject.toml +46 -0
- d2b_sdk-0.1.0/tests/test_cli_args.py +276 -0
- d2b_sdk-0.1.0/tests/test_cli_init.py +130 -0
- d2b_sdk-0.1.0/tests/test_client_paths.py +101 -0
- d2b_sdk-0.1.0/tests/test_sync.py +880 -0
- d2b_sdk-0.1.0/tests/test_sync_workspace.py +312 -0
- d2b_sdk-0.1.0/uv.lock +103 -0
d2b_sdk-0.1.0/.gitignore
ADDED
d2b_sdk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 600
|
|
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.
|
d2b_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: d2b-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: D2B Python SDK — Spreadsheets for AI Agents (typed, versioned, governed tables behind an agent-native API)
|
|
5
|
+
Project-URL: Homepage, https://d2b.dev
|
|
6
|
+
Project-URL: Documentation, https://docs.d2b.dev
|
|
7
|
+
Project-URL: Repository, https://github.com/600/d2b-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/600/d2b-sdk/issues
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,d2b,duckdb,etl,excel,llm,mcp,spreadsheet
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: httpx>=0.27
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# d2b-sdk — D2B Python SDK
|
|
27
|
+
|
|
28
|
+
Spreadsheets for AI Agents: typed, versioned, governed tables behind an
|
|
29
|
+
agent-native API.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install d2b-sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The distribution is `d2b-sdk`; the import package and the command are both
|
|
36
|
+
`d2b` (`d2b` on PyPI is an unrelated project). With `uvx`, that means
|
|
37
|
+
`uvx --from d2b-sdk d2b ...`.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from d2b import D2BClient, ConflictError
|
|
41
|
+
|
|
42
|
+
client = D2BClient(api_key="d2b_pat_...", base_url="https://d2b.dev")
|
|
43
|
+
wb = client.workbooks.create(title="monthly")["id"]
|
|
44
|
+
|
|
45
|
+
# Large files are safe: the SDK drives the async ingest and waits on the job.
|
|
46
|
+
client.sources.upload(wb, "sales.xlsx", wait=True)
|
|
47
|
+
|
|
48
|
+
for t in client.tables.list(wb):
|
|
49
|
+
print(t["name"], t["row_count"])
|
|
50
|
+
|
|
51
|
+
# Row edits are optimistically locked — a 409 is ConflictError, and the
|
|
52
|
+
# contract is to re-read and re-apply rather than retry.
|
|
53
|
+
page = client.tables.rows(wb, "sales")
|
|
54
|
+
try:
|
|
55
|
+
client.tables.upsert_rows(
|
|
56
|
+
wb, "sales",
|
|
57
|
+
rows=[{"product": "apple", "qty": 3}],
|
|
58
|
+
expected_version=page["edit_version"],
|
|
59
|
+
)
|
|
60
|
+
except ConflictError:
|
|
61
|
+
page = client.tables.rows(wb, "sales")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The client is a thin skin over the REST API — every method maps to one
|
|
65
|
+
endpoint:
|
|
66
|
+
|
|
67
|
+
- an `Idempotency-Key` on every mutating call (retry-safe);
|
|
68
|
+
- exponential-backoff retry on 429 / 5xx. **409 is never retried**;
|
|
69
|
+
- problem+json errors raised with their `suggested_fix` attached (written for
|
|
70
|
+
LLMs to read and react to);
|
|
71
|
+
- helpers for the parts that bite: `jobs.wait()`, `tables.iter_rows()`,
|
|
72
|
+
`webhooks.verify_delivery()` (signature + send-time check).
|
|
73
|
+
|
|
74
|
+
Docs: [docs.d2b.dev](https://docs.d2b.dev) ·
|
|
75
|
+
[API reference](https://docs.d2b.dev/en/api-reference) ·
|
|
76
|
+
[日本語](https://docs.d2b.dev/ja)
|
|
77
|
+
|
|
78
|
+
## CLI
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
d2b login # browser login; no raw API keys
|
|
82
|
+
d2b workbooks create --title monthly
|
|
83
|
+
d2b upload sales.xlsx --workbook WB --wait
|
|
84
|
+
d2b query 'SELECT 1' --workbook WB
|
|
85
|
+
d2b pull --workbook WB # transforms/ sheets/ charts/ + d2b.json
|
|
86
|
+
d2b pull --data customers # track base tables as data/*.csv too
|
|
87
|
+
d2b push --commit "$(git rev-parse --short HEAD)" # re-run what changed, then name the version after the commit
|
|
88
|
+
d2b github-workflow > .github/workflows/d2b.yml # CI: push on merge to main, scheduled pull → PR
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Output is JSON on stdout; errors carry their `suggested_fix` on stderr; exit
|
|
92
|
+
codes are 0 / 1 (API errors, refused syncs) / 2 (usage). Nothing prompts
|
|
93
|
+
interactively.
|
|
94
|
+
|
|
95
|
+
`d2b login` targets `https://d2b.dev` unless `--base-url` or `$D2B_BASE_URL`
|
|
96
|
+
says otherwise. For non-interactive use set `D2B_API_KEY` and `D2B_BASE_URL`
|
|
97
|
+
— **never pass secrets as command-line arguments** (`--api-key` is not
|
|
98
|
+
accepted, and secret-shaped strings are redacted from error messages).
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT ([LICENSE](LICENSE)). "D2B", its name and logo, are trademarks and are not
|
|
103
|
+
covered by this license.
|
d2b_sdk-0.1.0/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# d2b-sdk — D2B Python SDK
|
|
2
|
+
|
|
3
|
+
Spreadsheets for AI Agents: typed, versioned, governed tables behind an
|
|
4
|
+
agent-native API.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install d2b-sdk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The distribution is `d2b-sdk`; the import package and the command are both
|
|
11
|
+
`d2b` (`d2b` on PyPI is an unrelated project). With `uvx`, that means
|
|
12
|
+
`uvx --from d2b-sdk d2b ...`.
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from d2b import D2BClient, ConflictError
|
|
16
|
+
|
|
17
|
+
client = D2BClient(api_key="d2b_pat_...", base_url="https://d2b.dev")
|
|
18
|
+
wb = client.workbooks.create(title="monthly")["id"]
|
|
19
|
+
|
|
20
|
+
# Large files are safe: the SDK drives the async ingest and waits on the job.
|
|
21
|
+
client.sources.upload(wb, "sales.xlsx", wait=True)
|
|
22
|
+
|
|
23
|
+
for t in client.tables.list(wb):
|
|
24
|
+
print(t["name"], t["row_count"])
|
|
25
|
+
|
|
26
|
+
# Row edits are optimistically locked — a 409 is ConflictError, and the
|
|
27
|
+
# contract is to re-read and re-apply rather than retry.
|
|
28
|
+
page = client.tables.rows(wb, "sales")
|
|
29
|
+
try:
|
|
30
|
+
client.tables.upsert_rows(
|
|
31
|
+
wb, "sales",
|
|
32
|
+
rows=[{"product": "apple", "qty": 3}],
|
|
33
|
+
expected_version=page["edit_version"],
|
|
34
|
+
)
|
|
35
|
+
except ConflictError:
|
|
36
|
+
page = client.tables.rows(wb, "sales")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The client is a thin skin over the REST API — every method maps to one
|
|
40
|
+
endpoint:
|
|
41
|
+
|
|
42
|
+
- an `Idempotency-Key` on every mutating call (retry-safe);
|
|
43
|
+
- exponential-backoff retry on 429 / 5xx. **409 is never retried**;
|
|
44
|
+
- problem+json errors raised with their `suggested_fix` attached (written for
|
|
45
|
+
LLMs to read and react to);
|
|
46
|
+
- helpers for the parts that bite: `jobs.wait()`, `tables.iter_rows()`,
|
|
47
|
+
`webhooks.verify_delivery()` (signature + send-time check).
|
|
48
|
+
|
|
49
|
+
Docs: [docs.d2b.dev](https://docs.d2b.dev) ·
|
|
50
|
+
[API reference](https://docs.d2b.dev/en/api-reference) ·
|
|
51
|
+
[日本語](https://docs.d2b.dev/ja)
|
|
52
|
+
|
|
53
|
+
## CLI
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
d2b login # browser login; no raw API keys
|
|
57
|
+
d2b workbooks create --title monthly
|
|
58
|
+
d2b upload sales.xlsx --workbook WB --wait
|
|
59
|
+
d2b query 'SELECT 1' --workbook WB
|
|
60
|
+
d2b pull --workbook WB # transforms/ sheets/ charts/ + d2b.json
|
|
61
|
+
d2b pull --data customers # track base tables as data/*.csv too
|
|
62
|
+
d2b push --commit "$(git rev-parse --short HEAD)" # re-run what changed, then name the version after the commit
|
|
63
|
+
d2b github-workflow > .github/workflows/d2b.yml # CI: push on merge to main, scheduled pull → PR
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Output is JSON on stdout; errors carry their `suggested_fix` on stderr; exit
|
|
67
|
+
codes are 0 / 1 (API errors, refused syncs) / 2 (usage). Nothing prompts
|
|
68
|
+
interactively.
|
|
69
|
+
|
|
70
|
+
`d2b login` targets `https://d2b.dev` unless `--base-url` or `$D2B_BASE_URL`
|
|
71
|
+
says otherwise. For non-interactive use set `D2B_API_KEY` and `D2B_BASE_URL`
|
|
72
|
+
— **never pass secrets as command-line arguments** (`--api-key` is not
|
|
73
|
+
accepted, and secret-shaped strings are redacted from error messages).
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT ([LICENSE](LICENSE)). "D2B", its name and logo, are trademarks and are not
|
|
78
|
+
covered by this license.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""D2B Python SDK — Spreadsheets for AI Agents.
|
|
2
|
+
|
|
3
|
+
A thin, agent-native client over the D2B v1 API. The ergonomics live
|
|
4
|
+
in behaviour, not just types:
|
|
5
|
+
|
|
6
|
+
- automatic ``Idempotency-Key`` on every mutating call (retry-safe);
|
|
7
|
+
- transparent retry with backoff on 429/5xx;
|
|
8
|
+
- problem+json errors surfaced as typed exceptions carrying
|
|
9
|
+
``suggested_fix`` (written for LLMs to read and react);
|
|
10
|
+
- ``jobs.wait()`` for the async ingest flow;
|
|
11
|
+
- ``webhooks.verify_delivery()`` for the delivery HMAC + send-time check.
|
|
12
|
+
|
|
13
|
+
Quickstart::
|
|
14
|
+
|
|
15
|
+
from d2b import D2BClient
|
|
16
|
+
|
|
17
|
+
client = D2BClient(api_key="d2b_pat_...", base_url="https://d2b.dev")
|
|
18
|
+
wb = client.workbooks.create(title="monthly")
|
|
19
|
+
job = client.sources.upload(wb["id"], "sales.xlsx", wait=True)
|
|
20
|
+
for t in client.tables.list(wb["id"]):
|
|
21
|
+
print(t["name"], t["row_count"])
|
|
22
|
+
"""
|
|
23
|
+
from ._version import __version__
|
|
24
|
+
from .client import (
|
|
25
|
+
ConflictError,
|
|
26
|
+
D2BClient,
|
|
27
|
+
D2BError,
|
|
28
|
+
NotFoundError,
|
|
29
|
+
PolicyError,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"D2BClient",
|
|
34
|
+
"D2BError",
|
|
35
|
+
"ConflictError",
|
|
36
|
+
"NotFoundError",
|
|
37
|
+
"PolicyError",
|
|
38
|
+
"__version__",
|
|
39
|
+
]
|