cocoindex 0.1.82__cp311-cp311-win_amd64.whl → 0.1.83__cp311-cp311-win_amd64.whl

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.
Binary file
cocoindex/flow.py CHANGED
@@ -105,18 +105,26 @@ def _spec_kind(spec: Any) -> str:
105
105
 
106
106
  def _transform_helper(
107
107
  flow_builder_state: _FlowBuilderState,
108
- fn_spec: FunctionSpec,
108
+ fn_spec: FunctionSpec | Callable[..., Any],
109
109
  transform_args: list[tuple[Any, str | None]],
110
110
  name: str | None = None,
111
111
  ) -> DataSlice[Any]:
112
- if not isinstance(fn_spec, FunctionSpec):
112
+ if isinstance(fn_spec, FunctionSpec):
113
+ kind = _spec_kind(fn_spec)
114
+ spec = fn_spec
115
+ elif callable(fn_spec) and (
116
+ op_kind := getattr(fn_spec, "__cocoindex_op_kind__", None)
117
+ ):
118
+ kind = op_kind
119
+ spec = op.EmptyFunctionSpec()
120
+ else:
113
121
  raise ValueError("transform() can only be called on a CocoIndex function")
114
122
 
115
123
  return _create_data_slice(
116
124
  flow_builder_state,
117
125
  lambda target_scope, name: flow_builder_state.engine_flow_builder.transform(
118
- _spec_kind(fn_spec),
119
- dump_engine_object(fn_spec),
126
+ kind,
127
+ dump_engine_object(spec),
120
128
  transform_args,
121
129
  target_scope,
122
130
  flow_builder_state.field_name_builder.build_name(
@@ -245,7 +253,7 @@ class DataSlice(Generic[T]):
245
253
  f(scope)
246
254
 
247
255
  def transform(
248
- self, fn_spec: op.FunctionSpec, *args: Any, **kwargs: Any
256
+ self, fn_spec: op.FunctionSpec | Callable[..., Any], *args: Any, **kwargs: Any
249
257
  ) -> DataSlice[Any]:
250
258
  """
251
259
  Apply a function to the data slice.
@@ -513,7 +521,7 @@ class FlowBuilder:
513
521
  )
514
522
 
515
523
  def transform(
516
- self, fn_spec: FunctionSpec, *args: Any, **kwargs: Any
524
+ self, fn_spec: FunctionSpec | Callable[..., Any], *args: Any, **kwargs: Any
517
525
  ) -> DataSlice[Any]:
518
526
  """
519
527
  Apply a function to inputs, returning a DataSlice.
cocoindex/op.py CHANGED
@@ -388,53 +388,39 @@ def executor_class(**args: Any) -> Callable[[type], type]:
388
388
  return _inner
389
389
 
390
390
 
391
- class _EmptyFunctionSpec(FunctionSpec):
391
+ class EmptyFunctionSpec(FunctionSpec):
392
392
  pass
393
393
 
394
394
 
395
395
  class _SimpleFunctionExecutor:
396
- spec: Any
396
+ spec: Callable[..., Any]
397
397
 
398
398
  def prepare(self) -> None:
399
- self.__call__ = self.spec.__call__
399
+ self.__call__ = staticmethod(self.spec)
400
400
 
401
401
 
402
- def function(**args: Any) -> Callable[[Callable[..., Any]], FunctionSpec]:
402
+ def function(**args: Any) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
403
403
  """
404
404
  Decorate a function to provide a function for an op.
405
405
  """
406
406
  op_args = OpArgs(**args)
407
407
 
408
- def _inner(fn: Callable[..., Any]) -> FunctionSpec:
408
+ def _inner(fn: Callable[..., Any]) -> Callable[..., Any]:
409
409
  # Convert snake case to camel case.
410
- op_name = "".join(word.capitalize() for word in fn.__name__.split("_"))
410
+ op_kind = "".join(word.capitalize() for word in fn.__name__.split("_"))
411
411
  sig = inspect.signature(fn)
412
- full_name = f"{fn.__module__}.{fn.__qualname__}"
413
-
414
- # An object that is both callable and can act as a FunctionSpec.
415
- class _CallableSpec(_EmptyFunctionSpec):
416
- __call__ = staticmethod(fn)
417
-
418
- def __reduce__(self) -> str | tuple[Any, ...]:
419
- return full_name
420
-
421
- _CallableSpec.__name__ = op_name
422
- _CallableSpec.__doc__ = fn.__doc__
423
- _CallableSpec.__qualname__ = fn.__qualname__
424
- _CallableSpec.__module__ = fn.__module__
425
- callable_spec = _CallableSpec()
426
-
412
+ fn.__cocoindex_op_kind__ = op_kind # type: ignore
427
413
  _register_op_factory(
428
414
  category=OpCategory.FUNCTION,
429
415
  expected_args=list(sig.parameters.items()),
430
416
  expected_return=sig.return_annotation,
431
417
  executor_factory=_SimpleFunctionExecutor,
432
- spec_loader=lambda: callable_spec,
433
- op_kind=op_name,
418
+ spec_loader=lambda: fn,
419
+ op_kind=op_kind,
434
420
  op_args=op_args,
435
421
  )
436
422
 
437
- return callable_spec
423
+ return fn
438
424
 
439
425
  return _inner
440
426
 
cocoindex/sources.py CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  from . import op
4
4
  from .auth_registry import TransientAuthEntryReference
5
+ from .setting import DatabaseConnectionSpec
5
6
  import datetime
6
7
 
7
8
 
@@ -67,3 +68,22 @@ class AzureBlob(op.SourceSpec):
67
68
 
68
69
  sas_token: TransientAuthEntryReference[str] | None = None
69
70
  account_access_key: TransientAuthEntryReference[str] | None = None
71
+
72
+
73
+ class Postgres(op.SourceSpec):
74
+ """Import data from a PostgreSQL table."""
75
+
76
+ _op_category = op.OpCategory.SOURCE
77
+
78
+ # Table name to read from (required)
79
+ table_name: str
80
+
81
+ # Database connection reference (optional - uses default if not provided)
82
+ database: TransientAuthEntryReference[DatabaseConnectionSpec] | None = None
83
+
84
+ # Optional: specific columns to include (if None, includes all columns)
85
+ included_columns: list[str] | None = None
86
+
87
+ # Optional: column name to use for ordinal tracking (for incremental updates)
88
+ # Should be a timestamp, serial, or other incrementing column
89
+ ordinal_column: str | None = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cocoindex
3
- Version: 0.1.82
3
+ Version: 0.1.83
4
4
  Requires-Dist: click>=8.1.8
5
5
  Requires-Dist: rich>=14.0.0
6
6
  Requires-Dist: python-dotenv>=1.1.0
@@ -1,23 +1,23 @@
1
- cocoindex-0.1.82.dist-info/METADATA,sha256=Wsdop0-iOt3GkpwMxty-ugwIrha5QEZ0SC8YKK-lp6o,12404
2
- cocoindex-0.1.82.dist-info/WHEEL,sha256=Ncll1xfKuKRSH9zs2vSEuHQoNZLcJWpzadJbiEni0qk,96
3
- cocoindex-0.1.82.dist-info/entry_points.txt,sha256=_NretjYVzBdNTn7dK-zgwr7YfG2afz1u1uSE-5bZXF8,46
4
- cocoindex-0.1.82.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
1
+ cocoindex-0.1.83.dist-info/METADATA,sha256=hdRQSWNsnB6dUFa1F8ikl2fE9dnIVNv288ldby5XbNU,12404
2
+ cocoindex-0.1.83.dist-info/WHEEL,sha256=Ncll1xfKuKRSH9zs2vSEuHQoNZLcJWpzadJbiEni0qk,96
3
+ cocoindex-0.1.83.dist-info/entry_points.txt,sha256=_NretjYVzBdNTn7dK-zgwr7YfG2afz1u1uSE-5bZXF8,46
4
+ cocoindex-0.1.83.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
5
5
  cocoindex/__init__.py,sha256=5zwuS_X-n7QAE5uBSufqXp77OW8KVVD8E5t_6koDLRc,2293
6
- cocoindex/_engine.cp311-win_amd64.pyd,sha256=AQj00N1QLJKKylTdrHowJV2180GRr7SYkbTHznHnneQ,71394816
6
+ cocoindex/_engine.cp311-win_amd64.pyd,sha256=HHuen2QVc-Hcc41yMyqwiW-tqYtzPDojLYYr3rlfCHY,71555584
7
7
  cocoindex/auth_registry.py,sha256=Qq1IVZb-7K4luRrQSDlOPbISnGEZ4kIDsrCU8H2ARw0,1529
8
8
  cocoindex/cli.py,sha256=VgeVgO5z2l6tv7XWS3q-sRZ8cYe9r7izUYUR3NfdgJA,21372
9
9
  cocoindex/convert.py,sha256=IqrOswncP99pOYecCtOKpp1pQEQHyxE13KKfLGSN9ZQ,22066
10
- cocoindex/flow.py,sha256=2GRqGPLGMUJF8JLiuvA_CpGtoBFpCY1gqJ7aMrU2w9w,37155
10
+ cocoindex/flow.py,sha256=6AadyuaQsujkjV1zcXM-DiYr29uVdGXII4tIuNGDo_k,37440
11
11
  cocoindex/functions.py,sha256=CtiwTVW6g4BtO5_EvVcij7Si4Bx-axnM1hsdU43aM4g,12617
12
12
  cocoindex/index.py,sha256=GrqTm1rLwICQ8hadtNvJAxVg7GWMvtMmFcbiNtNzmP0,569
13
13
  cocoindex/lib.py,sha256=cZosix4nwROvod4QJOwCzrm6U1CVy_wKMMk7sDDG_Z0,849
14
14
  cocoindex/llm.py,sha256=JM5EPup7FZojynCI0rg4gnMBYmdPZpaHJbVBz3f7BAI,897
15
- cocoindex/op.py,sha256=7NQNc7CNleDrVz1wq0DLRaiWxj4Sz80QG8NG8qvPhs0,23371
15
+ cocoindex/op.py,sha256=1uOwE1zzMs7FrMSpQMJPUI8YtnXXk3-tlEJ_ahPFq5A,22884
16
16
  cocoindex/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  cocoindex/runtime.py,sha256=6mE-jR1Kh5c4GETDvBgwjXZq69TK5rh1qNpaseRDZnw,1117
18
18
  cocoindex/setting.py,sha256=048VfKRly9TzLElJlL01tUxySGtRbsc9m68yIHvMzMU,5464
19
19
  cocoindex/setup.py,sha256=KbJvmeFu0NbeoH-5iDmHZP86f26HIId8kHmGUNZAePI,3160
20
- cocoindex/sources.py,sha256=DEEfJGrz0eG9dFF-sjn7ddbebHfqPpbyN5KXYagbZ50,2152
20
+ cocoindex/sources.py,sha256=mVZhyVTyHzFy7z3lceYqgguygADQkIL42nYK6zKSKKQ,2868
21
21
  cocoindex/subprocess_exec.py,sha256=KDV7xdFUhKYqHZdiJqirNTl7DbJQUXLvga0Q1urE6XA,8143
22
22
  cocoindex/targets.py,sha256=7FfG9kuEf5KTXtLwXMFaPFIut3PsIbpb3XIEjjeF7Bg,2931
23
23
  cocoindex/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -30,4 +30,4 @@ cocoindex/typing.py,sha256=gMNJIpGGe-SiXlihDQ-Dw2YdebQvOyG-bWovR-veO6g,13817
30
30
  cocoindex/user_app_loader.py,sha256=jKNyCq5Osl4dMevlDNloGuwCfDscxw5o0m9_OqrHDN8,1965
31
31
  cocoindex/utils.py,sha256=U3W39zD2uZpXX8v84tJD7sRmbC5ar3z_ljAP1cJrYXI,618
32
32
  cocoindex/validation.py,sha256=4ZjsW-SZT8X_TEEhEE6QG6D-8Oq_TkPAhTqP0mdFYSE,3194
33
- cocoindex-0.1.82.dist-info/RECORD,,
33
+ cocoindex-0.1.83.dist-info/RECORD,,