vgi-python 0.8.6__py3-none-any.whl → 0.8.7__py3-none-any.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.
@@ -90,12 +90,14 @@ class CatalogClientMixin:
90
90
  Catalog methods spawn ephemeral connections under the hood — for
91
91
  subprocess transport a pooled subprocess worker; for HTTP transport a
92
92
  short-lived ``http_connect`` session reusing the ``Client``'s shared
93
- ``httpx.Client`` (bearer token, headers). Browsing catalogs over HTTP
94
- is the canonical non-DuckDB use case this mixin supports.
93
+ ``httpx.Client`` (bearer token, headers); for TCP transport a short-lived
94
+ ``tcp_connect`` session. Browsing catalogs over HTTP is the canonical
95
+ non-DuckDB use case this mixin supports.
95
96
 
96
- Other attributes expected from ``Client``: ``_transport`` (subprocess vs
97
- http), ``_base_url`` (HTTP base URL), and ``_get_or_create_httpx_client()``
98
- (shared HTTP client factory).
97
+ Other attributes expected from ``Client``: ``_transport`` (subprocess,
98
+ http, or tcp), ``_base_url`` (HTTP base URL), ``_tcp_host`` / ``_tcp_port``
99
+ (TCP endpoint), and ``_get_or_create_httpx_client()`` (shared HTTP client
100
+ factory).
99
101
 
100
102
  Attributes:
101
103
  server_path: Worker shell command used for subprocess transport.
@@ -103,8 +105,10 @@ class CatalogClientMixin:
103
105
 
104
106
  # Type hints for attributes expected from Client
105
107
  server_path: str
106
- _transport: Literal["subprocess", "http"]
108
+ _transport: Literal["subprocess", "http", "tcp"]
107
109
  _base_url: str | None
110
+ _tcp_host: str | None
111
+ _tcp_port: int | None
108
112
  _external_location: Any | None
109
113
 
110
114
  def _get_or_create_httpx_client(self) -> Any: # implemented by Client
@@ -128,7 +132,8 @@ class CatalogClientMixin:
128
132
  A typed `[`VgiProtocol`][]` proxy bound to the active transport.
