databar 2.7.0__tar.gz → 2.8.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.
- {databar-2.7.0/src/databar.egg-info → databar-2.8.0}/PKG-INFO +1 -1
- {databar-2.7.0 → databar-2.8.0}/pyproject.toml +1 -1
- {databar-2.7.0 → databar-2.8.0}/src/databar/__init__.py +13 -1
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/app.py +3 -1
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/tables.py +83 -0
- databar-2.8.0/src/databar/cli/workbooks.py +233 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/client.py +173 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/models.py +55 -1
- {databar-2.7.0 → databar-2.8.0/src/databar.egg-info}/PKG-INFO +1 -1
- {databar-2.7.0 → databar-2.8.0}/src/databar.egg-info/SOURCES.txt +3 -1
- {databar-2.7.0 → databar-2.8.0}/tests/test_cli.py +1 -1
- databar-2.8.0/tests/test_workbooks.py +90 -0
- {databar-2.7.0 → databar-2.8.0}/LICENSE +0 -0
- {databar-2.7.0 → databar-2.8.0}/README.md +0 -0
- {databar-2.7.0 → databar-2.8.0}/setup.cfg +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/__init__.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/_auth.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/_guide.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/_oauth.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/_onboard.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/_output.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/enrichments.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/flows.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/tasks.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/cli/waterfalls.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar/exceptions.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar.egg-info/dependency_links.txt +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar.egg-info/entry_points.txt +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar.egg-info/requires.txt +0 -0
- {databar-2.7.0 → databar-2.8.0}/src/databar.egg-info/top_level.txt +0 -0
- {databar-2.7.0 → databar-2.8.0}/tests/test_client.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/tests/test_new_features.py +0 -0
- {databar-2.7.0 → databar-2.8.0}/tests/test_oauth_login.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "databar"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.8.0"
|
|
8
8
|
description = "Official Databar.ai Python SDK and CLI — connect to enrichments, waterfalls, and tables via api.databar.ai"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
@@ -108,9 +108,15 @@ from .models import (
|
|
|
108
108
|
Connector,
|
|
109
109
|
# Folders
|
|
110
110
|
Folder,
|
|
111
|
+
# Workbooks / trash
|
|
112
|
+
Workbook,
|
|
113
|
+
WorkbookTable,
|
|
114
|
+
ExportStatus,
|
|
115
|
+
DedupeResult,
|
|
116
|
+
TrashItem,
|
|
111
117
|
)
|
|
112
118
|
|
|
113
|
-
__version__ = "2.
|
|
119
|
+
__version__ = "2.8.0"
|
|
114
120
|
__all__ = [
|
|
115
121
|
"DatabarClient",
|
|
116
122
|
# exceptions
|
|
@@ -195,4 +201,10 @@ __all__ = [
|
|
|
195
201
|
"Connector",
|
|
196
202
|
# folders
|
|
197
203
|
"Folder",
|
|
204
|
+
# workbooks
|
|
205
|
+
"Workbook",
|
|
206
|
+
"WorkbookTable",
|
|
207
|
+
"ExportStatus",
|
|
208
|
+
"DedupeResult",
|
|
209
|
+
"TrashItem",
|
|
198
210
|
]
|
|
@@ -12,7 +12,7 @@ import typer
|
|
|
12
12
|
|
|
13
13
|
from databar import __version__
|
|
14
14
|
|
|
15
|
-
from . import enrichments, flows, tables, tasks, waterfalls
|
|
15
|
+
from . import enrichments, flows, tables, tasks, waterfalls, workbooks
|
|
16
16
|
from ._auth import app as auth_app
|
|
17
17
|
|
|
18
18
|
app = typer.Typer(
|
|
@@ -35,6 +35,8 @@ app.add_typer(waterfalls.app, name="waterfall")
|
|
|
35
35
|
app.add_typer(flows.app, name="flow")
|
|
36
36
|
app.add_typer(tables.app, name="table")
|
|
37
37
|
app.add_typer(tasks.app, name="task")
|
|
38
|
+
app.add_typer(workbooks.workbook_app, name="workbook")
|
|
39
|
+
app.add_typer(workbooks.trash_app, name="trash")
|
|
38
40
|
|
|
39
41
|
|
|
40
42
|
@app.command("onboard")
|
|
@@ -386,6 +386,89 @@ def run_table_enrichment(
|
|
|
386
386
|
output(result, OutputFormat.JSON)
|
|
387
387
|
|
|
388
388
|
|
|
389
|
+
@app.command("duplicate")
|
|
390
|
+
def duplicate_table(
|
|
391
|
+
table_uuid: str = _TABLE_UUID,
|
|
392
|
+
fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
|
|
393
|
+
) -> None:
|
|
394
|
+
"""Duplicate a table into a new workbook."""
|
|
395
|
+
client = get_client()
|
|
396
|
+
try:
|
|
397
|
+
table = client.duplicate_table(table_uuid)
|
|
398
|
+
except DatabarError as e:
|
|
399
|
+
error(e)
|
|
400
|
+
finally:
|
|
401
|
+
client.close()
|
|
402
|
+
success(f"Duplicated as {table.identifier}")
|
|
403
|
+
output({"uuid": table.identifier, "name": table.name, "workbook": table.workbook}, fmt)
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
@app.command("clear")
|
|
407
|
+
def clear_table(table_uuid: str = _TABLE_UUID) -> None:
|
|
408
|
+
"""Queue deletion of every row in the table."""
|
|
409
|
+
client = get_client()
|
|
410
|
+
try:
|
|
411
|
+
client.clear_table(table_uuid)
|
|
412
|
+
except DatabarError as e:
|
|
413
|
+
error(e)
|
|
414
|
+
finally:
|
|
415
|
+
client.close()
|
|
416
|
+
success("Clear queued.")
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
@app.command("export")
|
|
420
|
+
def export_table(
|
|
421
|
+
table_uuid: str = _TABLE_UUID,
|
|
422
|
+
format: str = typer.Option("csv", "--export-format", help="csv, xlsx, or sheets."),
|
|
423
|
+
fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
|
|
424
|
+
) -> None:
|
|
425
|
+
"""Start a table export. Poll status with get-export."""
|
|
426
|
+
client = get_client()
|
|
427
|
+
try:
|
|
428
|
+
status = client.export_table(table_uuid, format=format)
|
|
429
|
+
except DatabarError as e:
|
|
430
|
+
error(e)
|
|
431
|
+
finally:
|
|
432
|
+
client.close()
|
|
433
|
+
success(f"Export queued (file_id={status.file_id})")
|
|
434
|
+
output(status.model_dump(), fmt)
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
@app.command("get-export")
|
|
438
|
+
def get_table_export(
|
|
439
|
+
table_uuid: str = _TABLE_UUID,
|
|
440
|
+
fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
|
|
441
|
+
) -> None:
|
|
442
|
+
"""Check the latest export status / download URL."""
|
|
443
|
+
client = get_client()
|
|
444
|
+
try:
|
|
445
|
+
status = client.get_table_export(table_uuid)
|
|
446
|
+
except DatabarError as e:
|
|
447
|
+
error(e)
|
|
448
|
+
finally:
|
|
449
|
+
client.close()
|
|
450
|
+
output(status.model_dump(), fmt)
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
@app.command("dedupe")
|
|
454
|
+
def dedupe_table(
|
|
455
|
+
table_uuid: str = _TABLE_UUID,
|
|
456
|
+
columns: Optional[str] = typer.Option(None, "--columns", help="Comma-separated column UUIDs."),
|
|
457
|
+
fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
|
|
458
|
+
) -> None:
|
|
459
|
+
"""Delete duplicate rows, keeping the oldest of each group."""
|
|
460
|
+
col_ids = [c.strip() for c in columns.split(",")] if columns else None
|
|
461
|
+
client = get_client()
|
|
462
|
+
try:
|
|
463
|
+
result = client.dedupe_table_rows(table_uuid, columns=col_ids)
|
|
464
|
+
except DatabarError as e:
|
|
465
|
+
error(e)
|
|
466
|
+
finally:
|
|
467
|
+
client.close()
|
|
468
|
+
success(f"Deleted {result.count_rows_delete} duplicate rows.")
|
|
469
|
+
output(result.model_dump(), fmt)
|
|
470
|
+
|
|
471
|
+
|
|
389
472
|
# ---------------------------------------------------------------------------
|
|
390
473
|
# Helpers
|
|
391
474
|
# ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI commands for workbooks and trash.
|
|
3
|
+
|
|
4
|
+
databar workbook list
|
|
5
|
+
databar workbook get <id>
|
|
6
|
+
databar workbook rename <id> --name
|
|
7
|
+
databar workbook delete <id>
|
|
8
|
+
databar workbook duplicate <id>
|
|
9
|
+
databar workbook merge --target <id> --sources id1,id2
|
|
10
|
+
databar workbook add-table <id> [--name]
|
|
11
|
+
databar trash list
|
|
12
|
+
databar trash restore --workbooks id1 [--tables uuid]
|
|
13
|
+
databar trash purge --workbooks id1 [--tables uuid]
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from typing import Optional
|
|
19
|
+
|
|
20
|
+
import typer
|
|
21
|
+
|
|
22
|
+
from databar.exceptions import DatabarError
|
|
23
|
+
|
|
24
|
+
from ._auth import get_client
|
|
25
|
+
from ._output import OutputFormat, error, info, output, success
|
|
26
|
+
|
|
27
|
+
workbook_app = typer.Typer(help="Manage workbooks (multi-sheet documents).")
|
|
28
|
+
trash_app = typer.Typer(help="List, restore, or permanently delete trash.")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@workbook_app.command("list")
|
|
32
|
+
def list_workbooks(
|
|
33
|
+
fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
|
|
34
|
+
) -> None:
|
|
35
|
+
"""List workbooks in your workspace."""
|
|
36
|
+
client = get_client()
|
|
37
|
+
try:
|
|
38
|
+
workbooks = client.list_workbooks()
|
|
39
|
+
except DatabarError as e:
|
|
40
|
+
error(e)
|
|
41
|
+
finally:
|
|
42
|
+
client.close()
|
|
43
|
+
|
|
44
|
+
if not workbooks:
|
|
45
|
+
info("No workbooks found.")
|
|
46
|
+
output([], fmt)
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
rows = [
|
|
50
|
+
{
|
|
51
|
+
"id": w.identifier,
|
|
52
|
+
"name": w.name,
|
|
53
|
+
"tables": w.tables_count,
|
|
54
|
+
"updated": w.updated_at,
|
|
55
|
+
}
|
|
56
|
+
for w in workbooks
|
|
57
|
+
]
|
|
58
|
+
output(rows, fmt, table_columns=["id", "name", "tables", "updated"])
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@workbook_app.command("get")
|
|
62
|
+
def get_workbook(
|
|
63
|
+
workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
|
|
64
|
+
fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
|
|
65
|
+
) -> None:
|
|
66
|
+
"""Show one workbook and its sheets."""
|
|
67
|
+
client = get_client()
|
|
68
|
+
try:
|
|
69
|
+
wb = client.get_workbook(workbook_id)
|
|
70
|
+
except DatabarError as e:
|
|
71
|
+
error(e)
|
|
72
|
+
finally:
|
|
73
|
+
client.close()
|
|
74
|
+
|
|
75
|
+
output(
|
|
76
|
+
{
|
|
77
|
+
"id": wb.identifier,
|
|
78
|
+
"name": wb.name,
|
|
79
|
+
"tables": [{"uuid": t.identifier, "name": t.name, "position": t.position} for t in wb.tables],
|
|
80
|
+
},
|
|
81
|
+
fmt,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@workbook_app.command("rename")
|
|
86
|
+
def rename_workbook(
|
|
87
|
+
workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
|
|
88
|
+
name: str = typer.Option(..., "--name", "-n", help="New name."),
|
|
89
|
+
) -> None:
|
|
90
|
+
"""Rename a workbook."""
|
|
91
|
+
client = get_client()
|
|
92
|
+
try:
|
|
93
|
+
wb = client.rename_workbook(workbook_id, name)
|
|
94
|
+
except DatabarError as e:
|
|
95
|
+
error(e)
|
|
96
|
+
finally:
|
|
97
|
+
client.close()
|
|
98
|
+
success(f"Renamed workbook to {wb.name!r}")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@workbook_app.command("delete")
|
|
102
|
+
def delete_workbook(
|
|
103
|
+
workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
|
|
104
|
+
) -> None:
|
|
105
|
+
"""Move a workbook to Trash."""
|
|
106
|
+
client = get_client()
|
|
107
|
+
try:
|
|
108
|
+
client.delete_workbook(workbook_id)
|
|
109
|
+
except DatabarError as e:
|
|
110
|
+
error(e)
|
|
111
|
+
finally:
|
|
112
|
+
client.close()
|
|
113
|
+
success(f"Workbook {workbook_id} moved to trash.")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@workbook_app.command("duplicate")
|
|
117
|
+
def duplicate_workbook(
|
|
118
|
+
workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
|
|
119
|
+
fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
|
|
120
|
+
) -> None:
|
|
121
|
+
"""Duplicate a workbook."""
|
|
122
|
+
client = get_client()
|
|
123
|
+
try:
|
|
124
|
+
wb = client.duplicate_workbook(workbook_id)
|
|
125
|
+
except DatabarError as e:
|
|
126
|
+
error(e)
|
|
127
|
+
finally:
|
|
128
|
+
client.close()
|
|
129
|
+
success(f"Duplicated as {wb.identifier}")
|
|
130
|
+
output({"id": wb.identifier, "name": wb.name, "tables": wb.tables_count}, fmt)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@workbook_app.command("merge")
|
|
134
|
+
def merge_workbooks(
|
|
135
|
+
target: str = typer.Option(..., "--target", help="Workbook that keeps the sheets."),
|
|
136
|
+
sources: str = typer.Option(..., "--sources", help="Comma-separated workbook ids to fold in."),
|
|
137
|
+
) -> None:
|
|
138
|
+
"""Merge source workbooks into target."""
|
|
139
|
+
source_ids = [s.strip() for s in sources.split(",") if s.strip()]
|
|
140
|
+
client = get_client()
|
|
141
|
+
try:
|
|
142
|
+
wb = client.merge_workbooks(target, source_ids)
|
|
143
|
+
except DatabarError as e:
|
|
144
|
+
error(e)
|
|
145
|
+
finally:
|
|
146
|
+
client.close()
|
|
147
|
+
success(f"Merged into {wb.identifier} ({wb.tables_count} sheets)")
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@workbook_app.command("add-table")
|
|
151
|
+
def add_workbook_table(
|
|
152
|
+
workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
|
|
153
|
+
name: Optional[str] = typer.Option(None, "--name", "-n", help="Sheet name."),
|
|
154
|
+
) -> None:
|
|
155
|
+
"""Add an empty sheet to a workbook."""
|
|
156
|
+
client = get_client()
|
|
157
|
+
try:
|
|
158
|
+
table = client.add_workbook_table(workbook_id, name=name)
|
|
159
|
+
except DatabarError as e:
|
|
160
|
+
error(e)
|
|
161
|
+
finally:
|
|
162
|
+
client.close()
|
|
163
|
+
success(f"Added table {table.get('identifier')}")
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@trash_app.command("list")
|
|
167
|
+
def list_trash(
|
|
168
|
+
fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
|
|
169
|
+
) -> None:
|
|
170
|
+
"""List items in Trash."""
|
|
171
|
+
client = get_client()
|
|
172
|
+
try:
|
|
173
|
+
items = client.list_trash()
|
|
174
|
+
except DatabarError as e:
|
|
175
|
+
error(e)
|
|
176
|
+
finally:
|
|
177
|
+
client.close()
|
|
178
|
+
|
|
179
|
+
if not items:
|
|
180
|
+
info("Trash is empty.")
|
|
181
|
+
output([], fmt)
|
|
182
|
+
return
|
|
183
|
+
|
|
184
|
+
rows = [
|
|
185
|
+
{
|
|
186
|
+
"kind": i.kind,
|
|
187
|
+
"id": i.identifier,
|
|
188
|
+
"name": i.name,
|
|
189
|
+
"trashed_at": i.trashed_at,
|
|
190
|
+
}
|
|
191
|
+
for i in items
|
|
192
|
+
]
|
|
193
|
+
output(rows, fmt, table_columns=["kind", "id", "name", "trashed_at"])
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
@trash_app.command("restore")
|
|
197
|
+
def restore_trash(
|
|
198
|
+
workbooks: Optional[str] = typer.Option(None, "--workbooks", help="Comma-separated workbook ids."),
|
|
199
|
+
tables: Optional[str] = typer.Option(None, "--tables", help="Comma-separated table UUIDs."),
|
|
200
|
+
) -> None:
|
|
201
|
+
"""Restore workbooks and/or tables from Trash."""
|
|
202
|
+
wb_ids = [s.strip() for s in (workbooks or "").split(",") if s.strip()]
|
|
203
|
+
table_ids = [s.strip() for s in (tables or "").split(",") if s.strip()]
|
|
204
|
+
if not wb_ids and not table_ids:
|
|
205
|
+
error("Pass --workbooks and/or --tables.")
|
|
206
|
+
client = get_client()
|
|
207
|
+
try:
|
|
208
|
+
client.restore_trash(workbooks=wb_ids, tables=table_ids)
|
|
209
|
+
except DatabarError as e:
|
|
210
|
+
error(e)
|
|
211
|
+
finally:
|
|
212
|
+
client.close()
|
|
213
|
+
success("Restored.")
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
@trash_app.command("purge")
|
|
217
|
+
def purge_trash(
|
|
218
|
+
workbooks: Optional[str] = typer.Option(None, "--workbooks", help="Comma-separated workbook ids."),
|
|
219
|
+
tables: Optional[str] = typer.Option(None, "--tables", help="Comma-separated table UUIDs."),
|
|
220
|
+
) -> None:
|
|
221
|
+
"""Permanently delete workbooks and/or tables from Trash."""
|
|
222
|
+
wb_ids = [s.strip() for s in (workbooks or "").split(",") if s.strip()]
|
|
223
|
+
table_ids = [s.strip() for s in (tables or "").split(",") if s.strip()]
|
|
224
|
+
if not wb_ids and not table_ids:
|
|
225
|
+
error("Pass --workbooks and/or --tables.")
|
|
226
|
+
client = get_client()
|
|
227
|
+
try:
|
|
228
|
+
client.purge_trash(workbooks=wb_ids, tables=table_ids)
|
|
229
|
+
except DatabarError as e:
|
|
230
|
+
error(e)
|
|
231
|
+
finally:
|
|
232
|
+
client.close()
|
|
233
|
+
success("Purged.")
|
|
@@ -65,10 +65,12 @@ from .models import (
|
|
|
65
65
|
Connector,
|
|
66
66
|
CreateColumnResponse,
|
|
67
67
|
DedupeOptions,
|
|
68
|
+
DedupeResult,
|
|
68
69
|
Enrichment,
|
|
69
70
|
EnrichmentListResponse,
|
|
70
71
|
EnrichmentSummary,
|
|
71
72
|
Exporter,
|
|
73
|
+
ExportStatus,
|
|
72
74
|
ExporterDetail,
|
|
73
75
|
ExporterListResponse,
|
|
74
76
|
ExporterParam,
|
|
@@ -93,10 +95,12 @@ from .models import (
|
|
|
93
95
|
Table,
|
|
94
96
|
TableEnrichment,
|
|
95
97
|
TaskResponse,
|
|
98
|
+
TrashItem,
|
|
96
99
|
UpsertResponse,
|
|
97
100
|
UpsertRow,
|
|
98
101
|
User,
|
|
99
102
|
Waterfall,
|
|
103
|
+
Workbook,
|
|
100
104
|
)
|
|
101
105
|
|
|
102
106
|
DEFAULT_BASE_URL = "https://api.databar.ai/v1"
|
|
@@ -866,6 +870,53 @@ class DatabarClient:
|
|
|
866
870
|
data = self._request("PATCH", f"/table/{table_uuid}", json={"name": name})
|
|
867
871
|
return Table.model_validate(data)
|
|
868
872
|
|
|
873
|
+
def duplicate_table(self, table_uuid: str) -> Table:
|
|
874
|
+
"""Duplicate a table into a new workbook."""
|
|
875
|
+
data = self._request("POST", "/table/duplicate", json={"table": table_uuid})
|
|
876
|
+
return Table.model_validate(data)
|
|
877
|
+
|
|
878
|
+
def move_table(
|
|
879
|
+
self,
|
|
880
|
+
table_uuid: str,
|
|
881
|
+
*,
|
|
882
|
+
workbook: Optional[str] = None,
|
|
883
|
+
new_workbook: bool = False,
|
|
884
|
+
name: Optional[str] = None,
|
|
885
|
+
) -> Dict[str, Any]:
|
|
886
|
+
"""Move a table into another workbook, or into a freshly created workbook."""
|
|
887
|
+
payload: Dict[str, Any] = {"new_workbook": new_workbook}
|
|
888
|
+
if workbook is not None:
|
|
889
|
+
payload["workbook"] = workbook
|
|
890
|
+
if name is not None:
|
|
891
|
+
payload["name"] = name
|
|
892
|
+
return self._request("POST", f"/table/{table_uuid}/move", json=payload) or {}
|
|
893
|
+
|
|
894
|
+
def clear_table(self, table_uuid: str) -> Dict[str, Any]:
|
|
895
|
+
"""Queue deletion of every row in the table."""
|
|
896
|
+
return self._request("POST", f"/table/{table_uuid}/clear") or {}
|
|
897
|
+
|
|
898
|
+
def export_table(self, table_uuid: str, format: str = "csv") -> ExportStatus:
|
|
899
|
+
"""Start a table export. Poll :meth:`get_table_export` for the file URL."""
|
|
900
|
+
data = self._request("POST", f"/table/{table_uuid}/export", json={"format": format})
|
|
901
|
+
return ExportStatus.model_validate(data)
|
|
902
|
+
|
|
903
|
+
def get_table_export(self, table_uuid: str) -> ExportStatus:
|
|
904
|
+
"""Status of the latest export for a table."""
|
|
905
|
+
data = self._request("GET", f"/table/{table_uuid}/export")
|
|
906
|
+
return ExportStatus.model_validate(data)
|
|
907
|
+
|
|
908
|
+
def dedupe_table_rows(
|
|
909
|
+
self,
|
|
910
|
+
table_uuid: str,
|
|
911
|
+
columns: Optional[List[str]] = None,
|
|
912
|
+
) -> DedupeResult:
|
|
913
|
+
"""Delete duplicate rows, keeping the oldest of each group."""
|
|
914
|
+
payload: Dict[str, Any] = {}
|
|
915
|
+
if columns is not None:
|
|
916
|
+
payload["columns"] = columns
|
|
917
|
+
data = self._request("POST", f"/table/{table_uuid}/rows/dedupe", json=payload or None)
|
|
918
|
+
return DedupeResult.model_validate(data)
|
|
919
|
+
|
|
869
920
|
# -----------------------------------------------------------------------
|
|
870
921
|
# Tables — Columns
|
|
871
922
|
# -----------------------------------------------------------------------
|
|
@@ -916,6 +967,17 @@ class DatabarClient:
|
|
|
916
967
|
"""Delete a column from a table."""
|
|
917
968
|
self._request("DELETE", f"/table/{table_uuid}/columns/{column_id}")
|
|
918
969
|
|
|
970
|
+
def reorder_column(self, table_uuid: str, column_id: str, index: int) -> Dict[str, Any]:
|
|
971
|
+
"""Move a column to a new 0-based index among non-system columns."""
|
|
972
|
+
return (
|
|
973
|
+
self._request(
|
|
974
|
+
"POST",
|
|
975
|
+
f"/table/{table_uuid}/columns/{column_id}/reorder",
|
|
976
|
+
json={"index": index},
|
|
977
|
+
)
|
|
978
|
+
or {}
|
|
979
|
+
)
|
|
980
|
+
|
|
919
981
|
# -----------------------------------------------------------------------
|
|
920
982
|
# Tables — Enrichments
|
|
921
983
|
# -----------------------------------------------------------------------
|
|
@@ -982,6 +1044,27 @@ class DatabarClient:
|
|
|
982
1044
|
data = self._request("POST", f"/table/{table_uuid}/add-enrichment", json=payload)
|
|
983
1045
|
return AddEnrichmentResponse.model_validate(data)
|
|
984
1046
|
|
|
1047
|
+
def update_enrichment(
|
|
1048
|
+
self,
|
|
1049
|
+
table_uuid: str,
|
|
1050
|
+
enrichment_id: int,
|
|
1051
|
+
*,
|
|
1052
|
+
mapping: Optional[Dict[str, Any]] = None,
|
|
1053
|
+
launch_strategy: Optional[Literal["run_on_click", "run_on_update"]] = None,
|
|
1054
|
+
) -> AddEnrichmentResponse:
|
|
1055
|
+
"""Update the mapping and/or launch strategy of an attached enrichment."""
|
|
1056
|
+
payload: Dict[str, Any] = {}
|
|
1057
|
+
if mapping is not None:
|
|
1058
|
+
payload["mapping"] = mapping
|
|
1059
|
+
if launch_strategy is not None:
|
|
1060
|
+
payload["launch_strategy"] = launch_strategy
|
|
1061
|
+
data = self._request(
|
|
1062
|
+
"PATCH",
|
|
1063
|
+
f"/table/{table_uuid}/enrichments/{enrichment_id}",
|
|
1064
|
+
json=payload,
|
|
1065
|
+
)
|
|
1066
|
+
return AddEnrichmentResponse.model_validate(data)
|
|
1067
|
+
|
|
985
1068
|
def run_table_enrichment(
|
|
986
1069
|
self,
|
|
987
1070
|
table_uuid: str,
|
|
@@ -1431,3 +1514,93 @@ class DatabarClient:
|
|
|
1431
1514
|
payload["folder_id"] = folder_id
|
|
1432
1515
|
data = self._request("POST", "/folders/move-table", json=payload)
|
|
1433
1516
|
return data or {}
|
|
1517
|
+
|
|
1518
|
+
# -----------------------------------------------------------------------
|
|
1519
|
+
# Workbooks
|
|
1520
|
+
# -----------------------------------------------------------------------
|
|
1521
|
+
|
|
1522
|
+
def list_workbooks(self) -> List[Workbook]:
|
|
1523
|
+
"""List workbooks (multi-sheet documents) in the workspace."""
|
|
1524
|
+
data = self._request("GET", "/workbooks")
|
|
1525
|
+
return [Workbook.model_validate(w) for w in data]
|
|
1526
|
+
|
|
1527
|
+
def get_workbook(self, workbook_id: str) -> Workbook:
|
|
1528
|
+
"""Get one workbook and its sheets."""
|
|
1529
|
+
data = self._request("GET", f"/workbooks/{workbook_id}")
|
|
1530
|
+
return Workbook.model_validate(data)
|
|
1531
|
+
|
|
1532
|
+
def rename_workbook(self, workbook_id: str, name: str) -> Workbook:
|
|
1533
|
+
"""Rename a workbook."""
|
|
1534
|
+
data = self._request("PATCH", f"/workbooks/{workbook_id}", json={"name": name})
|
|
1535
|
+
return Workbook.model_validate(data)
|
|
1536
|
+
|
|
1537
|
+
def delete_workbook(self, workbook_id: str) -> None:
|
|
1538
|
+
"""Move a workbook to Trash."""
|
|
1539
|
+
self._request("DELETE", f"/workbooks/{workbook_id}")
|
|
1540
|
+
|
|
1541
|
+
def duplicate_workbook(self, workbook_id: str) -> Workbook:
|
|
1542
|
+
"""Duplicate every sheet in a workbook into a new document."""
|
|
1543
|
+
data = self._request("POST", f"/workbooks/{workbook_id}/duplicate")
|
|
1544
|
+
return Workbook.model_validate(data)
|
|
1545
|
+
|
|
1546
|
+
def merge_workbooks(self, target: str, sources: List[str]) -> Workbook:
|
|
1547
|
+
"""Move every live table from source workbooks onto target."""
|
|
1548
|
+
data = self._request("POST", "/workbooks/merge", json={"target": target, "sources": sources})
|
|
1549
|
+
return Workbook.model_validate(data)
|
|
1550
|
+
|
|
1551
|
+
def add_workbook_table(self, workbook_id: str, name: Optional[str] = None) -> Dict[str, Any]:
|
|
1552
|
+
"""Add an empty sheet to a workbook."""
|
|
1553
|
+
payload: Dict[str, Any] = {}
|
|
1554
|
+
if name is not None:
|
|
1555
|
+
payload["name"] = name
|
|
1556
|
+
return self._request("POST", f"/workbooks/{workbook_id}/tables", json=payload or None) or {}
|
|
1557
|
+
|
|
1558
|
+
def reorder_workbook_tables(self, workbook_id: str, table_ids: List[str]) -> Workbook:
|
|
1559
|
+
"""Set sheet order. ``table_ids`` must list every live table exactly once."""
|
|
1560
|
+
data = self._request(
|
|
1561
|
+
"POST",
|
|
1562
|
+
f"/workbooks/{workbook_id}/tables/reorder",
|
|
1563
|
+
json={"table_ids": table_ids},
|
|
1564
|
+
)
|
|
1565
|
+
return Workbook.model_validate(data)
|
|
1566
|
+
|
|
1567
|
+
# -----------------------------------------------------------------------
|
|
1568
|
+
# Trash
|
|
1569
|
+
# -----------------------------------------------------------------------
|
|
1570
|
+
|
|
1571
|
+
def list_trash(self) -> List[TrashItem]:
|
|
1572
|
+
"""List binned workbooks and tables."""
|
|
1573
|
+
data = self._request("GET", "/trash")
|
|
1574
|
+
return [TrashItem.model_validate(i) for i in data]
|
|
1575
|
+
|
|
1576
|
+
def restore_trash(
|
|
1577
|
+
self,
|
|
1578
|
+
*,
|
|
1579
|
+
workbooks: Optional[List[str]] = None,
|
|
1580
|
+
tables: Optional[List[str]] = None,
|
|
1581
|
+
) -> Dict[str, Any]:
|
|
1582
|
+
"""Restore workbooks and/or tables from Trash."""
|
|
1583
|
+
return (
|
|
1584
|
+
self._request(
|
|
1585
|
+
"POST",
|
|
1586
|
+
"/trash/restore",
|
|
1587
|
+
json={"workbooks": workbooks or [], "tables": tables or []},
|
|
1588
|
+
)
|
|
1589
|
+
or {}
|
|
1590
|
+
)
|
|
1591
|
+
|
|
1592
|
+
def purge_trash(
|
|
1593
|
+
self,
|
|
1594
|
+
*,
|
|
1595
|
+
workbooks: Optional[List[str]] = None,
|
|
1596
|
+
tables: Optional[List[str]] = None,
|
|
1597
|
+
) -> Dict[str, Any]:
|
|
1598
|
+
"""Permanently delete workbooks and/or tables from Trash."""
|
|
1599
|
+
return (
|
|
1600
|
+
self._request(
|
|
1601
|
+
"POST",
|
|
1602
|
+
"/trash/delete-forever",
|
|
1603
|
+
json={"workbooks": workbooks or [], "tables": tables or []},
|
|
1604
|
+
)
|
|
1605
|
+
or {}
|
|
1606
|
+
)
|
|
@@ -503,7 +503,7 @@ class RestoreFlowVersionResult(BaseModel):
|
|
|
503
503
|
class Table(BaseModel):
|
|
504
504
|
"""A Databar table.
|
|
505
505
|
|
|
506
|
-
Fields: identifier, name, created_at, updated_at, workspace_identifier, table_url.
|
|
506
|
+
Fields: identifier, name, created_at, updated_at, workspace_identifier, workbook, table_url.
|
|
507
507
|
|
|
508
508
|
Property aliases: .id → .identifier, .uuid → .identifier.
|
|
509
509
|
|
|
@@ -518,6 +518,7 @@ class Table(BaseModel):
|
|
|
518
518
|
created_at: str
|
|
519
519
|
updated_at: str
|
|
520
520
|
workspace_identifier: Optional[str] = None
|
|
521
|
+
workbook: Optional[str] = Field(None, description="Parent workbook identifier (wb_…).")
|
|
521
522
|
table_url: Optional[str] = None
|
|
522
523
|
|
|
523
524
|
@property
|
|
@@ -909,3 +910,56 @@ class Folder(BaseModel):
|
|
|
909
910
|
created_at: Optional[str] = None
|
|
910
911
|
updated_at: Optional[str] = None
|
|
911
912
|
table_count: Optional[int] = None
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
# ===========================================================================
|
|
916
|
+
# Workbooks
|
|
917
|
+
# ===========================================================================
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
class WorkbookTable(BaseModel):
|
|
921
|
+
"""One sheet inside a workbook."""
|
|
922
|
+
|
|
923
|
+
identifier: str
|
|
924
|
+
name: str
|
|
925
|
+
position: int
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
class Workbook(BaseModel):
|
|
929
|
+
"""A multi-sheet document that owns one or more tables.
|
|
930
|
+
|
|
931
|
+
Fields: identifier, name, created_at, updated_at, folder_id, tables, tables_count.
|
|
932
|
+
"""
|
|
933
|
+
|
|
934
|
+
identifier: str
|
|
935
|
+
name: str
|
|
936
|
+
created_at: str
|
|
937
|
+
updated_at: str
|
|
938
|
+
folder_id: Optional[int] = None
|
|
939
|
+
tables: List[WorkbookTable] = Field(default_factory=list)
|
|
940
|
+
tables_count: int = 0
|
|
941
|
+
|
|
942
|
+
@property
|
|
943
|
+
def id(self) -> str:
|
|
944
|
+
return self.identifier
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
class ExportStatus(BaseModel):
|
|
948
|
+
status: str
|
|
949
|
+
file_id: Optional[int] = None
|
|
950
|
+
file: Optional[str] = None
|
|
951
|
+
message: Optional[str] = None
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
class DedupeResult(BaseModel):
|
|
955
|
+
count_all_rows: int
|
|
956
|
+
count_rows_delete: int
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
class TrashItem(BaseModel):
|
|
960
|
+
kind: str
|
|
961
|
+
identifier: str
|
|
962
|
+
name: str
|
|
963
|
+
trashed_at: Optional[str] = None
|
|
964
|
+
tables_count: Optional[int] = None
|
|
965
|
+
workbook: Optional[Dict[str, Any]] = None
|
|
@@ -23,7 +23,9 @@ src/databar/cli/flows.py
|
|
|
23
23
|
src/databar/cli/tables.py
|
|
24
24
|
src/databar/cli/tasks.py
|
|
25
25
|
src/databar/cli/waterfalls.py
|
|
26
|
+
src/databar/cli/workbooks.py
|
|
26
27
|
tests/test_cli.py
|
|
27
28
|
tests/test_client.py
|
|
28
29
|
tests/test_new_features.py
|
|
29
|
-
tests/test_oauth_login.py
|
|
30
|
+
tests/test_oauth_login.py
|
|
31
|
+
tests/test_workbooks.py
|
|
@@ -759,7 +759,7 @@ def test_task_cancel_reports_a_finished_task(monkeypatch):
|
|
|
759
759
|
def test_version_flag():
|
|
760
760
|
result = runner.invoke(app, ["--version"])
|
|
761
761
|
assert result.exit_code == 0
|
|
762
|
-
assert "2.
|
|
762
|
+
assert "2.8.0" in result.output
|
|
763
763
|
|
|
764
764
|
|
|
765
765
|
def test_output_module_does_not_import_click():
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Workbook, trash and table-operation client methods hit the routes the server serves."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
from pytest_httpx import HTTPXMock
|
|
8
|
+
|
|
9
|
+
from databar.client import DatabarClient
|
|
10
|
+
from databar.models import DedupeResult, ExportStatus, TrashItem, Workbook
|
|
11
|
+
|
|
12
|
+
from .conftest import BASE_URL, table_payload
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def workbook_payload(identifier: str = "wb_abc12345", **overrides) -> dict:
|
|
16
|
+
return {
|
|
17
|
+
"identifier": identifier,
|
|
18
|
+
"name": "Doc",
|
|
19
|
+
"created_at": "2026-10-06T00:00:00Z",
|
|
20
|
+
"updated_at": "2026-10-06T00:00:00Z",
|
|
21
|
+
"folder_id": None,
|
|
22
|
+
"tables": [{"identifier": "tbl-uuid-1", "name": "Sheet", "position": 0}],
|
|
23
|
+
"tables_count": 1,
|
|
24
|
+
**overrides,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_list_and_merge_workbooks(client: DatabarClient, httpx_mock: HTTPXMock):
|
|
29
|
+
httpx_mock.add_response(url=f"{BASE_URL}/workbooks", json=[workbook_payload()])
|
|
30
|
+
httpx_mock.add_response(url=f"{BASE_URL}/workbooks/merge", method="POST", json=workbook_payload(tables_count=2))
|
|
31
|
+
|
|
32
|
+
workbooks = client.list_workbooks()
|
|
33
|
+
merged = client.merge_workbooks("wb_abc12345", ["wb_other123"])
|
|
34
|
+
|
|
35
|
+
assert isinstance(workbooks[0], Workbook)
|
|
36
|
+
assert workbooks[0].tables[0].identifier == "tbl-uuid-1"
|
|
37
|
+
assert merged.tables_count == 2
|
|
38
|
+
assert json.loads(httpx_mock.get_requests()[1].content) == {"target": "wb_abc12345", "sources": ["wb_other123"]}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_table_operations(client: DatabarClient, httpx_mock: HTTPXMock):
|
|
42
|
+
httpx_mock.add_response(
|
|
43
|
+
url=f"{BASE_URL}/table/duplicate", method="POST", json=table_payload("tbl-copy", workbook="wb_new12345")
|
|
44
|
+
)
|
|
45
|
+
httpx_mock.add_response(
|
|
46
|
+
url=f"{BASE_URL}/table/tbl-uuid-1/export", method="POST", json={"status": "waiting", "file_id": 7}
|
|
47
|
+
)
|
|
48
|
+
httpx_mock.add_response(
|
|
49
|
+
url=f"{BASE_URL}/table/tbl-uuid-1/rows/dedupe",
|
|
50
|
+
method="POST",
|
|
51
|
+
json={"count_all_rows": 3, "count_rows_delete": 2},
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
copy = client.duplicate_table("tbl-uuid-1")
|
|
55
|
+
export = client.export_table("tbl-uuid-1", format="xlsx")
|
|
56
|
+
dedupe = client.dedupe_table_rows("tbl-uuid-1", columns=["col-uuid-1"])
|
|
57
|
+
|
|
58
|
+
assert copy.workbook == "wb_new12345"
|
|
59
|
+
assert isinstance(export, ExportStatus) and export.file_id == 7
|
|
60
|
+
assert isinstance(dedupe, DedupeResult) and dedupe.count_rows_delete == 2
|
|
61
|
+
requests = httpx_mock.get_requests()
|
|
62
|
+
assert json.loads(requests[0].content) == {"table": "tbl-uuid-1"}
|
|
63
|
+
assert json.loads(requests[1].content) == {"format": "xlsx"}
|
|
64
|
+
assert json.loads(requests[2].content) == {"columns": ["col-uuid-1"]}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_update_enrichment_sends_only_what_changed(client: DatabarClient, httpx_mock: HTTPXMock):
|
|
68
|
+
httpx_mock.add_response(
|
|
69
|
+
url=f"{BASE_URL}/table/tbl-uuid-1/enrichments/5",
|
|
70
|
+
method="PATCH",
|
|
71
|
+
json={"id": 5, "enrichment_name": "Email finder"},
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
client.update_enrichment("tbl-uuid-1", 5, launch_strategy="run_on_update")
|
|
75
|
+
|
|
76
|
+
assert json.loads(httpx_mock.get_requests()[0].content) == {"launch_strategy": "run_on_update"}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_trash_list_and_restore(client: DatabarClient, httpx_mock: HTTPXMock):
|
|
80
|
+
httpx_mock.add_response(
|
|
81
|
+
url=f"{BASE_URL}/trash",
|
|
82
|
+
json=[{"kind": "workbook", "identifier": "wb_abc12345", "name": "Doc", "tables_count": 1}],
|
|
83
|
+
)
|
|
84
|
+
httpx_mock.add_response(url=f"{BASE_URL}/trash/restore", method="POST", json={"status": "ok"})
|
|
85
|
+
|
|
86
|
+
items = client.list_trash()
|
|
87
|
+
client.restore_trash(workbooks=["wb_abc12345"])
|
|
88
|
+
|
|
89
|
+
assert isinstance(items[0], TrashItem) and items[0].kind == "workbook"
|
|
90
|
+
assert json.loads(httpx_mock.get_requests()[1].content) == {"workbooks": ["wb_abc12345"], "tables": []}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|