databar 2.7.0__tar.gz → 2.9.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 (33) hide show
  1. {databar-2.7.0/src/databar.egg-info → databar-2.9.0}/PKG-INFO +62 -1
  2. {databar-2.7.0 → databar-2.9.0}/README.md +61 -0
  3. {databar-2.7.0 → databar-2.9.0}/pyproject.toml +1 -1
  4. {databar-2.7.0 → databar-2.9.0}/src/databar/__init__.py +13 -1
  5. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/app.py +3 -1
  6. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/tables.py +117 -0
  7. databar-2.9.0/src/databar/cli/workbooks.py +267 -0
  8. {databar-2.7.0 → databar-2.9.0}/src/databar/client.py +173 -0
  9. {databar-2.7.0 → databar-2.9.0}/src/databar/models.py +55 -1
  10. {databar-2.7.0 → databar-2.9.0/src/databar.egg-info}/PKG-INFO +62 -1
  11. {databar-2.7.0 → databar-2.9.0}/src/databar.egg-info/SOURCES.txt +3 -1
  12. {databar-2.7.0 → databar-2.9.0}/tests/test_cli.py +73 -1
  13. databar-2.9.0/tests/test_workbooks.py +90 -0
  14. {databar-2.7.0 → databar-2.9.0}/LICENSE +0 -0
  15. {databar-2.7.0 → databar-2.9.0}/setup.cfg +0 -0
  16. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/__init__.py +0 -0
  17. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/_auth.py +0 -0
  18. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/_guide.py +0 -0
  19. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/_oauth.py +0 -0
  20. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/_onboard.py +0 -0
  21. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/_output.py +0 -0
  22. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/enrichments.py +0 -0
  23. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/flows.py +0 -0
  24. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/tasks.py +0 -0
  25. {databar-2.7.0 → databar-2.9.0}/src/databar/cli/waterfalls.py +0 -0
  26. {databar-2.7.0 → databar-2.9.0}/src/databar/exceptions.py +0 -0
  27. {databar-2.7.0 → databar-2.9.0}/src/databar.egg-info/dependency_links.txt +0 -0
  28. {databar-2.7.0 → databar-2.9.0}/src/databar.egg-info/entry_points.txt +0 -0
  29. {databar-2.7.0 → databar-2.9.0}/src/databar.egg-info/requires.txt +0 -0
  30. {databar-2.7.0 → databar-2.9.0}/src/databar.egg-info/top_level.txt +0 -0
  31. {databar-2.7.0 → databar-2.9.0}/tests/test_client.py +0 -0
  32. {databar-2.7.0 → databar-2.9.0}/tests/test_new_features.py +0 -0
  33. {databar-2.7.0 → databar-2.9.0}/tests/test_oauth_login.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: databar
3
- Version: 2.7.0
3
+ Version: 2.9.0
4
4
  Summary: Official Databar.ai Python SDK and CLI — connect to enrichments, waterfalls, and tables via api.databar.ai
5
5
  Author-email: "Databar.ai Team" <info@databar.ai>
6
6
  License: MIT License
@@ -264,6 +264,35 @@ client.upsert_rows(table.identifier, rows)
264
264
 
265
265
  # Delete specific rows
266
266
  client.delete_rows(table.identifier, ["row-uuid-1", "row-uuid-2"])
