databar 2.0.2__tar.gz → 2.0.3__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 (25) hide show
  1. {databar-2.0.2/src/databar.egg-info → databar-2.0.3}/PKG-INFO +1 -1
  2. {databar-2.0.2 → databar-2.0.3}/pyproject.toml +1 -1
  3. {databar-2.0.2 → databar-2.0.3}/src/databar/__init__.py +1 -1
  4. {databar-2.0.2 → databar-2.0.3}/src/databar/client.py +60 -4
  5. {databar-2.0.2 → databar-2.0.3/src/databar.egg-info}/PKG-INFO +1 -1
  6. {databar-2.0.2 → databar-2.0.3}/LICENSE +0 -0
  7. {databar-2.0.2 → databar-2.0.3}/README.md +0 -0
  8. {databar-2.0.2 → databar-2.0.3}/setup.cfg +0 -0
  9. {databar-2.0.2 → databar-2.0.3}/src/databar/cli/__init__.py +0 -0
  10. {databar-2.0.2 → databar-2.0.3}/src/databar/cli/_auth.py +0 -0
  11. {databar-2.0.2 → databar-2.0.3}/src/databar/cli/_output.py +0 -0
  12. {databar-2.0.2 → databar-2.0.3}/src/databar/cli/app.py +0 -0
  13. {databar-2.0.2 → databar-2.0.3}/src/databar/cli/enrichments.py +0 -0
  14. {databar-2.0.2 → databar-2.0.3}/src/databar/cli/tables.py +0 -0
  15. {databar-2.0.2 → databar-2.0.3}/src/databar/cli/tasks.py +0 -0
  16. {databar-2.0.2 → databar-2.0.3}/src/databar/cli/waterfalls.py +0 -0
  17. {databar-2.0.2 → databar-2.0.3}/src/databar/exceptions.py +0 -0
  18. {databar-2.0.2 → databar-2.0.3}/src/databar/models.py +0 -0
  19. {databar-2.0.2 → databar-2.0.3}/src/databar.egg-info/SOURCES.txt +0 -0
  20. {databar-2.0.2 → databar-2.0.3}/src/databar.egg-info/dependency_links.txt +0 -0
  21. {databar-2.0.2 → databar-2.0.3}/src/databar.egg-info/entry_points.txt +0 -0
  22. {databar-2.0.2 → databar-2.0.3}/src/databar.egg-info/requires.txt +0 -0
  23. {databar-2.0.2 → databar-2.0.3}/src/databar.egg-info/top_level.txt +0 -0
  24. {databar-2.0.2 → databar-2.0.3}/tests/test_cli.py +0 -0
  25. {databar-2.0.2 → databar-2.0.3}/tests/test_client.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: databar
3
- Version: 2.0.2
3
+ Version: 2.0.3
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "databar"
7
- version = "2.0.2"
7
+ version = "2.0.3"
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" }
@@ -57,7 +57,7 @@ from .models import (
57
57
  WaterfallEnrichment,
58
58
  )
59
59
 
60
- __version__ = "2.0.2"
60
+ __version__ = "2.0.3"
61
61
  __all__ = [
62
62
  "DatabarClient",
63
63
  # exceptions
@@ -16,6 +16,7 @@ in databar_mcp/src/databar-client.ts.
16
16
  from __future__ import annotations
17
17
 
18
18
  import os
19
+ import re
19
20
  import time
20
21
  from typing import Any, Dict, List, Optional
21
22
 
@@ -438,10 +439,65 @@ class DatabarClient:
438
439
  table_uuid: str,
439
440
  enrichment_id: int,
440
441
  mapping: Dict[str, Any],
441
- ) -> Any:
442
- """Add an enrichment to a table with a parameter-to-column mapping."""
443
- payload = {"enrichment": enrichment_id, "mapping": mapping}
444
- return self._request("POST", f"/table/{table_uuid}/add-enrichment", json=payload)
442
+ ) -> TableEnrichment:
443
+ """
444
+ Add an enrichment to a table with a parameter-to-column mapping.
445
+
446
+ ``mapping`` keys are enrichment parameter names. Values are dicts with:
447
+ - ``{"type": "mapping", "value": "<column-name-or-uuid>"}``
448
+ — reads the value from a table column per row.
449
+ You may pass a human-readable column name; the SDK will automatically
450
+ resolve it to the required column UUID via GET /table/{uuid}/columns.
451
+ - ``{"type": "simple", "value": "<static-value>"}``
452
+ — uses the same hardcoded value for every row.
453
+
454
+ Returns the newly added :class:`TableEnrichment` (with ``id`` and ``name``),
455
+ resolved by diffing enrichments before and after the add.
456
+ """
457
+ # Auto-resolve column names → UUIDs for mapping-type entries
458
+ resolved_mapping: Dict[str, Any] = {}
459
+ column_map: Optional[Dict[str, str]] = None # name → uuid, built lazily
460
+
461
+ for param, entry in mapping.items():
462
+ if not isinstance(entry, dict) or entry.get("type") != "mapping":
463
+ resolved_mapping[param] = entry
464
+ continue
465
+
466
+ value = entry.get("value", "")
467
+ # Looks like a UUID already — 8-4-4-4-12 hex pattern
468
+ if re.fullmatch(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", str(value), re.IGNORECASE):
469
+ resolved_mapping[param] = entry
470
+ continue
471
+
472
+ # Build the column name→uuid map once
473
+ if column_map is None:
474
+ columns = self.get_columns(table_uuid)
475
+ column_map = {c.name: c.identifier for c in columns}
476
+
477
+ uuid = column_map.get(value)
478
+ if uuid is None:
479
+ # Not a known column name — pass through and let the API surface the error
480
+ resolved_mapping[param] = entry
481
+ else:
482
+ resolved_mapping[param] = {**entry, "value": uuid}
483
+
484
+ # Snapshot existing enrichment IDs so we can detect the new one
485
+ before_ids = {e.id for e in self.get_table_enrichments(table_uuid)}
486
+
487
+ payload = {"enrichment": enrichment_id, "mapping": resolved_mapping}
488
+ self._request("POST", f"/table/{table_uuid}/add-enrichment", json=payload)
489
+
490
+ # Fetch updated list and return the newly created TableEnrichment
491
+ after = self.get_table_enrichments(table_uuid)
492
+ new_enrichments = [e for e in after if e.id not in before_ids]
493
+ if new_enrichments:
494
+ return new_enrichments[-1]
495
+
496
+ # Fallback: return the last enrichment in the list if we can't detect which is new
497
+ if after:
498
+ return after[-1]
499
+
500
+ raise DatabarError("Enrichment was added but could not be retrieved. Use get_table_enrichments() to fetch it manually.")
445
501
 
446
502
  def run_table_enrichment(
447
503
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: databar
3
- Version: 2.0.2
3
+ Version: 2.0.3
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes