@@ -99,7 +99,14 @@ singlestoredb/
9999│ ├── mmap.py # Memory-mapped execution
100100│ ├── json.py # JSON serialization
101101│ ├── rowdat_1.py # ROWDAT_1 format
102- │ └── arrow.py # Apache Arrow format
102+ │ ├── arrow.py # Apache Arrow format
103+ │ └── plugin/ # Plugin UDF server (Unix socket)
104+ │ ├── __main__.py # CLI entry point
105+ │ ├── server.py # Socket server with thread/process pool
106+ │ ├── connection.py # Connection handling
107+ │ ├── control.py # Control protocol
108+ │ ├── registry.py # Function registry & discovery
109+ │ └── wasm.py # WASM component interface
103110│
104111├── ai/ # AI/ML integration
105112│ ├── chat.py # Chat completion factory
@@ -603,9 +610,9 @@ Located in `singlestoredb/fusion/handlers/`:
603610## External Functions (UDFs)
604611
605612The functions module (` singlestoredb/functions/ ` ) enables deploying Python functions
606- as SingleStore external functions. UDF servers can be deployed as HTTP using
607- an ASGI application or a collocated socket server that uses mmap files to
608- transfer data .
613+ as SingleStore external functions. UDF servers can be deployed in three modes: as HTTP using an ASGI application
614+ (remote), a memory-mapped collocated server (lowest latency), or as a plugin
615+ server using Unix sockets with a thread/process pool (CLI-driven) .
609616
610617### Architecture
611618
@@ -629,6 +636,7 @@ transfer data.
629636├─────────────────────────────────────────────────────────────────────┤
630637│ asgi.py │ HTTP server via ASGI (Uvicorn; JSON or ROWDAT_1) │
631638│ mmap.py │ Memory-mapped shared memory (collocated; ROWDAT_1) │
639+ │ plugin/ │ Plugin UDF server (Unix socket + thread/process pool) │
632640│ json.py │ JSON serialization over HTTP │
633641│ rowdat_1.py│ ROWDAT_1 binary format │
634642│ arrow.py │ Apache Arrow columnar format │
@@ -659,6 +667,33 @@ python -m singlestoredb.functions.ext.asgi \
659667 my_functions
660668```
661669
670+ ### Plugin Server CLI
671+
672+ The plugin server can be launched via the CLI for Unix socket-based UDF serving:
673+
674+ ``` bash
675+ # Launch the plugin server
676+ python -m singlestoredb.functions.ext.plugin \
677+ --plugin-name myfuncs \
678+ --search-path /home/user/libs \
679+ --socket /tmp/my-udf.sock
680+
681+ # Or use the console_scripts entry point
682+ python-udf-server --plugin-name myfuncs
683+ ```
684+
685+ ** CLI Arguments:**
686+
687+ | Argument | Env Variable | Default | Description |
688+ | ----------| -------------| ---------| -------------|
689+ | ` --plugin-name ` | ` PLUGIN_NAME ` | (required) | Python module to import |
690+ | ` --search-path ` | ` PLUGIN_SEARCH_PATH ` | ` "" ` | Colon-separated search dirs for the module |
691+ | ` --socket ` | ` PLUGIN_SOCKET_PATH ` | auto-generated | Unix socket path |
692+ | ` --n-workers ` | ` PLUGIN_N_WORKERS ` | ` 0 ` (CPU count) | Worker threads/processes |
693+ | ` --max-connections ` | ` PLUGIN_MAX_CONNECTIONS ` | ` 32 ` | Socket backlog |
694+ | ` --log-level ` | ` PLUGIN_LOG_LEVEL ` | ` info ` | Logging level (debug/info/warning/error) |
695+ | ` --process-mode ` | ` PLUGIN_PROCESS_MODE ` | ` process ` | Concurrency mode: ` thread ` or ` process ` |
696+
662697### Type Mapping
663698
664699The ` signature.py ` module maps Python types to SQL types:
@@ -682,29 +717,30 @@ The `signature.py` module maps Python types to SQL types:
682717┌─────────────────────────────────────────────────────────────────────┐
683718│ SingleStore Database │
684719└─────────────────────────────────────────────────────────────────────┘
685- │ │
686- │ ASGI/HTTP │ Memory-mapped
687- │ (remote) │ (collocated)
688- ▼ ▼
689- ┌─────────────┐ ┌─────────────┐
690- │ asgi.py │ │ mmap.py │
691- │ Uvicorn │ │ Shared │
692- │ HTTP/2 │ │ Memory │
693- └─────────────┘ └─────────────┘
694- │ │
695- └────────────────────┘
696- │
697- ▼
698- ┌─────────────────┐
699- │ Python UDF │
700- │ Functions │
701- └─────────────────┘
720+ │ │ │
721+ │ ASGI/HTTP │ Memory-mapped │ Plugin
722+ │ (remote) │ (collocated) │ (Unix socket)
723+ ▼ ▼ ▼
724+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
725+ │ asgi.py │ │ mmap.py │ │ plugin/ │
726+ │ Uvicorn │ │ Shared │ │ Unix sock │
727+ │ HTTP/2 │ │ Memory │ │ + pool │
728+ └─────────────┘ └─────────────┘ └─────────────┘
729+ │ │ │
730+ └────────────────────┴──────────────────── ┘
731+ │
732+ ▼
733+ ┌─────────────────┐
734+ │ Python UDF │
735+ │ Functions │
736+ └─────────────────┘
702737```
703738
704739| Mode | File | Use Case |
705740| ------| ------| ----------|
706741| ASGI | ` asgi.py ` | Remote execution via HTTP, scalable |
707742| Memory-mapped | ` mmap.py ` | Collocated execution, lowest latency |
743+ | Plugin | ` plugin/ ` | Unix socket server, thread/process pool, CLI-driven |
708744| JSON | ` json.py ` | Simple serialization, debugging |
709745| ROWDAT_1 | ` rowdat_1.py ` | Binary format, efficient |
710746| Arrow | ` arrow.py ` | Columnar format, analytics |
@@ -1043,6 +1079,13 @@ with free_tier.start() as server:
10431079| ` SINGLESTOREDB_MANAGEMENT_TOKEN ` | Management API token | None |
10441080| ` SINGLESTORE_LICENSE ` | License key for Docker | None |
10451081| ` USE_DATA_API ` | Use HTTP API for tests | 0 |
1082+ | ` PLUGIN_NAME ` | Plugin server: Python module to import | None |
1083+ | ` PLUGIN_SEARCH_PATH ` | Plugin server: colon-separated module search dirs | ` "" ` |
1084+ | ` PLUGIN_SOCKET_PATH ` | Plugin server: Unix socket path | auto-generated |
1085+ | ` PLUGIN_N_WORKERS ` | Plugin server: worker count (0 = CPU count) | ` 0 ` |
1086+ | ` PLUGIN_MAX_CONNECTIONS ` | Plugin server: socket backlog | ` 32 ` |
1087+ | ` PLUGIN_LOG_LEVEL ` | Plugin server: logging level | ` info ` |
1088+ | ` PLUGIN_PROCESS_MODE ` | Plugin server: ` thread ` or ` process ` | ` process ` |
10461089
10471090### B. Cursor Type Matrix
10481091
@@ -1096,4 +1139,5 @@ Feature options:
10961139| Management API | ` singlestoredb/management/workspace.py ` |
10971140| Fusion handlers | ` singlestoredb/fusion/handler.py ` |
10981141| UDF decorator | ` singlestoredb/functions/decorator.py ` |
1142+ | Plugin UDF server | ` singlestoredb/functions/ext/plugin/server.py ` |
10991143| Test fixtures | ` singlestoredb/pytest.py ` |
0 commit comments