267
+
268
+ # Duplicate, clear, export, dedupe
269
+ copy = client.duplicate_table(table.identifier)
270
+ client.clear_table(table.identifier)
271
+ client.export_table(table.identifier, format="csv")
272
+ print(client.get_table_export(table.identifier).file)
273
+ client.dedupe_table_rows(table.identifier)
274
+ ```
275
+
276
+ ### Workbooks and trash
277
+
278
+ ```python
279
+ workbooks = client.list_workbooks()
280
+ wb = client.get_workbook(workbooks[0].identifier)
281
+ client.rename_workbook(wb.identifier, "Q4 leads")
282
+ client.add_workbook_table(wb.identifier, name="Sheet 2")
283
+ # Set the tab order: list every sheet of the workbook exactly once
284
+ sheets = client.get_workbook(wb.identifier).tables
285
+ client.reorder_workbook_tables(wb.identifier, [s.identifier for s in reversed(sheets)])
286
+ client.duplicate_workbook(wb.identifier)
287
+ client.merge_workbooks(wb.identifier, ["wb_other"])
288
+ client.move_table(table.identifier, workbook=wb.identifier)
289
+ client.move_table(table.identifier, new_workbook=True, name="Split out")
290
+ client.delete_workbook(wb.identifier)
291
+
292
+ for item in client.list_trash():
293
+ print(item.kind, item.identifier)
294
+ client.restore_trash(workbooks=[wb.identifier])
295
+ client.purge_trash(workbooks=[wb.identifier])
267
296
  ```
268
297
 
269
298
  ### Enrichments on tables
@@ -281,6 +310,12 @@ result = client.add_enrichment(
281
310
  )
282
311
  print(f"Added enrichment #{result.id}: {result.enrichment_name}")
283
312
 
313
+ client.update_enrichment(
314
+ table.identifier,
315
+ result.id,
316
+ launch_strategy="run_on_update",
317
+ )
318
+
284
319
  # Run it (run_strategy: run_all | run_empty | run_errors)
285
320
  status = client.run_table_enrichment(
286
321
  table.identifier,
@@ -518,6 +553,32 @@ databar table upsert <uuid> --key-col email --input data.csv
518
553
  databar table enrichments <uuid>
519
554
  databar table add-enrichment <uuid> --enrichment-id 123 --mapping '{"email": "email_col"}'
520
555
  databar table run-enrichment <uuid> --enrichment-id <table-enrichment-id>
556
+
557
+ # Duplicate, clear, export, dedupe
558
+ databar table duplicate <uuid>
559
+ databar table clear <uuid>
560
+ databar table export <uuid> --export-format csv
561
+ databar table get-export <uuid>
562
+ databar table dedupe <uuid>
563
+ ```
564
+
565
+ ### Workbooks and trash
566
+
567
+ ```bash
568
+ databar workbook list
569
+ databar workbook get <wb_id>
570
+ databar workbook rename <wb_id> --name "Q4 leads"
571
+ databar workbook duplicate <wb_id>
572
+ databar workbook add-table <wb_id> --name "Sheet 2"
573
+ databar workbook reorder <wb_id> --tables <uuid_1>,<uuid_2> # every sheet, once
574
+ databar workbook merge --target <wb_id> --sources <wb_a>,<wb_b>
575
+ databar table move <table-uuid> --workbook <wb_id>
576
+ databar table move <table-uuid> --new-workbook --name "Split out"
577
+ databar workbook delete <wb_id>
578
+
579
+ databar trash list
580
+ databar trash restore --workbooks <wb_id>
581
+ databar trash purge --workbooks <wb_id>
521
582
  ```
522
583
 
523
584
  ### Tasks
@@ -209,6 +209,35 @@ client.upsert_rows(table.identifier, rows)
209
209
 
210
210
  # Delete specific rows
211
211
  client.delete_rows(table.identifier, ["row-uuid-1", "row-uuid-2"])
