Skip to content

Commit dc1c156

Browse files
kesmit13claude
andcommitted
Add Docker and free tier server usage examples to ARCHITECTURE.md
Expand the Server Tools section with concrete code examples showing how to start and connect to SingleStore via Docker containers and free tier instances, including context manager usage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 00622a9 commit dc1c156

File tree

1 file changed

+107
-77
lines changed

1 file changed

+107
-77
lines changed

ARCHITECTURE.md

Lines changed: 107 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ singlestoredb/
9494
│ ├── decorator.py # @udf decorator
9595
│ ├── signature.py # Type signature handling
9696
│ ├── dtypes.py # Data type mapping
97-
│ └── ext/ # Execution modes
97+
│ └── ext/ # External function servers
9898
│ ├── asgi.py # HTTP/ASGI server
9999
│ ├── mmap.py # Memory-mapped execution
100100
│ ├── json.py # JSON serialization
@@ -105,7 +105,7 @@ singlestoredb/
105105
│ ├── chat.py # Chat completion factory
106106
│ └── embeddings.py # Embeddings factory
107107
108-
├── alchemy/ # SQLAlchemy integration
108+
├── alchemy/ # SQLAlchemy utilities
109109
├── notebook/ # Jupyter notebook support
110110
├── magics/ # IPython magic commands
111111
├── server/ # Server management tools
@@ -352,21 +352,9 @@ with conn.cursor(results_type='pandas', buffered=False) as cur:
352352
process(batch)
353353
```
354354

355-
#### Authentication Methods
355+
### HTTP (Data API) Connector (`singlestoredb/http/`)
356356

357-
Defined in `singlestoredb/mysql/_auth.py`:
358-
359-
| Method | Function | Description |
360-
|--------|----------|-------------|
361-
| Native | `scramble_native_password()` | MySQL native password authentication |
362-
| SHA256 | `sha256_password_auth()` | SHA-256 with RSA encryption |
363-
| Caching SHA2 | `caching_sha2_password_auth()` | Fast cached authentication |
364-
| Ed25519 | `ed25519_password()` | Ed25519 signature authentication |
365-
| GSSAPI | `gssapi_auth()` | Kerberos/GSSAPI authentication |
366-
367-
### HTTP Connector (`singlestoredb/http/`)
368-
369-
The HTTP connector provides REST-based access via SingleStore's HTTP API (port 9000).
357+
The HTTP connector provides REST-like access via SingleStore's HTTP API (port 9000).
370358

371359
**Key Characteristics:**
372360
- JSON request/response encoding
@@ -443,7 +431,7 @@ SingleStore's cloud management features.
443431
│ api.singlestore.com │
444432
└─────────────────────────────────────────────────────────────────────┘
445433
446-
│ REST + JWT Auth
434+
│ REST + (JWT Auth or Org API key)
447435
448436
┌─────────────────────────────────────────────────────────────────────┐
449437
│ Manager (base) │
@@ -462,20 +450,6 @@ SingleStore's cloud management features.
462450
└─────────────────────────────────────────────────────────────────────┘
463451
```
464452

465-
### Resource Hierarchy
466-
467-
```
468-
Organization
469-
470-
├── WorkspaceGroup
471-
│ ├── Stage (file storage)
472-
│ └── Workspace (database instance)
473-
│ └── connect() → Connection
474-
475-
└── StarterWorkspace (free tier)
476-
└── connect() → Connection
477-
```
478-
479453
### Usage
480454

481455
```python
@@ -531,24 +505,24 @@ intercepted before being sent to the database and processed by registered handle
531505
┌─────────────────────────────────────────────────────────────────────┐
532506
│ cursor.execute(sql) │
533507
└─────────────────────────────────────────────────────────────────────┘
534-
535-
536-
┌─────────────────────────────────────┐
537-
│ Fusion SQL Registry │
538-
│ singlestoredb/fusion/registry.py │
539-
│ Match leading keywords │
540-
└─────────────────────────────────────┘
541-
542-
┌────────────────────┼────────────────────┐
543-
│ │
544-
▼ ▼
545-
┌───────────┐ ┌───────────┐ ┌───────────┐
546-
│ No Match │ Handler │ │ Handler │
547-
│ → Send Found │ │ Found │
548-
│ to DB │ │ │
549-
└───────────┘ └───────────┘ └───────────┘
550-
551-
508+
509+
510+
┌─────────────────────────────────────┐
511+
│ Fusion SQL Registry │
512+
│ singlestoredb/fusion/registry.py │
513+
│ Match leading keywords │
514+
└─────────────────────────────────────┘
515+
516+
────────────────────┐
517+
│ │
518+
▼ ▼
519+
┌───────────┐ ┌───────────┐
520+
No Match │ │ Handler │
521+
→ Send │ │ Found │
522+
to DB │ │ │
523+
└───────────┘ └───────────┘
524+
525+
552526
┌─────────────────────────────────┐
553527
│ SQLHandler.execute(sql) │
554528
│ Parse grammar → params dict │
@@ -561,6 +535,8 @@ intercepted before being sent to the database and processed by registered handle
561535

562536
```python
563537
import os
538+
539+
# Must be enabled by env var (default in notebook env is 1)
564540
os.environ['SINGLESTOREDB_FUSION_ENABLED'] = '1'
565541

566542
import singlestoredb as s2
@@ -573,7 +549,8 @@ cur.execute('SHOW WORKSPACE GROUPS')
573549
### Handler Architecture
574550

575551
Handlers extend `SQLHandler` (`singlestoredb/fusion/handler.py`) with grammar defined
576-
in the docstring:
552+
in the docstring. See the `singlestoredb/fusion/README.md` for more detailed information
553+
on writing handlers.
577554