129
133
  """
130
134
  try:
131
- if getattr(self, "_transport", "subprocess") == "http":
135
+ transport = getattr(self, "_transport", "subprocess")
136
+ if transport == "http":
132
137
  from vgi_rpc.http import http_connect
133
138
 
134
139
  httpx_client = self._get_or_create_httpx_client()
@@ -139,6 +144,17 @@ class CatalogClientMixin:
139
144
  external_location=getattr(self, "_external_location", None),
140
145
  ) as proxy:
141
146
  yield proxy
147
+ elif transport == "tcp":
148
+ from vgi_rpc.rpc import tcp_connect
149
+
150
+ assert self._tcp_host is not None and self._tcp_port is not None
151
+ with tcp_connect(
152
+ VgiProtocol, # type: ignore[type-abstract]
153
+ self._tcp_host,
154
+ self._tcp_port,
155
+ external_location=getattr(self, "_external_location", None),
156
+ ) as proxy:
157
+ yield proxy
142
158
  else:
143
159
  cmd = shlex.split(self.server_path, posix=sys.platform != "win32")
144
160
  with _catalog_pool.connect(VgiProtocol, cmd) as proxy: # type: ignore[type-abstract]
vgi/client/client.py CHANGED
@@ -197,10 +197,10 @@ _HTTP_TRANSPORT_READY = True
197
197
 
198
198
  @dataclass
199
199
  class WorkerConnection:
200
- """Holds state for a single worker connection (subprocess or HTTP).
200
+ """Holds state for a single worker connection (subprocess, HTTP, or TCP).
201
201
 
202
- Exactly one of {proc+connection, _pool_ctx, _http_ctx} is active per
203
- connection — transport-specific teardown inspects these fields.
202
+ Exactly one of {proc+connection, _pool_ctx, _http_ctx, _tcp_ctx} is active
203
+ per connection — transport-specific teardown inspects these fields.
204
204
 
205
205
  Attributes:
206
206
  proxy: The typed `[`VgiProtocol`][]` proxy used to invoke the worker.
@@ -220,6 +220,8 @@ class WorkerConnection:
220
220
  _pool_ctx: AbstractContextManager[Any] | None = field(default=None, repr=False)
221
221
  # HTTP transport: context manager from vgi_rpc.http.http_connect.
222
222
  _http_ctx: AbstractContextManager[Any] | None = field(default=None, repr=False)
223
+ # TCP transport: context manager from vgi_rpc.rpc.tcp_connect.
224
+ _tcp_ctx: AbstractContextManager[Any] | None = field(default=None, repr=False)
223
225
 
224
226
 
225
227
  class Client(CatalogClientMixin):
@@ -381,8 +383,10 @@ class Client(CatalogClientMixin):
381
383
  attach_opaque_data: bytes | None = None,
382
384
  pool: WorkerPool | None = _default_pool,
383
385
  *,
384
- transport: Literal["subprocess", "http"] = "subprocess",
386
+ transport: Literal["subprocess", "http", "tcp"] = "subprocess",
385
387
  base_url: str | None = None,
388
+ tcp_host: str | None = None,
389
+ tcp_port: int | None = None,
386
390
  bearer_token: str | None = None,
387
391
  httpx_client: Any | None = None,
388
392
  external_location: Any | None = None,
@@ -413,9 +417,14 @@ class Client(CatalogClientMixin):
413
417
  management.
414
418
  transport: Which transport to use. ``"subprocess"`` (default)
415
419
  spawns a local subprocess per worker; ``"http"`` connects to
416
- a running worker via ``vgi_rpc.http.http_connect``.
420
+ a running worker via ``vgi_rpc.http.http_connect``; ``"tcp"``
421
+ connects to a running worker via ``vgi_rpc.rpc.tcp_connect``
422
+ (raw Arrow-IPC framing, no auth/encryption — loopback /
423
+ trusted networks only; use ``Client.from_tcp(...)``).
417
424
  base_url: HTTP-only. Base URL of the running worker, e.g.
418
425
  ``"http://127.0.0.1:8765"``.
426
+ tcp_host: TCP-only. Hostname or IP of the running worker.
427
+ tcp_port: TCP-only. Port of the running worker.
419
428
  bearer_token: HTTP-only. When set, every request carries an
420
429
  ``Authorization: Bearer <token>`` header. Static token
421
430
  support only — no JWT / OAuth flows.
@@ -446,12 +455,21 @@ class Client(CatalogClientMixin):
446
455
  raise ValueError("transport='http' requires base_url")
447
456
  if server_path is not None:
448
457
  raise ValueError("server_path is only meaningful for transport='subprocess'")
458
+ elif transport == "tcp":
459
+ if tcp_host is None or tcp_port is None:
460
+ raise ValueError("transport='tcp' requires tcp_host and tcp_port")
461
+ if server_path is not None:
462
+ raise ValueError("server_path is only meaningful for transport='subprocess'")
463
+ if base_url is not None:
464
+ raise ValueError("base_url is only meaningful for transport='http'")
449
465
  else:
450
466
  raise ValueError(f"unknown transport {transport!r}")
451
467
 
452
468
  self.server_path = server_path or ""
453
469
  self._transport = transport
454
470
  self._base_url = base_url
471
+ self._tcp_host = tcp_host
472
+ self._tcp_port = tcp_port
455
473
  self._bearer_token = bearer_token
456
474
  self._httpx_client = httpx_client
457
475
  # True when ``_get_or_create_httpx_client`` constructed the client and
@@ -460,7 +478,7 @@ class Client(CatalogClientMixin):
460
478
  self._httpx_client_owned = False
461
479
  # Auto-enable pointer-batch resolution for HTTP unless the caller
462
480
  # asked for something different. See ``external_location`` docs above.
463
- if transport == "http" and external_location is None:
481
+ if transport in ("http", "tcp") and external_location is None:
464
482
  from vgi_rpc.external import ExternalLocationConfig
465
483
 
466
484
  external_location = ExternalLocationConfig()
@@ -509,6 +527,34 @@ class Client(CatalogClientMixin):
509
527
  pool=None,
510
528
  )
511
529
 
530
+ @classmethod
531
+ def from_tcp(
532
+ cls,
533
+ host: str,
534
+ port: int,
535
+ *,
536
+ external_location: Any | None = None,
537
+ worker_limit: int | None = None,
538
+ attach_opaque_data: bytes | None = None,
539
+ ) -> Client:
540
+ """Create a `[`Client`][]` bound to a running TCP VGI worker.
541
+
542
+ Connects via ``vgi_rpc.rpc.tcp_connect`` (raw Arrow-IPC framing). The
543
+ framing carries **no authentication or encryption** — only connect to
544
+ trusted endpoints on loopback or a trusted network; use
545
+ ``Client.from_http(...)`` for untrusted networks. Spin up a matching
546
+ worker with ``vgi-fixture-worker --tcp [HOST:]PORT``.
547
+ """
548
+ return cls(
549
+ transport="tcp",
550
+ tcp_host=host,
551
+ tcp_port=port,
552
+ external_location=external_location,
553
+ worker_limit=worker_limit,
554
+ attach_opaque_data=attach_opaque_data,
555
+ pool=None,
556
+ )
557
+
512
558
  def _drain_stderr(self, stderr: IO[bytes]) -> None:
513
559
  """Background thread that continuously reads stderr.