212
+
213
+ # Duplicate, clear, export, dedupe
214
+ copy = client.duplicate_table(table.identifier)
215
+ client.clear_table(table.identifier)
216
+ client.export_table(table.identifier, format="csv")
217
+ print(client.get_table_export(table.identifier).file)
218
+ client.dedupe_table_rows(table.identifier)
219
+ ```
220
+
221
+ ### Workbooks and trash
222
+
223
+ ```python
224
+ workbooks = client.list_workbooks()
225
+ wb = client.get_workbook(workbooks[0].identifier)
226
+ client.rename_workbook(wb.identifier, "Q4 leads")
227
+ client.add_workbook_table(wb.identifier, name="Sheet 2")
228
+ # Set the tab order: list every sheet of the workbook exactly once
229
+ sheets = client.get_workbook(wb.identifier).tables
230
+ client.reorder_workbook_tables(wb.identifier, [s.identifier for s in reversed(sheets)])
231
+ client.duplicate_workbook(wb.identifier)
232
+ client.merge_workbooks(wb.identifier, ["wb_other"])
233
+ client.move_table(table.identifier, workbook=wb.identifier)
234
+ client.move_table(table.identifier, new_workbook=True, name="Split out")
235
+ client.delete_workbook(wb.identifier)
236
+
237
+ for item in client.list_trash():
238
+ print(item.kind, item.identifier)
239
+ client.restore_trash(workbooks=[wb.identifier])
240
+ client.purge_trash(workbooks=[wb.identifier])
212
241
  ```
213
242
 
214
243
  ### Enrichments on tables
@@ -226,6 +255,12 @@ result = client.add_enrichment(
226
255
  )
227
256
  print(f"Added enrichment #{result.id}: {result.enrichment_name}")
228
257
 
258
+ client.update_enrichment(
259
+ table.identifier,
260
+ result.id,
261
+ launch_strategy="run_on_update",
262
+ )
263
+
229
264
  # Run it (run_strategy: run_all | run_empty | run_errors)
230
265
  status = client.run_table_enrichment(
231
266
  table.identifier,
@@ -463,6 +498,32 @@ databar table upsert <uuid> --key-col email --input data.csv
463
498
  databar table enrichments <uuid>
464
499
  databar table add-enrichment <uuid> --enrichment-id 123 --mapping '{"email": "email_col"}'
465
500
  databar table run-enrichment <uuid> --enrichment-id <table-enrichment-id>
501
+
502
+ # Duplicate, clear, export, dedupe
503
+ databar table duplicate <uuid>
504
+ databar table clear <uuid>
505
+ databar table export <uuid> --export-format csv
506
+ databar table get-export <uuid>
507
+ databar table dedupe <uuid>
508
+ ```
509
+
510
+ ### Workbooks and trash
511
+
512
+ ```bash
513
+ databar workbook list
514
+ databar workbook get <wb_id>
515
+ databar workbook rename <wb_id> --name "Q4 leads"
516
+ databar workbook duplicate <wb_id>
517
+ databar workbook add-table <wb_id> --name "Sheet 2"
518
+ databar workbook reorder <wb_id> --tables <uuid_1>,<uuid_2> # every sheet, once
519
+ databar workbook merge --target <wb_id> --sources <wb_a>,<wb_b>
520
+ databar table move <table-uuid> --workbook <wb_id>
521
+ databar table move <table-uuid> --new-workbook --name "Split out"
522
+ databar workbook delete <wb_id>
523
+
524
+ databar trash list
525
+ databar trash restore --workbooks <wb_id>
526
+ databar trash purge --workbooks <wb_id>
466
527
  ```
467
528
 
468
529
  ### Tasks
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "databar"
7
- version = "2.7.0"
7
+ version = "2.9.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.7.0"
119
+ __version__ = "2.9.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")
@@ -12,6 +12,7 @@ CLI commands for tables and rows.
12
12
  databar table enrichments <uuid>
13
13
  databar table add-enrichment <uuid> --enrichment-id <n> --mapping '{...}'
14
14
  databar table run-enrichment <uuid> --enrichment-id <n> [--run-strategy]