578555
```python
579556
from singlestoredb.fusion.handler import SQLHandler
@@ -626,7 +603,9 @@ Located in `singlestoredb/fusion/handlers/`:
626603
## External Functions (UDFs)
627604

628605
The functions module (`singlestoredb/functions/`) enables deploying Python functions
629-
as SingleStore external 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.
630609

631610
### Architecture
632611

@@ -648,8 +627,8 @@ as SingleStore external functions.
648627
│ Execution Modes │
649628
│ singlestoredb/functions/ext/ │
650629
├─────────────────────────────────────────────────────────────────────┤
651-
│ asgi.py │ HTTP server via ASGI (Uvicorn)
652-
│ mmap.py │ Memory-mapped shared memory (collocated)
630+
│ asgi.py │ HTTP server via ASGI (Uvicorn; JSON or ROWDAT_1)
631+
│ mmap.py │ Memory-mapped shared memory (collocated; ROWDAT_1)
653632
│ json.py │ JSON serialization over HTTP │
654633
│ rowdat_1.py│ ROWDAT_1 binary format │
655634
│ arrow.py │ Apache Arrow columnar format │
@@ -703,22 +682,23 @@ The `signature.py` module maps Python types to SQL types:
703682
┌─────────────────────────────────────────────────────────────────────┐
704683
│ SingleStore Database │
705684
└─────────────────────────────────────────────────────────────────────┘
706-
│ │ │
707-
│ ASGI/HTTP │ Memory-mapped │ JSON
708-
│ (remote) │ (collocated) │ (simple)
709-
▼ ▼ ▼
710-
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
711-
│ asgi.py │ │ mmap.py │ │ json.py │
712-
│ Uvicorn │ │ Shared │ │ Simple │
713-
│ HTTP/2 │ │ Memory │ │ Serialize │
714-
└─────────────┘ └─────────────┘ └─────────────┘
715-
│ │ │
716-
└────────────────────┼────────────────────┘
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+
717697
718-
┌─────────────────┐
719-
│ Python UDF │
720-
│ Functions │
721-
└─────────────────┘
698+
┌─────────────────┐
699+
│ Python UDF │
700+
│ Functions │
701+
└─────────────────┘
722702
```
723703

724704
| Mode | File | Use Case |
@@ -762,11 +742,6 @@ embeddings = SingleStoreEmbeddingsFactory(
762742
vectors = embeddings.embed(['Hello', 'World'])
763743
```
764744

765-
### Supported Providers
766-
767-
- **OpenAI**: GPT models, text embeddings
768-
- **AWS Bedrock**: Claude, Titan models
769-
770745
---
771746

772747
## Vector Store
@@ -911,12 +886,14 @@ class _TestContainerManager:
911886

912887
### SQLAlchemy (`singlestoredb/alchemy/`)
913888

914-
SQLAlchemy dialect for SingleStore:
889+
SQLAlchemy utilities for SingleStore. The dialect is a separate package.
890+
This package just addes a `create_function` that works in the notebook
891+
environment without having to specify a connection URL.
915892

916893
```python
917894
from sqlalchemy import create_engine
918895

919-
engine = create_engine('singlestoredb://user:pass@host/db')
896+
engine = create_engine()
920897
```
921898

922899
### Jupyter/Notebook (`singlestoredb/notebook/`, `singlestoredb/magics/`)
@@ -926,8 +903,9 @@ IPython magic commands for notebooks:
926903
```python
927904
%load_ext singlestoredb
928905

929-
%%sql
930-
SELECT * FROM users
906+
%run_shared shared_notebook.ipynb
907+
908+
%run_personal personal_notebook.ipynb
931909
```
932910

933911
#### Portal and Live Accessor Objects
@@ -993,6 +971,58 @@ propagate bidirectionally between Python and the Portal UI.
993971
Utilities for managing SingleStore server instances, including Docker helpers and
994972
free tier management.
995973

974+
#### Docker Server (`singlestoredb/server/docker.py`)
975+
976+
Start a SingleStore server in a Docker container and connect to it:
977+
978+
```python
979+
from singlestoredb.server import docker
980+
981+
# Start with default settings
982+
server = docker.start(password='my_password')
983+
984+
# Or customize ports, license, and other options
985+
server = docker.start(
986+
name='my-container',
987+
password='my_password',
988+
license='your-license-key',
989+
server_port=3306,
990+
data_api_port=9000,
991+
database='my_db',
992+
)
993+
994+
# Connect using the MySQL protocol
995+
conn = server.connect()
996+
997+
# Connect using the HTTP Data API
998+
conn = server.connect(use_data_api=True)
999+
1000+
# Use as a context manager for automatic cleanup
1001+
with docker.start(password='my_password') as server:
1002+
conn = server.connect()
1003+
# ... use connection ...
1004+
# Server is stopped automatically on exit
1005+
```
1006+
1007+
#### Free Tier Server (`singlestoredb/server/free_tier.py`)
1008+
1009+
Start a free tier SingleStore server instance:
1010+
1011+
```python
1012+
from singlestoredb.server import free_tier
1013+
1014+
# Start the free tier server (no configuration required)
1015+
server = free_tier.start()
1016+
1017+
# Connect to the server
1018+
conn = server.connect()
1019+
1020+
# Use as a context manager
1021+
with free_tier.start() as server:
1022+
conn = server.connect()
1023+
# ... use connection ...
1024+
```
1025+
9961026
---
9971027

9981028
## Appendices

0 commit comments

Comments
 (0)