514
560
 
@@ -577,8 +623,40 @@ class Client(CatalogClientMixin):
577
623
  """
578
624
  if self._transport == "http":
579
625
  return self._spawn_http_connection(worker_index)
626
+ if self._transport == "tcp":
627
+ return self._spawn_tcp_connection(worker_index)
580
628
  return self._spawn_subprocess_connection(worker_index)
581
629
 
630
+ def _spawn_tcp_connection(self, worker_index: int) -> WorkerConnection:
631
+ """Connect to a running TCP worker via ``vgi_rpc.rpc.tcp_connect``.
632
+
633
+ Raw Arrow-IPC framing with no auth/encryption — see ``from_tcp``.
634
+ Multiple ``worker_index`` values open independent TCP connections to
635
+ the same ``host:port``.
636
+ """
637
+ from vgi_rpc.rpc import tcp_connect
638
+
639
+ assert self._tcp_host is not None and self._tcp_port is not None # enforced in __init__
640
+ ctx: AbstractContextManager[VgiProtocol] = tcp_connect(
641
+ VgiProtocol, # type: ignore[type-abstract]
642
+ self._tcp_host,
643
+ self._tcp_port,
644
+ on_log=self._on_worker_log,
645
+ external_location=self._external_location,
646
+ )
647
+ proxy = ctx.__enter__()
648
+ _logger.debug(
649
+ "tcp_connection_opened worker_index=%s host=%s port=%s",
650
+ worker_index,
651
+ self._tcp_host,
652
+ self._tcp_port,
653
+ )
654
+ return WorkerConnection(
655
+ proxy=proxy,
656
+ worker_index=worker_index,
657
+ _tcp_ctx=ctx,
658
+ )
659
+
582
660
  def _spawn_http_connection(self, worker_index: int) -> WorkerConnection:
583
661
  """Connect to a remote HTTP worker via ``vgi_rpc.http.http_connect``.
584
662
 
@@ -724,6 +802,12 @@ class Client(CatalogClientMixin):
724
802
  _logger.debug("http_connection_closed worker_index=%s", worker.worker_index)
725
803
  return 0
726
804
 
805
+ if worker._tcp_ctx is not None:
806
+ # TCP transport — close the RPC proxy (and its socket).
807
+ worker._tcp_ctx.__exit__(None, None, None)
808
+ _logger.debug("tcp_connection_closed worker_index=%s", worker.worker_index)
809
+ return 0
810
+
727
811
  if worker._pool_ctx is not None:
728
812
  # Return to pool — pool handles subprocess lifecycle
729
813
  worker._pool_ctx.__exit__(None, None, None)
@@ -805,6 +889,8 @@ class Client(CatalogClientMixin):
805
889
  id_repr: Any = self._primary.proc.pid
806
890
  elif self._primary._http_ctx is not None:
807
891
  id_repr = f"http({self._base_url})"
892
+ elif self._primary._tcp_ctx is not None:
893
+ id_repr = f"tcp({self._tcp_host}:{self._tcp_port})"
808
894
  else:
809
895
  id_repr = "pooled"
810
896
  _logger.debug("server_started id=%s", id_repr)
vgi/worker.py CHANGED
@@ -1276,10 +1276,25 @@ class Worker:
1276
1276
  "--unix",
1277
1277
  help="Bind to this AF_UNIX socket path instead of stdin/stdout (mutex with --http).",
1278
1278
  ),
1279
+ # TCP launcher contract — mutually exclusive with --http/--unix.
1280
+ # Accepts ``[HOST:]PORT``; host defaults to loopback (127.0.0.1)
1281
+ # and ``PORT`` may be 0 to auto-select a free port. After binding
1282
+ # the worker prints TCP:<host>:<port> to stdout and self-shuts-down
1283
+ # after --idle-timeout seconds with zero connected clients. The raw
1284
+ # framing carries no auth/encryption — bind loopback only; use
1285
+ # --http for untrusted networks.
1286
+ tcp: str | None = typer.Option(
1287
+ None,
1288
+ "--tcp",
1289
+ help=(
1290
+ "Bind a TCP socket ([HOST:]PORT, host defaults to 127.0.0.1, PORT 0 "
1291
+ "auto-selects) instead of stdin/stdout (mutex with --http/--unix)."
1292
+ ),
1293
+ ),
1279
1294
  idle_timeout: float = typer.Option(
1280
1295
  300.0,
1281
1296
  "--idle-timeout",
1282
- help="Self-shutdown after N seconds idle when serving --unix.",
1297
+ help="Self-shutdown after N seconds idle when serving --unix/--tcp.",
1283
1298
  ),
1284
1299
  http_threads: int | None = typer.Option( # noqa: B008
1285
1300
  None,
@@ -1300,8 +1315,8 @@ class Worker:
1300
1315
  log_format=log_format,
1301
1316
  )
1302
1317
 
1303
- if http and unix is not None:
1304
- raise typer.BadParameter("--http and --unix are mutually exclusive")
1318
+ if sum(x for x in (http, unix is not None, tcp is not None)) > 1:
1319
+ raise typer.BadParameter("--http, --unix, and --tcp are mutually exclusive")
1305
1320
 
1306
1321
  if http:
1307
1322
  from vgi.serve import (
@@ -1358,6 +1373,47 @@ class Worker:
1358
1373
  idle_timeout=effective_idle,
1359
1374
  on_bound=_emit,
1360
1375
  )
1376
+ elif tcp is not None:
1377
+ # TCP launcher path. Bind to [HOST:]PORT, print
1378
+ # TCP:<host>:<port> on stdout (mirrors run_server's
1379
+ # cross-language discovery contract), idle-shutdown after
1380
+ # idle_timeout seconds.
1381
+ from vgi_rpc.rpc import serve_tcp
1382
+
1383
+ from vgi.serve import _maybe_init_sentry, _resolve_otel_config
1384
+
1385
+ if ":" in tcp:
1386
+ host_part, _, port_part = tcp.rpartition(":")
1387
+ tcp_host = host_part or "127.0.0.1"
1388
+ else:
1389
+ tcp_host, port_part = "127.0.0.1", tcp
1390
+ try:
1391
+ tcp_port = int(port_part)
1392
+ except ValueError:
1393
+ raise typer.BadParameter(f"--tcp expects [HOST:]PORT, got {tcp!r}") from None
1394
+
1395
+ _maybe_init_sentry()
1396
+ otel_config = _resolve_otel_config()
1397
+ worker = cls(quiet=quiet, log_level=effective_level)
1398
+ server = RpcServer(cls.protocol_class, worker, server_version=_get_vgi_version())
1399
+ if otel_config is not None:
1400
+ from vgi_rpc.otel import instrument_server
1401
+
1402
+ instrument_server(server, otel_config)
1403
+ worker._vgi_tracer = VgiTracer.create(otel_config)
1404
+ effective_idle = idle_timeout if idle_timeout > 0 else None
1405
+
1406
+ def _emit_tcp(bound_host: str, bound_port: int) -> None:
1407
+ print(f"TCP:{bound_host}:{bound_port}", flush=True)
1408
+
1409
+ serve_tcp(
1410
+ server,
1411
+ tcp_host,
1412
+ tcp_port,
1413
+ threaded=True,
1414
+ idle_timeout=effective_idle,
1415
+ on_bound=_emit_tcp,
1416
+ )
1361
1417
  else:
1362
1418
  from vgi.serve import _maybe_init_sentry, _resolve_otel_config
1363
1419
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vgi-python
3
- Version: 0.8.6
3
+ Version: 0.8.7
4
4
  Summary: Vector Gateway Interface - Connect DuckDB to external programs via Apache Arrow
5
5
  Project-URL: Homepage, https://query.farm
6
6
  Project-URL: Repository, https://github.com/Query-farm/vgi-python
@@ -162,7 +162,7 @@ Requires-Dist: httpx>=0.24
162
162
  Requires-Dist: platformdirs
163
163
  Requires-Dist: pyarrow
164
164
  Requires-Dist: typer>=0.9
165
- Requires-Dist: vgi-rpc>=0.20.5
165
+ Requires-Dist: vgi-rpc>=0.21.0
166
166
  Provides-Extra: azure
167
167
  Requires-Dist: azure-identity>=1.16.0; extra == 'azure'
168
168
  Requires-Dist: pymssql>=2.3.0; extra == 'azure'
@@ -27,7 +27,7 @@ vgi/table_buffering_function.py,sha256=O5TcIdqk8-YViCQCkb8bOevO-zhe3IoyzLgwXDO3C
27
27
  vgi/table_filter_pushdown.py,sha256=zak3AuXLVw51vXew93i81fRReG1H8yr4XxCfRnnISj4,63961
28
28
  vgi/table_function.py,sha256=_Ni1deyPaabnQJDQz9CUL4fXy79r_OVyN6ZuWTZ1lMQ,52215
29
29
  vgi/table_in_out_function.py,sha256=Ouv02ubP-XsRdByIR0ZSagi6VbZfQ8G1e5QWpqlLqvY,15508
30
- vgi/worker.py,sha256=zrAk_ac_SFMLO0pTZajOrYevAYTGr5opkAV_BtF9CT0,195873
30
+ vgi/worker.py,sha256=t5OKx5mGU91zeV6ErOifeTQmOw16fTOc18jOSDbTDaA,198588
31
31
  vgi/_test_fixtures/__init__.py,sha256=xQq-QQLk8USQ6TZHsPiPcZldNNUdcJ2gToXMPGzScLI,444
32
32
  vgi/_test_fixtures/attach_options.py,sha256=YtNk1krDdKLnNVtX9yGkgS8XyzdOI0oXtNDbAV73Phg,11091
33
33
  vgi/_test_fixtures/bad_enum.py,sha256=lIVemVWTM1JVOHut47Q71Czw-sEiMjfFiyZ15NDaWAk,2910
@@ -105,7 +105,7 @@ vgi/catalog/secret_type.py,sha256=MKtAypBa3xXyr-NC5CHjdX1R00JEnuMtvgboFWC2T9o,33
105
105
  vgi/catalog/setting.py,sha256=06QfgaAR-0BKflIJ0du6PGqA5BPMdrkwr6u7f4nddII,1846
106
106
  vgi/catalog/storage.py,sha256=DhngzywbhQUfLF7NjFyiPp4Sw2ovOhcUXAuW3rkBQD8,11935
107
107
  vgi/client/__init__.py,sha256=6LPHqlcNFy77apDNXUntgOVLhuXfpJyZd6TI7R7QfbY,2122
108
- vgi/client/catalog_mixin.py,sha256=0EL7eY6DYkqIq_zWWjcEH7xCyNkEyxaoygMW0ehsvEY,45908
108
+ vgi/client/catalog_mixin.py,sha256=fH_D756rzQZHi6UKbeVbWCIScVUqcGw8Dfp8nD36dao,46600
109
109
  vgi/client/cli.py,sha256=KfoqIiMXiUNAdYxRp-O6BOi3FA1IsesSBb_XeZGWFSo,22287