15
+ databar table move <uuid> (--workbook <wb_id> | --new-workbook [--name])
15
16
  """
16
17
 
17
18
  from __future__ import annotations
@@ -386,6 +387,122 @@ def run_table_enrichment(
386
387
  output(result, OutputFormat.JSON)
387
388
 
388
389
 
390
+ @app.command("duplicate")
391
+ def duplicate_table(
392
+ table_uuid: str = _TABLE_UUID,
393
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
394
+ ) -> None:
395
+ """Duplicate a table into a new workbook."""
396
+ client = get_client()
397
+ try:
398
+ table = client.duplicate_table(table_uuid)
399
+ except DatabarError as e:
400
+ error(e)
401
+ finally:
402
+ client.close()
403
+ success(f"Duplicated as {table.identifier}")
404
+ output({"uuid": table.identifier, "name": table.name, "workbook": table.workbook}, fmt)
405
+
406
+
407
+ @app.command("clear")
408
+ def clear_table(table_uuid: str = _TABLE_UUID) -> None:
409
+ """Queue deletion of every row in the table."""
410
+ client = get_client()
411
+ try:
412
+ client.clear_table(table_uuid)
413
+ except DatabarError as e:
414
+ error(e)
415
+ finally:
416
+ client.close()
417
+ success("Clear queued.")
418
+
419
+
420
+ @app.command("export")
421
+ def export_table(
422
+ table_uuid: str = _TABLE_UUID,
423
+ format: str = typer.Option("csv", "--export-format", help="csv, xlsx, or sheets."),
424
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
425
+ ) -> None:
426
+ """Start a table export. Poll status with get-export."""
427
+ client = get_client()
428
+ try:
429
+ status = client.export_table(table_uuid, format=format)
430
+ except DatabarError as e:
431
+ error(e)
432
+ finally:
433
+ client.close()
434
+ success(f"Export queued (file_id={status.file_id})")
435
+ output(status.model_dump(), fmt)
436
+
437
+
438
+ @app.command("get-export")
439
+ def get_table_export(
440
+ table_uuid: str = _TABLE_UUID,
441
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
442
+ ) -> None:
443
+ """Check the latest export status / download URL."""
444
+ client = get_client()
445
+ try:
446
+ status = client.get_table_export(table_uuid)
447
+ except DatabarError as e:
448
+ error(e)
449
+ finally:
450
+ client.close()
451
+ output(status.model_dump(), fmt)
452
+
453
+
454
+ @app.command("dedupe")
455
+ def dedupe_table(
456
+ table_uuid: str = _TABLE_UUID,
457
+ columns: Optional[str] = typer.Option(None, "--columns", help="Comma-separated column UUIDs."),
458
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
459
+ ) -> None:
460
+ """Delete duplicate rows, keeping the oldest of each group."""
461
+ col_ids = [c.strip() for c in columns.split(",")] if columns else None
462
+ client = get_client()
463
+ try:
464
+ result = client.dedupe_table_rows(table_uuid, columns=col_ids)
465
+ except DatabarError as e:
466
+ error(e)
467
+ finally:
468
+ client.close()
469
+ success(f"Deleted {result.count_rows_delete} duplicate rows.")
470
+ output(result.model_dump(), fmt)
471
+
472
+
473
+ @app.command("move")
474
+ def move_table(
475
+ table_uuid: str = _TABLE_UUID,
476
+ workbook: Optional[str] = typer.Option(None, "--workbook", "-w", help="Target workbook id (wb_…)."),
477
+ new_workbook: bool = typer.Option(False, "--new-workbook", help="Split the sheet out into a new workbook."),
478
+ name: Optional[str] = typer.Option(
479
+ None, "--name", "-n", help="Name of the new workbook (with --new-workbook). Default: the sheet name."
480
+ ),
481
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
482
+ ) -> None:
483
+ """Move a sheet into another workbook, or split it out into a new one."""
484
+ if bool(workbook) == new_workbook:
485
+ error("Pass --workbook <wb_id> or --new-workbook, not both.")
486
+ if name is not None and not new_workbook:
487
+ error("--name names the new workbook; use it with --new-workbook.")
488
+ client = get_client()
489
+ try:
490
+ result = client.move_table(table_uuid, workbook=workbook, new_workbook=new_workbook, name=name)
491
+ except DatabarError as e:
492
+ error(e)
493
+ finally:
494
+ client.close()
495
+ target = result.get("workbook")
496
+ status = result.get("status")
497
+ if status == "unchanged":
498
+ info(f"Table is already in workbook {target}.")
499
+ elif status == "created":
500
+ success(f"Moved into new workbook {target}")
501
+ else:
502
+ success(f"Moved into workbook {target}")
503
+ output(result, fmt)
504
+
505
+
389
506
  # ---------------------------------------------------------------------------
390
507
  # Helpers
391
508
  # ---------------------------------------------------------------------------
@@ -0,0 +1,267 @@
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 workbook reorder <id> --tables uuid1,uuid2,...
12
+ databar trash list
13
+ databar trash restore --workbooks id1 [--tables uuid]
14
+ databar trash purge --workbooks id1 [--tables uuid]
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from typing import Optional
20
+
21
+ import typer
22
+
23
+ from databar.exceptions import DatabarError
24
+
25
+ from ._auth import get_client
26
+ from ._output import OutputFormat, error, info, output, success
27
+
28
+ workbook_app = typer.Typer(help="Manage workbooks (multi-sheet documents).")
29
+ trash_app = typer.Typer(help="List, restore, or permanently delete trash.")
30
+
31
+
32
+ @workbook_app.command("list")
33
+ def list_workbooks(
34
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
35
+ ) -> None:
36
+ """List workbooks in your workspace."""
37
+ client = get_client()
38
+ try:
39
+ workbooks = client.list_workbooks()
40
+ except DatabarError as e:
41
+ error(e)
42
+ finally:
43
+ client.close()
44
+
45
+ if not workbooks:
46
+ info("No workbooks found.")
47
+ output([], fmt)
48
+ return
49
+
50
+ rows = [
51
+ {
52
+ "id": w.identifier,
53
+ "name": w.name,
54
+ "tables": w.tables_count,
55
+ "updated": w.updated_at,
56
+ }
57
+ for w in workbooks
58
+ ]
59
+ output(rows, fmt, table_columns=["id", "name", "tables", "updated"])
60
+
61
+
62
+ @workbook_app.command("get")
63
+ def get_workbook(
64
+ workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
65
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
66
+ ) -> None:
67
+ """Show one workbook and its sheets."""
68
+ client = get_client()
69
+ try:
70
+ wb = client.get_workbook(workbook_id)
71
+ except DatabarError as e:
72
+ error(e)
73
+ finally:
74
+ client.close()
75
+
76
+ output(
77
+ {
78
+ "id": wb.identifier,
79
+ "name": wb.name,
80
+ "tables": [{"uuid": t.identifier, "name": t.name, "position": t.position} for t in wb.tables],
81
+ },
82
+ fmt,
83
+ )
84
+
85
+
86
+ @workbook_app.command("rename")
87
+ def rename_workbook(
88
+ workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
89
+ name: str = typer.Option(..., "--name", "-n", help="New name."),
90
+ ) -> None:
91
+ """Rename a workbook."""
92
+ client = get_client()
93
+ try:
94
+ wb = client.rename_workbook(workbook_id, name)
95
+ except DatabarError as e:
96
+ error(e)
97
+ finally:
98
+ client.close()
99
+ success(f"Renamed workbook to {wb.name!r}")
100
+
101
+
102
+ @workbook_app.command("delete")
103
+ def delete_workbook(
104
+ workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
105
+ ) -> None:
106
+ """Move a workbook to Trash."""
107
+ client = get_client()
108
+ try:
109
+ client.delete_workbook(workbook_id)
110
+ except DatabarError as e:
111
+ error(e)
112
+ finally:
113
+ client.close()
114
+ success(f"Workbook {workbook_id} moved to trash.")
115
+
116
+
117
+ @workbook_app.command("duplicate")
118
+ def duplicate_workbook(
119
+ workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
120
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
121
+ ) -> None:
122
+ """Duplicate a workbook."""
123
+ client = get_client()
124
+ try:
125
+ wb = client.duplicate_workbook(workbook_id)
126
+ except DatabarError as e:
127
+ error(e)
128
+ finally:
129
+ client.close()
130
+ success(f"Duplicated as {wb.identifier}")
131
+ output({"id": wb.identifier, "name": wb.name, "tables": wb.tables_count}, fmt)
132
+
133
+
134
+ @workbook_app.command("merge")
135
+ def merge_workbooks(
136
+ target: str = typer.Option(..., "--target", help="Workbook that keeps the sheets."),
137
+ sources: str = typer.Option(..., "--sources", help="Comma-separated workbook ids to fold in."),
138
+ ) -> None:
139
+ """Merge source workbooks into target."""
140
+ source_ids = [s.strip() for s in sources.split(",") if s.strip()]
141
+ client = get_client()
142
+ try:
143
+ wb = client.merge_workbooks(target, source_ids)
144
+ except DatabarError as e:
145
+ error(e)
146
+ finally:
147
+ client.close()
148
+ success(f"Merged into {wb.identifier} ({wb.tables_count} sheets)")
149
+
150
+
151
+ @workbook_app.command("add-table")
152
+ def add_workbook_table(
153
+ workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
154
+ name: Optional[str] = typer.Option(None, "--name", "-n", help="Sheet name."),
155
+ ) -> None:
156
+ """Add an empty sheet to a workbook."""
157
+ client = get_client()
158
+ try:
159
+ table = client.add_workbook_table(workbook_id, name=name)
160
+ except DatabarError as e:
161
+ error(e)
162
+ finally:
163
+ client.close()
164
+ success(f"Added table {table.get('identifier')}")
165
+
166
+
167
+ @workbook_app.command("reorder")
168
+ def reorder_workbook_tables(
169
+ workbook_id: str = typer.Argument(..., help="Workbook identifier (wb_…)."),
170
+ tables: str = typer.Option(
171
+ ...,
172
+ "--tables",
173
+ "-t",
174
+ help="Comma-separated table UUIDs in the new order. List every sheet of the workbook exactly once.",
175
+ ),
176
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
177
+ ) -> None:
178
+ """Set the order of a workbook's sheets (tabs)."""
179
+ table_ids = [s.strip() for s in tables.split(",") if s.strip()]
180
+ if not table_ids:
181
+ error("Pass --tables with the workbook's table UUIDs in the new order.")
182
+ if len(set(table_ids)) != len(table_ids):
183
+ error("--tables lists a table more than once; list each sheet exactly once.")
184
+ client = get_client()
185
+ try:
186
+ wb = client.reorder_workbook_tables(workbook_id, table_ids)
187
+ except DatabarError as e:
188
+ error(e)
189
+ finally:
190
+ client.close()
191
+ success(f"Reordered {len(table_ids)} sheets in {wb.identifier}")
192
+ sheets = sorted(wb.tables, key=lambda t: t.position)
193
+ output(
194
+ [{"position": t.position, "uuid": t.identifier, "name": t.name} for t in sheets],
195
+ fmt,
196
+ table_columns=["position", "uuid", "name"],
197
+ )
198
+
199
+
200
+ @trash_app.command("list")
201
+ def list_trash(
202
+ fmt: OutputFormat = typer.Option(OutputFormat.TABLE, "--format", "--output", "-f"),
203
+ ) -> None:
204
+ """List items in Trash."""
205
+ client = get_client()
206
+ try:
207
+ items = client.list_trash()
208
+ except DatabarError as e:
209
+ error(e)
210
+ finally:
211
+ client.close()
212
+
213
+ if not items:
214
+ info("Trash is empty.")
215
+ output([], fmt)
216
+ return
217
+
218
+ rows = [
219
+ {
220
+ "kind": i.kind,
221
+ "id": i.identifier,
222
+ "name": i.name,
223
+ "trashed_at": i.trashed_at,
224
+ }
225
+ for i in items
226
+ ]
227
+ output(rows, fmt, table_columns=["kind", "id", "name", "trashed_at"])
228
+
229
+
230
+ @trash_app.command("restore")
231
+ def restore_trash(
232
+ workbooks: Optional[str] = typer.Option(None, "--workbooks", help="Comma-separated workbook ids."),
233
+ tables: Optional[str] = typer.Option(None, "--tables", help="Comma-separated table UUIDs."),
234
+ ) -> None:
235
+ """Restore workbooks and/or tables from Trash."""
236
+ wb_ids = [s.strip() for s in (workbooks or "").split(",") if s.strip()]
237
+ table_ids = [s.strip() for s in (tables or "").split(",") if s.strip()]
238
+ if not wb_ids and not table_ids:
239
+ error("Pass --workbooks and/or --tables.")
240
+ client = get_client()
241
+ try:
242
+ client.restore_trash(workbooks=wb_ids, tables=table_ids)
243
+ except DatabarError as e:
244
+ error(e)
245
+ finally:
246
+ client.close()
247
+ success("Restored.")
248
+
249
+
250
+ @trash_app.command("purge")
251
+ def purge_trash(
252
+ workbooks: Optional[str] = typer.Option(None, "--workbooks", help="Comma-separated workbook ids."),
253
+ tables: Optional[str] = typer.Option(None, "--tables", help="Comma-separated table UUIDs."),
254
+ ) -> None:
255
+ """Permanently delete workbooks and/or tables from Trash."""
256
+ wb_ids = [s.strip() for s in (workbooks or "").split(",") if s.strip()]
257
+ table_ids = [s.strip() for s in (tables or "").split(",") if s.strip()]
258
+ if not wb_ids and not table_ids:
259
+ error("Pass --workbooks and/or --tables.")
260
+ client = get_client()
261
+ try:
262
+ client.purge_trash(workbooks=wb_ids, tables=table_ids)
263
+ except DatabarError as e:
264
+ error(e)
265
+ finally:
266
+ client.close()
267
+ 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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: databar
3
- Version: 2.7.0
3
+ Version: 2.9.0
4
4
  Summary: Official Databar.ai Python SDK and CLI — connect to enrichments, waterfalls, and tables via api.databar.ai
5
5
  Author-email: "Databar.ai Team" <info@databar.ai>
6
6
  License: MIT License
@@ -264,6 +264,35 @@ client.upsert_rows(table.identifier, rows)
264
264
 
265
265
  # Delete specific rows
266
266
  client.delete_rows(table.identifier, ["row-uuid-1", "row-uuid-2"])
267
+
268
+ # Duplicate, clear, export, dedupe
269
+ copy = client.duplicate_table(table.identifier)
270
+ client.clear_table(table.identifier)
271
+ client.export_table(table.identifier, format="csv")
272
+ print(client.get_table_export(table.identifier).file)
273
+ client.dedupe_table_rows(table.identifier)
274
+ ```
275
+
276
+ ### Workbooks and trash
277
+
278
+ ```python
279
+ workbooks = client.list_workbooks()
280
+ wb = client.get_workbook(workbooks[0].identifier)
281
+ client.rename_workbook(wb.identifier, "Q4 leads")
282
+ client.add_workbook_table(wb.identifier, name="Sheet 2")
283
+ # Set the tab order: list every sheet of the workbook exactly once
284
+ sheets = client.get_workbook(wb.identifier).tables
285
+ client.reorder_workbook_tables(wb.identifier, [s.identifier for s in reversed(sheets)])
286
+ client.duplicate_workbook(wb.identifier)
287
+ client.merge_workbooks(wb.identifier, ["wb_other"])
288
+ client.move_table(table.identifier, workbook=wb.identifier)
289
+ client.move_table(table.identifier, new_workbook=True, name="Split out")
290
+ client.delete_workbook(wb.identifier)
291
+
292
+ for item in client.list_trash():
293
+ print(item.kind, item.identifier)
294
+ client.restore_trash(workbooks=[wb.identifier])
295
+ client.purge_trash(workbooks=[wb.identifier])
267
296
  ```
268
297
 
269
298
  ### Enrichments on tables
@@ -281,6 +310,12 @@ result = client.add_enrichment(
281
310
  )
282
311
  print(f"Added enrichment #{result.id}: {result.enrichment_name}")
283
312
 
313
+ client.update_enrichment(
314
+ table.identifier,
315
+ result.id,
316
+ launch_strategy="run_on_update",
317
+ )
318
+
284
319
  # Run it (run_strategy: run_all | run_empty | run_errors)
285
320
  status = client.run_table_enrichment(
286
321
  table.identifier,
@@ -518,6 +553,32 @@ databar table upsert <uuid> --key-col email --input data.csv
518
553
  databar table enrichments <uuid>
519
554
  databar table add-enrichment <uuid> --enrichment-id 123 --mapping '{"email": "email_col"}'
520
555
  databar table run-enrichment <uuid> --enrichment-id <table-enrichment-id>
556
+
557
+ # Duplicate, clear, export, dedupe
558
+ databar table duplicate <uuid>
559
+ databar table clear <uuid>
560
+ databar table export <uuid> --export-format csv
561
+ databar table get-export <uuid>
562
+ databar table dedupe <uuid>
563
+ ```
564
+
565
+ ### Workbooks and trash
566
+
567
+ ```bash
568
+ databar workbook list
569
+ databar workbook get <wb_id>
570
+ databar workbook rename <wb_id> --name "Q4 leads"
571
+ databar workbook duplicate <wb_id>
572
+ databar workbook add-table <wb_id> --name "Sheet 2"
573
+ databar workbook reorder <wb_id> --tables <uuid_1>,<uuid_2> # every sheet, once
574
+ databar workbook merge --target <wb_id> --sources <wb_a>,<wb_b>
575
+ databar table move <table-uuid> --workbook <wb_id>
576
+ databar table move <table-uuid> --new-workbook --name "Split out"
577
+ databar workbook delete <wb_id>
578
+
579
+ databar trash list
580
+ databar trash restore --workbooks <wb_id>
581
+ databar trash purge --workbooks <wb_id>
521
582
  ```