110
110
  vgi/client/cli_catalog.py,sha256=twjlhHGl7n2mNN4jc7DnDRQr-Zj9KLAF2eATIQnITHQ,5577
111
111
  vgi/client/cli_schema.py,sha256=FTkf1moDn_dWFMPDxJqaNFhc2oyrLEutP8xC60EbPIk,7556
@@ -113,7 +113,7 @@ vgi/client/cli_table.py,sha256=hxASTkLZy69z4qoYhpIqrV9ZmZdPLKIzhmHy-hB9qqE,26145
113
113
  vgi/client/cli_transaction.py,sha256=TDW0ZrBy8XM_eYSkYk5ewEsnozfzDJOlopd66Fm7OOE,3142
114
114
  vgi/client/cli_utils.py,sha256=kilyfxRgFdW63IYQU6xsVls1wIcRjR-ZP63qu0FdXLI,16223
115
115
  vgi/client/cli_view.py,sha256=p2wiJAuaEv-8qEgWxiNKgzA9qLdYZ87XCJwkxx5c-YU,8353
116
- vgi/client/client.py,sha256=M-P3v1Xi5aroTl7Zdtx_tdMT4VjWhTZKiqAog9BDsb4,93582
116
+ vgi/client/client.py,sha256=Pb5qLfydDEnrTW-yCUDSGkerGJesCeHQQbFNTZpxN24,97270
117
117
  vgi/http/__init__.py,sha256=hlOwOVcoZqmEKVGk7ganOdr5ryRSpEhLBF9sRD7BkYc,608
118
118
  vgi/http/demo_storage.py,sha256=830s-H61thozC3eEuqdnwCpYFfvoJRq9vjyuXa5OURo,8769
119
119
  vgi/http/worker_page.py,sha256=Eq70-hPfG2PIuhFjEDMf-BxF7Fdjcb4dN2SploH2jWE,54577
@@ -122,8 +122,8 @@ vgi/transactor/_duckdb_compat.py,sha256=sXVZ9JLKAQyGR1BjWczSwdQEavtr-TcZPoVZZnTr
122
122
  vgi/transactor/client.py,sha256=7DTeMksogsw6ANjQjGOPpKYrV76rg4_kGjktMJf54jg,4486
123
123
  vgi/transactor/protocol.py,sha256=Mtmll3CdrLFL1B4NY4NZUTO_yi3PT0qhvMQnzapuBWU,4780
124
124
  vgi/transactor/server.py,sha256=WpIqjzy2Mebw17Jui4-w7vyGEo9pD-pEZJG-3Ob1Sk8,29705
125
- vgi_python-0.8.6.dist-info/METADATA,sha256=b59V9U4mHNCh4vgMDP_4iOEGPAa6eCisvaxwNhrtC4s,24725
126
- vgi_python-0.8.6.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
127
- vgi_python-0.8.6.dist-info/entry_points.txt,sha256=3Kz1vgodw3pOL_xjtSyDB55-ZRy-U2X-X_Bdr582x0Q,165
128
- vgi_python-0.8.6.dist-info/licenses/LICENSE,sha256=pbJb4zZasP6n5ifEV81wFu017TarjydaYVmGbHcehtY,6103
129
- vgi_python-0.8.6.dist-info/RECORD,,
125
+ vgi_python-0.8.7.dist-info/METADATA,sha256=tNHKhPZbF3jkRYNokolq5dGV1pj1iLcqN2AedbfdK2I,24725
126
+ vgi_python-0.8.7.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
127
+ vgi_python-0.8.7.dist-info/entry_points.txt,sha256=3Kz1vgodw3pOL_xjtSyDB55-ZRy-U2X-X_Bdr582x0Q,165
128
+ vgi_python-0.8.7.dist-info/licenses/LICENSE,sha256=pbJb4zZasP6n5ifEV81wFu017TarjydaYVmGbHcehtY,6103
129
+ vgi_python-0.8.7.dist-info/RECORD,,