522
583
 
523
584
  ### Tasks
@@ -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.7.0" in result.output
762
+ assert "2.9.0" in result.output
763
763
 
764
764
 
765
765
  def test_output_module_does_not_import_click():
@@ -767,3 +767,75 @@ def test_output_module_does_not_import_click():
767
767
  import databar.cli._output as out
768
768
 
769
769
  assert "click" not in out.__dict__
770
+
771
+
772
+ # ---------------------------------------------------------------------------
773
+ # Workbook sheets: move / reorder
774
+ # ---------------------------------------------------------------------------
775
+
776
+ OTHER_UUID = "33333333-3333-3333-3333-333333333333"
777
+
778
+
779
+ def test_table_move_to_workbook(monkeypatch):
780
+ mock = _client_mock()
781
+ mock.move_table.return_value = {"status": "moved", "workbook": "wb_target123", "table": TABLE_UUID}
782
+ monkeypatch.setattr("databar.cli.tables.get_client", lambda: mock)
783
+ result = invoke(["table", "move", TABLE_UUID, "--workbook", "wb_target123", "--format", "json"])
784
+ assert result.exit_code == 0, result.output
785
+ assert json.loads(result.output)["data"]["workbook"] == "wb_target123"
786
+ mock.move_table.assert_called_once_with(TABLE_UUID, workbook="wb_target123", new_workbook=False, name=None)
787
+
788
+
789
+ def test_table_move_to_new_workbook_with_name(monkeypatch):
790
+ mock = _client_mock()
791
+ mock.move_table.return_value = {"status": "created", "workbook": "wb_new12345", "table": TABLE_UUID}
792
+ monkeypatch.setattr("databar.cli.tables.get_client", lambda: mock)
793
+ result = invoke(["table", "move", TABLE_UUID, "--new-workbook", "--name", "Split out"])
794
+ assert result.exit_code == 0, result.output
795
+ mock.move_table.assert_called_once_with(TABLE_UUID, workbook=None, new_workbook=True, name="Split out")
796
+
797
+
798
+ @pytest.mark.parametrize(
799
+ "args",
800
+ [
801
+ [],
802
+ ["--workbook", "wb_target123", "--new-workbook"],
803
+ ["--workbook", "wb_target123", "--name", "X"],
804
+ ],
805
+ )
806
+ def test_table_move_needs_exactly_one_target(monkeypatch, args):
807
+ mock = _client_mock()
808
+ monkeypatch.setattr("databar.cli.tables.get_client", lambda: mock)
809
+ result = invoke(["table", "move", TABLE_UUID, *args])
810
+ assert result.exit_code == 2
811
+ mock.move_table.assert_not_called()
812
+
813
+
814
+ def test_workbook_reorder(monkeypatch):
815
+ from databar.models import Workbook
816
+
817
+ mock = _client_mock()
818
+ mock.reorder_workbook_tables.return_value = Workbook(
819
+ identifier="wb_abc12345",
820
+ name="Doc",
821
+ created_at="2026-10-30T00:00:00Z",
822
+ updated_at="2026-10-30T00:00:00Z",
823
+ tables=[
824
+ {"identifier": TABLE_UUID, "name": "B", "position": 1},
825
+ {"identifier": OTHER_UUID, "name": "A", "position": 0},
826
+ ],
827
+ tables_count=2,
828
+ )
829
+ monkeypatch.setattr("databar.cli.workbooks.get_client", lambda: mock)
830
+ result = invoke(["workbook", "reorder", "wb_abc12345", "--tables", f"{OTHER_UUID}, {TABLE_UUID}", "--format", "json"])
831
+ assert result.exit_code == 0, result.output
832
+ mock.reorder_workbook_tables.assert_called_once_with("wb_abc12345", [OTHER_UUID, TABLE_UUID])
833
+ assert [t["uuid"] for t in json.loads(result.output)["data"]] == [OTHER_UUID, TABLE_UUID]
834
+
835
+
836
+ def test_workbook_reorder_rejects_repeats(monkeypatch):
837
+ mock = _client_mock()
838
+ monkeypatch.setattr("databar.cli.workbooks.get_client", lambda: mock)
839
+ result = invoke(["workbook", "reorder", "wb_abc12345", "--tables", f"{TABLE_UUID},{TABLE_UUID}"])
840
+ assert result.exit_code == 2
841
+ mock.reorder_workbook_tables.assert_not_called()
@@ -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