kycli 0.2.3__tar.gz → 0.4.0__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 (73) hide show
  1. {kycli-0.2.3/kycli.egg-info → kycli-0.4.0}/PKG-INFO +164 -10
  2. {kycli-0.2.3 → kycli-0.4.0}/README.md +163 -9
  3. {kycli-0.2.3 → kycli-0.4.0}/TODO.md +20 -4
  4. {kycli-0.2.3 → kycli-0.4.0}/kycli/cli.py +342 -43
  5. {kycli-0.2.3 → kycli-0.4.0}/kycli/config.py +42 -5
  6. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/audit.c +1421 -1152
  7. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/audit.pyx +10 -2
  8. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/engine.c +2151 -1215
  9. kycli-0.4.0/kycli/core/engine.pyx +152 -0
  10. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/query.c +67 -26
  11. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/security.c +1440 -528
  12. kycli-0.4.0/kycli/core/security.pxd +9 -0
  13. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/security.pyx +8 -7
  14. kycli-0.4.0/kycli/core/storage.c +55263 -0
  15. kycli-0.4.0/kycli/core/storage.pyx +1299 -0
  16. kycli-0.4.0/kycli/logging_utils.py +29 -0
  17. {kycli-0.2.3 → kycli-0.4.0}/kycli/tui.py +303 -48
  18. kycli-0.4.0/kycli/utils.py +51 -0
  19. {kycli-0.2.3 → kycli-0.4.0/kycli.egg-info}/PKG-INFO +164 -10
  20. {kycli-0.2.3 → kycli-0.4.0}/kycli.egg-info/SOURCES.txt +11 -1
  21. {kycli-0.2.3 → kycli-0.4.0}/kycli.egg-info/entry_points.txt +13 -0
  22. {kycli-0.2.3 → kycli-0.4.0}/pyproject.toml +14 -1
  23. {kycli-0.2.3 → kycli-0.4.0}/setup.py +14 -1
  24. kycli-0.4.0/tests/core/test_concurrency.py +145 -0
  25. kycli-0.4.0/tests/core/test_queues_stacks.py +128 -0
  26. kycli-0.4.0/tests/core/test_roadmap_features.py +92 -0
  27. {kycli-0.2.3 → kycli-0.4.0}/tests/core/test_storage_scaling.py +3 -3
  28. {kycli-0.2.3 → kycli-0.4.0}/tests/interface/test_gap_coverage.py +2 -1
  29. {kycli-0.2.3 → kycli-0.4.0}/tests/interface/test_new_features.py +12 -4
  30. kycli-0.4.0/tests/performance/kycli_benchmark.py +165 -0
  31. {kycli-0.2.3 → kycli-0.4.0}/tests/test_cli.py +20 -1
  32. kycli-0.4.0/tests/test_cli_coverage.py +401 -0
  33. kycli-0.4.0/tests/test_cli_coverage_gaps.py +242 -0
  34. kycli-0.4.0/tests/test_cli_legacy.py +70 -0
  35. kycli-0.4.0/tests/test_cli_roadmap.py +100 -0
  36. {kycli-0.2.3 → kycli-0.4.0}/tests/test_config.py +37 -5
  37. kycli-0.4.0/tests/test_init.py +21 -0
  38. kycli-0.4.0/tests/test_tui.py +867 -0
  39. kycli-0.4.0/tests/test_utils.py +23 -0
  40. kycli-0.2.3/kycli/core/engine.pyx +0 -88
  41. kycli-0.2.3/kycli/core/security.pxd +0 -9
  42. kycli-0.2.3/kycli/core/storage.c +0 -32373
  43. kycli-0.2.3/kycli/core/storage.pyx +0 -639
  44. kycli-0.2.3/tests/test_cli_coverage.py +0 -43
  45. kycli-0.2.3/tests/test_init.py +0 -33
  46. kycli-0.2.3/tests/test_tui.py +0 -434
  47. {kycli-0.2.3 → kycli-0.4.0}/CHANGELOG.md +0 -0
  48. {kycli-0.2.3 → kycli-0.4.0}/LICENSE +0 -0
  49. {kycli-0.2.3 → kycli-0.4.0}/MANIFEST.in +0 -0
  50. {kycli-0.2.3 → kycli-0.4.0}/kycli/__init__.py +0 -0
  51. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/audit.pxd +0 -0
  52. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/engine.pxd +0 -0
  53. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/query.pxd +0 -0
  54. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/query.pyx +0 -0
  55. {kycli-0.2.3 → kycli-0.4.0}/kycli/core/sqlite_defs.pxd +0 -0
  56. {kycli-0.2.3 → kycli-0.4.0}/kycli/kycli.c +0 -0
  57. {kycli-0.2.3 → kycli-0.4.0}/kycli/kyfactory.c +0 -0
  58. {kycli-0.2.3 → kycli-0.4.0}/kycli.egg-info/dependency_links.txt +0 -0
  59. {kycli-0.2.3 → kycli-0.4.0}/kycli.egg-info/requires.txt +0 -0
  60. {kycli-0.2.3 → kycli-0.4.0}/kycli.egg-info/top_level.txt +0 -0
  61. {kycli-0.2.3 → kycli-0.4.0}/setup.cfg +0 -0
  62. {kycli-0.2.3 → kycli-0.4.0}/tests/conftest.py +0 -0
  63. {kycli-0.2.3 → kycli-0.4.0}/tests/core/test_security_ops.py +0 -0
  64. {kycli-0.2.3 → kycli-0.4.0}/tests/core/test_storage.py +0 -0
  65. {kycli-0.2.3 → kycli-0.4.0}/tests/core/test_storage_advanced.py +0 -0
  66. {kycli-0.2.3 → kycli-0.4.0}/tests/integration/benchmark.py +0 -0
  67. {kycli-0.2.3 → kycli-0.4.0}/tests/integration/test_performance.py +0 -0
  68. {kycli-0.2.3 → kycli-0.4.0}/tests/interface/test_final.py +0 -0
  69. {kycli-0.2.3 → kycli-0.4.0}/tests/interface/test_full_coverage.py +0 -0
  70. {kycli-0.2.3 → kycli-0.4.0}/tests/interface/verify_encryption.py +0 -0
  71. {kycli-0.2.3 → kycli-0.4.0}/tests/test_cli_env.py +0 -0
  72. {kycli-0.2.3 → kycli-0.4.0}/tests/test_cli_workspaces.py +0 -0
  73. {kycli-0.2.3 → kycli-0.4.0}/tests/test_final_coverage.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kycli
3
- Version: 0.2.3
3
+ Version: 0.4.0
4
4
  Summary: **kycli** is a high-performance Python CLI toolkit built with Cython for speed.
5
5
  Author: Balakrishna Maduru
6
6
  Author-email: balakrishnamaduru@gmail.com
@@ -62,6 +62,16 @@ Install the latest version from PyPI:
62
62
  pip install kycli
63
63
  ```
64
64
 
65
+ ### Validate The Install
66
+
67
+ Run the end-to-end command matrix from the repo root:
68
+
69
+ ```bash
70
+ bash scripts/validate_install.sh
71
+ ```
72
+
73
+ The validator auto-resolves a usable Python executable, prefers the active `python3` runtime, and runs stateful sections in isolated home directories so queue, profile, and policy checks do not interfere with each other.
74
+
65
75
  ---
66
76
 
67
77
  ## 💻 CLI Command Reference
@@ -86,6 +96,17 @@ pip install kycli
86
96
  | **`kyd`** | Delete Key | `kyd host` |
87
97
  | **`kypush`**| Push to List | `kypush logs "error"` |
88
98
  | **`kyrem`** | Remove from List | `kyrem tags "old"` |
99
+ ### 🧱 Queues & Stacks Operations
100
+ | Command | Description | Example |
101
+ | :--- | :--- | :--- |
102
+ | **`kypush`** | Push to Queue/Stack | `kypush "task" --priority 10` |
103
+ | **`kypop`** | Pop item (Atomic) | `kypop` |
104
+ | **`kypeek`** | Peek next item | `kypeek` |
105
+ | **`kycount`** | Count items | `kycount` |
106
+ | **`kyclear`** | Clear implementation | `kyclear` |
107
+ | **`kyws`** | Create Typed WS | `kyws create q --type queue` |
108
+ | **`kyack`** | Ack leased item | `kyack <receipt_id>` |
109
+ | **`kynack`** | Requeue leased item | `kynack <receipt_id> --delay 30s` |
89
110
 
90
111
  ### 🔍 Search & Utility
91
112
  | Command | Description | Example |
@@ -106,6 +127,13 @@ pip install kycli
106
127
  | **`kyc`** | Execute Command | `kyc hello` |
107
128
  | **`kyco`** | Compact DB | `kyco 7` |
108
129
  | **`kyrotate`** | Rotate Master Key | `kyrotate --new-key "newpass" --old-key "oldpass" --backup` |
130
+ | **`kyttl`** | Workspace TTL policy | `kyttl set 1h` |
131
+ | **`kyprofile`** | Manage profiles | `kyprofile save dev` |
132
+ | **`kyacl`** | Workspace ACL/policy | `kyacl readonly on` |
133
+ | **`kyaudit`** | Export audit history | `kyaudit export audit.json json` |
134
+ | **`kystats`** | Show workspace stats | `kystats --json` |
135
+ | **`kybackup`** | Create/restore backup | `kybackup snapshot.db` |
136
+ | **`kymetrics`** | Local metrics endpoint | `kymetrics 8765` |
109
137
 
110
138
  ---
111
139
 
@@ -129,7 +157,6 @@ kyws
129
157
 
130
158
  #### `kymv` — Move Key
131
159
  Moves a key (and its value) from the current workspace to another.
132
- - **Safety**: Asks for confirmation if the key exists in the target.
133
160
  ```bash
134
161
  kymv my_api_key project_beta
135
162
  # Result: ✅ Moved 'my_api_key' to 'project_beta'.
@@ -137,16 +164,87 @@ kymv my_api_key project_beta
137
164
 
138
165
  #### `kydrop` — Delete Workspace
139
166
  Permanently deletes an entire workspace and its database file.
140
- - **Safety**: Requires explicit confirmation (`y/N`) in CLI.
141
- - **Restriction**: You cannot drop the currently active workspace.
142
167
  ```bash
143
168
  kydrop temp_test
144
169
  # Result: ⚠️ DANGER: Are you sure you want to PERMANENTLY delete workspace 'temp_test'? (y/N): y
145
170
  # Result: ✅ Workspace 'temp_test' deleted.
146
171
  ```
147
172
 
148
- ---
149
173
 
174
+ ## 🧭 Advanced Features
175
+
176
+ ### Queue Reliability
177
+ - **Batch Queue Ops**: `kypush --file` and `kypop --n 100` for throughput-oriented flows.
178
+ - **Delayed Jobs**: `kypush --delay 30s` schedules visibility in queue workspaces.
179
+ - **Visibility Timeout**: `kypop --lease 30s` with `kyack` and `kynack` supports retry flows.
180
+ - **Workspace TTL Policies**: `kyttl set/get` applies default TTL behavior per workspace.
181
+
182
+ ### Usability & DX
183
+ - **Config Profiles**: `kyprofile use prod` switches saved CLI defaults.
184
+ - **Output Formatting**: `--json` and `--pretty` are available on structured read paths.
185
+ - **Interactive TUI**: `kyshell` provides an interactive terminal workflow on top of the same engine.
186
+
187
+ ### Security & Compliance
188
+ - **Workspace ACLs**: `kyacl readonly on|off|status` supports write protection.
189
+ - **Workspace Access Keys**: `kyacl key set|get|clear` gates writes with `KYCLI_ACCESS_KEY`.
190
+ - **Audit Export**: `kyaudit export` supports JSON or CSV output with optional time filters.
191
+
192
+ ### Observability
193
+ - **Stats Command**: `kystats` exposes workspace type, counts, TTL usage, archive size, and DB size.
194
+ - **Metrics Endpoint**: `kymetrics` starts a local HTTP endpoint on `127.0.0.1`.
195
+
196
+ ### Data Management
197
+ - **Namespace/Prefix Views**: `kyws view <prefix>` filters large keyspaces.
198
+ - **Backup/Restore**: `kybackup` creates and restores encrypted snapshots.
199
+
200
+ ### Queue Reliability
201
+ ```bash
202
+ # Push from a file
203
+ kypush --file tasks.txt
204
+
205
+ # Delay visibility for 30 seconds
206
+ kypush "email:user_123" --delay 30s
207
+
208
+ # Lease one item for 30 seconds
209
+ kypop --lease 30s --json
210
+
211
+ # Acknowledge or requeue
212
+ kyack <receipt_id>
213
+ kynack <receipt_id> --delay 15s
214
+ ```
215
+
216
+ ### Workspace Policies
217
+ ```bash
218
+ # Set a default TTL for all new values in this workspace
219
+ kyttl set 1h
220
+ kyttl get
221
+
222
+ # Enable read-only mode
223
+ kyacl readonly on
224
+
225
+ # Protect a workspace with an access key
226
+ kyacl key set my-secret
227
+ KYCLI_ACCESS_KEY=my-secret kys protected value
228
+ ```
229
+
230
+ ### Profiles, Stats, and Backups
231
+ ```bash
232
+ kyprofile save dev
233
+ kyprofile list
234
+ kyprofile use dev
235
+
236
+ kystats --json
237
+ kyaudit export audit.json json --since "2026-01-01 00:00:00"
238
+ kybackup snapshot.db
239
+ kybackup restore snapshot.db
240
+ kymetrics 8765
241
+ ```
242
+
243
+ ### Maintenance & Reliability
244
+ - **Lock Management**: Retry with exponential backoff for "Database is locked" in multi-process scenarios.
245
+ - **Activity Logs**: Background logging via Python `logging` module.
246
+ - **Atomic Rename Exports**: Write-to-temp-then-rename for export safety.
247
+ - **Compression**: Optional large-value compression for storage efficiency.
150
248
  ### `kyh` — The Help Center
151
249
  Shows the available commands and basic usage instructions.
152
250
  ```bash
@@ -170,6 +268,40 @@ kys session_id "data" --ttl 1h
170
268
  # Result: ✅ Saved: session_id (New) (Expires in 1 hour)
171
269
  ```
172
270
 
271
+ ### 🧱 Typed Workspaces: Queues & Stacks
272
+ Optimize your workspace for specific data structures with strict concurrency guarantees (`BEGIN IMMEDIATE` locking).
273
+
274
+ #### 1. Queue (FIFO)
275
+ ```bash
276
+ # Create
277
+ kyws create jobs --type queue
278
+ kyuse jobs
279
+
280
+ # Push & Pop (Atomic)
281
+ kypush "job_1"
282
+ kypop
283
+ # Result: job_1
284
+ ```
285
+
286
+ #### 2. Stack (LIFO)
287
+ ```bash
288
+ kyws create undo_log --type stack
289
+ kypush "cmd1"
290
+ kypush "cmd2"
291
+ kypop
292
+ # Result: cmd2
293
+ ```
294
+
295
+ #### 3. Priority Queue
296
+ ```bash
297
+ kyws create triage --type priority_queue
298
+ kypush "low" --priority 1
299
+ kypush "high" --priority 100
300
+ kypop
301
+ # Result: high
302
+ ```
303
+ See [docs/QUEUES_STACKS.md](docs/QUEUES_STACKS.md) for full details.
304
+
173
305
  ### 📂 Advanced JSONPath & Dot-Notation
174
306
  `kycli` allows you to treat your key-value store like a document database. You can query and update deep nested structures without retrieving the entire object.
175
307
 
@@ -186,10 +318,13 @@ kyg logs[0:5]
186
318
  ```
187
319
 
188
320
  #### Atomic Patching (Partial Updates):
189
- Instead of rewriting a large JSON object, you can update just one field.
321
+ Instead of rewriting a large JSON object, you can update just one field. Use
322
+ `kypatch` (not `kys`) for this — `kys` always treats dots in a key as a literal
323
+ flat key name (e.g. for namespacing, like `kys ns.alpha 1`), while `kypatch`
324
+ treats them as a path into the nested object.
190
325
  ```bash
191
326
  # Update just the 'age' field inside the 'user' object
192
- kys user.profile.age 25
327
+ kypatch user.profile.age 25
193
328
  ```
194
329
 
195
330
  ### 📦 Collection Operations (Lists & Sets)
@@ -466,6 +601,24 @@ with Kycore() as kv:
466
601
  kv.save_many(items, ttl="1h")
467
602
  # Result: ⚡ Atomic transaction per batch (extremely fast)
468
603
 
604
+ # 5. Queues & Stacks (API)
605
+ use `set_type` to separate queues from KV stores.
606
+ ```python
607
+ from kycli import Kycore
608
+
609
+ # Initialize and set type
610
+ with Kycore("jobs.db") as q:
611
+ q.set_type("queue")
612
+
613
+ # Push (Atomic & Durable)
614
+ q.push("task_1")
615
+ q.push({"id": 2, "action": "email"})
616
+
617
+ # Pop (Thread-Safe)
618
+ item = q.pop()
619
+ print(item) # task_1
620
+ ```
621
+
469
622
  # 6. Maintenance & PITR
470
623
  with Kycore() as kv:
471
624
  # Cleanup history older than 30 days
@@ -544,8 +697,9 @@ async def fetch_config(key: str, db: Kycore = Depends(get_db)):
544
697
 
545
698
  ## 🏗 Architecture & Internal Safety
546
699
 
547
- - **SQLite Engine**: Running in `WAL` (Write-Ahead Logging) mode for concurrent reads/writes.
548
- - **Atomic Operations**: Exports use a "temp-file then rename" strategy to prevent corruption.
700
+ - **Encrypted Single-File Storage**: Each workspace is a single AES-GCM-encrypted file. `kycli` decrypts it into an in-memory SQLite engine on open and re-serializes the whole workspace back to disk on every write.
701
+ - **Atomic Writes**: Every persist (workspace file, exports, audit export) uses a "temp-file then rename" strategy a concurrent reader always sees a complete file, never a partial/corrupted one.
702
+ - **Cross-Process Write Safety**: Writes from independent `kycli` processes sharing one workspace file are serialized via an OS-level advisory lock (`flock`, POSIX). A process reloads the latest on-disk state immediately before mutating it, so sibling processes' writes are never silently overwritten. *(Windows: atomic writes still prevent corruption, but cross-process mutual exclusion requires POSIX `flock` and is not yet supported.)*
549
703
  - **Data Integrity**: Keys are automatically lowercased and stripped to prevent duplicate-but-slightly-different keys.
550
704
  - **Auto-Purge Policy**: Deleted keys are moved to an **Archive** table and automatically purged after **15 days** to keep the database size optimized.
551
705
  - **Embedded C**: Core operations are written in Cython, binding directly to native library pointers.
@@ -556,7 +710,7 @@ async def fetch_config(key: str, db: Kycore = Depends(get_db)):
556
710
 
557
711
  Want to test the speed on your own hardware?
558
712
  ```bash
559
- PYTHONPATH=. python3 tests/integration/benchmark.py
713
+ PYTHONPATH=. python3 tests/performance/kycli_benchmark.py
560
714
  ```
561
715
 
562
716
  ---
@@ -36,6 +36,16 @@ Install the latest version from PyPI:
36
36
  pip install kycli
37
37
  ```
38
38
 
39
+ ### Validate The Install
40
+
41
+ Run the end-to-end command matrix from the repo root:
42
+
43
+ ```bash
44
+ bash scripts/validate_install.sh
45
+ ```
46
+
47
+ The validator auto-resolves a usable Python executable, prefers the active `python3` runtime, and runs stateful sections in isolated home directories so queue, profile, and policy checks do not interfere with each other.
48
+
39
49
  ---
40
50
 
41
51
  ## 💻 CLI Command Reference
@@ -60,6 +70,17 @@ pip install kycli
60
70
  | **`kyd`** | Delete Key | `kyd host` |
61
71
  | **`kypush`**| Push to List | `kypush logs "error"` |
62
72
  | **`kyrem`** | Remove from List | `kyrem tags "old"` |
73
+ ### 🧱 Queues & Stacks Operations
74
+ | Command | Description | Example |
75
+ | :--- | :--- | :--- |
76
+ | **`kypush`** | Push to Queue/Stack | `kypush "task" --priority 10` |
77
+ | **`kypop`** | Pop item (Atomic) | `kypop` |
78
+ | **`kypeek`** | Peek next item | `kypeek` |
79
+ | **`kycount`** | Count items | `kycount` |
80
+ | **`kyclear`** | Clear implementation | `kyclear` |
81
+ | **`kyws`** | Create Typed WS | `kyws create q --type queue` |
82
+ | **`kyack`** | Ack leased item | `kyack <receipt_id>` |
83
+ | **`kynack`** | Requeue leased item | `kynack <receipt_id> --delay 30s` |
63
84
 
64
85
  ### 🔍 Search & Utility
65
86
  | Command | Description | Example |
@@ -80,6 +101,13 @@ pip install kycli
80
101
  | **`kyc`** | Execute Command | `kyc hello` |
81
102
  | **`kyco`** | Compact DB | `kyco 7` |
82
103
  | **`kyrotate`** | Rotate Master Key | `kyrotate --new-key "newpass" --old-key "oldpass" --backup` |
104
+ | **`kyttl`** | Workspace TTL policy | `kyttl set 1h` |
105
+ | **`kyprofile`** | Manage profiles | `kyprofile save dev` |
106
+ | **`kyacl`** | Workspace ACL/policy | `kyacl readonly on` |
107
+ | **`kyaudit`** | Export audit history | `kyaudit export audit.json json` |
108
+ | **`kystats`** | Show workspace stats | `kystats --json` |
109
+ | **`kybackup`** | Create/restore backup | `kybackup snapshot.db` |
110
+ | **`kymetrics`** | Local metrics endpoint | `kymetrics 8765` |
83
111
 
84
112
  ---
85
113
 
@@ -103,7 +131,6 @@ kyws
103
131
 
104
132
  #### `kymv` — Move Key
105
133
  Moves a key (and its value) from the current workspace to another.
106
- - **Safety**: Asks for confirmation if the key exists in the target.
107
134
  ```bash
108
135
  kymv my_api_key project_beta
109
136
  # Result: ✅ Moved 'my_api_key' to 'project_beta'.
@@ -111,16 +138,87 @@ kymv my_api_key project_beta
111
138
 
112
139
  #### `kydrop` — Delete Workspace
113
140
  Permanently deletes an entire workspace and its database file.
114
- - **Safety**: Requires explicit confirmation (`y/N`) in CLI.
115
- - **Restriction**: You cannot drop the currently active workspace.
116
141
  ```bash
117
142
  kydrop temp_test
118
143
  # Result: ⚠️ DANGER: Are you sure you want to PERMANENTLY delete workspace 'temp_test'? (y/N): y
119
144
  # Result: ✅ Workspace 'temp_test' deleted.
120
145
  ```
121
146
 
122
- ---
123
147
 
148
+ ## 🧭 Advanced Features
149
+
150
+ ### Queue Reliability
151
+ - **Batch Queue Ops**: `kypush --file` and `kypop --n 100` for throughput-oriented flows.
152
+ - **Delayed Jobs**: `kypush --delay 30s` schedules visibility in queue workspaces.
153
+ - **Visibility Timeout**: `kypop --lease 30s` with `kyack` and `kynack` supports retry flows.
154
+ - **Workspace TTL Policies**: `kyttl set/get` applies default TTL behavior per workspace.
155
+
156
+ ### Usability & DX
157
+ - **Config Profiles**: `kyprofile use prod` switches saved CLI defaults.
158
+ - **Output Formatting**: `--json` and `--pretty` are available on structured read paths.
159
+ - **Interactive TUI**: `kyshell` provides an interactive terminal workflow on top of the same engine.
160
+
161
+ ### Security & Compliance
162
+ - **Workspace ACLs**: `kyacl readonly on|off|status` supports write protection.
163
+ - **Workspace Access Keys**: `kyacl key set|get|clear` gates writes with `KYCLI_ACCESS_KEY`.
164
+ - **Audit Export**: `kyaudit export` supports JSON or CSV output with optional time filters.
165
+
166
+ ### Observability
167
+ - **Stats Command**: `kystats` exposes workspace type, counts, TTL usage, archive size, and DB size.
168
+ - **Metrics Endpoint**: `kymetrics` starts a local HTTP endpoint on `127.0.0.1`.
169
+
170
+ ### Data Management
171
+ - **Namespace/Prefix Views**: `kyws view <prefix>` filters large keyspaces.
172
+ - **Backup/Restore**: `kybackup` creates and restores encrypted snapshots.
173
+
174
+ ### Queue Reliability
175
+ ```bash
176
+ # Push from a file
177
+ kypush --file tasks.txt
178
+
179
+ # Delay visibility for 30 seconds
180
+ kypush "email:user_123" --delay 30s
181
+
182
+ # Lease one item for 30 seconds
183
+ kypop --lease 30s --json
184
+
185
+ # Acknowledge or requeue
186
+ kyack <receipt_id>
187
+ kynack <receipt_id> --delay 15s
188
+ ```
189
+
190
+ ### Workspace Policies
191
+ ```bash
192
+ # Set a default TTL for all new values in this workspace
193
+ kyttl set 1h
194
+ kyttl get
195
+
196
+ # Enable read-only mode
197
+ kyacl readonly on
198
+
199
+ # Protect a workspace with an access key
200
+ kyacl key set my-secret
201
+ KYCLI_ACCESS_KEY=my-secret kys protected value
202
+ ```
203
+
204
+ ### Profiles, Stats, and Backups
205
+ ```bash
206
+ kyprofile save dev
207
+ kyprofile list
208
+ kyprofile use dev
209
+
210
+ kystats --json
211
+ kyaudit export audit.json json --since "2026-01-01 00:00:00"
212
+ kybackup snapshot.db
213
+ kybackup restore snapshot.db
214
+ kymetrics 8765
215
+ ```
216
+
217
+ ### Maintenance & Reliability
218
+ - **Lock Management**: Retry with exponential backoff for "Database is locked" in multi-process scenarios.
219
+ - **Activity Logs**: Background logging via Python `logging` module.
220
+ - **Atomic Rename Exports**: Write-to-temp-then-rename for export safety.
221
+ - **Compression**: Optional large-value compression for storage efficiency.
124
222
  ### `kyh` — The Help Center
125
223
  Shows the available commands and basic usage instructions.
126
224
  ```bash
@@ -144,6 +242,40 @@ kys session_id "data" --ttl 1h
144
242
  # Result: ✅ Saved: session_id (New) (Expires in 1 hour)
145
243
  ```
146
244
 
245
+ ### 🧱 Typed Workspaces: Queues & Stacks
246
+ Optimize your workspace for specific data structures with strict concurrency guarantees (`BEGIN IMMEDIATE` locking).
247
+
248
+ #### 1. Queue (FIFO)
249
+ ```bash
250
+ # Create
251
+ kyws create jobs --type queue
252
+ kyuse jobs
253
+
254
+ # Push & Pop (Atomic)
255
+ kypush "job_1"
256
+ kypop
257
+ # Result: job_1
258
+ ```
259
+
260
+ #### 2. Stack (LIFO)
261
+ ```bash
262
+ kyws create undo_log --type stack
263
+ kypush "cmd1"
264
+ kypush "cmd2"
265
+ kypop
266
+ # Result: cmd2
267
+ ```
268
+
269
+ #### 3. Priority Queue
270
+ ```bash
271
+ kyws create triage --type priority_queue
272
+ kypush "low" --priority 1
273
+ kypush "high" --priority 100
274
+ kypop
275
+ # Result: high
276
+ ```
277
+ See [docs/QUEUES_STACKS.md](docs/QUEUES_STACKS.md) for full details.
278
+
147
279
  ### 📂 Advanced JSONPath & Dot-Notation
148
280
  `kycli` allows you to treat your key-value store like a document database. You can query and update deep nested structures without retrieving the entire object.
149
281
 
@@ -160,10 +292,13 @@ kyg logs[0:5]
160
292
  ```
161
293
 
162
294
  #### Atomic Patching (Partial Updates):
163
- Instead of rewriting a large JSON object, you can update just one field.
295
+ Instead of rewriting a large JSON object, you can update just one field. Use
296
+ `kypatch` (not `kys`) for this — `kys` always treats dots in a key as a literal
297
+ flat key name (e.g. for namespacing, like `kys ns.alpha 1`), while `kypatch`
298
+ treats them as a path into the nested object.
164
299
  ```bash
165
300
  # Update just the 'age' field inside the 'user' object
166
- kys user.profile.age 25
301
+ kypatch user.profile.age 25
167
302
  ```
168
303
 
169
304
  ### 📦 Collection Operations (Lists & Sets)
@@ -440,6 +575,24 @@ with Kycore() as kv:
440
575
  kv.save_many(items, ttl="1h")
441
576
  # Result: ⚡ Atomic transaction per batch (extremely fast)
442
577
 
578
+ # 5. Queues & Stacks (API)
579
+ use `set_type` to separate queues from KV stores.
580
+ ```python
581
+ from kycli import Kycore
582
+
583
+ # Initialize and set type
584
+ with Kycore("jobs.db") as q:
585
+ q.set_type("queue")
586
+
587
+ # Push (Atomic & Durable)
588
+ q.push("task_1")
589
+ q.push({"id": 2, "action": "email"})
590
+
591
+ # Pop (Thread-Safe)
592
+ item = q.pop()
593
+ print(item) # task_1
594
+ ```
595
+
443
596
  # 6. Maintenance & PITR
444
597
  with Kycore() as kv:
445
598
  # Cleanup history older than 30 days
@@ -518,8 +671,9 @@ async def fetch_config(key: str, db: Kycore = Depends(get_db)):
518
671
 
519
672
  ## 🏗 Architecture & Internal Safety
520
673
 
521
- - **SQLite Engine**: Running in `WAL` (Write-Ahead Logging) mode for concurrent reads/writes.
522
- - **Atomic Operations**: Exports use a "temp-file then rename" strategy to prevent corruption.
674
+ - **Encrypted Single-File Storage**: Each workspace is a single AES-GCM-encrypted file. `kycli` decrypts it into an in-memory SQLite engine on open and re-serializes the whole workspace back to disk on every write.
675
+ - **Atomic Writes**: Every persist (workspace file, exports, audit export) uses a "temp-file then rename" strategy a concurrent reader always sees a complete file, never a partial/corrupted one.
676
+ - **Cross-Process Write Safety**: Writes from independent `kycli` processes sharing one workspace file are serialized via an OS-level advisory lock (`flock`, POSIX). A process reloads the latest on-disk state immediately before mutating it, so sibling processes' writes are never silently overwritten. *(Windows: atomic writes still prevent corruption, but cross-process mutual exclusion requires POSIX `flock` and is not yet supported.)*
523
677
  - **Data Integrity**: Keys are automatically lowercased and stripped to prevent duplicate-but-slightly-different keys.
524
678
  - **Auto-Purge Policy**: Deleted keys are moved to an **Archive** table and automatically purged after **15 days** to keep the database size optimized.
525
679
  - **Embedded C**: Core operations are written in Cython, binding directly to native library pointers.
@@ -530,7 +684,7 @@ async def fetch_config(key: str, db: Kycore = Depends(get_db)):
530
684
 
531
685
  Want to test the speed on your own hardware?
532
686
  ```bash
533
- PYTHONPATH=. python3 tests/integration/benchmark.py
687
+ PYTHONPATH=. python3 tests/performance/kycli_benchmark.py
534
688
  ```
535
689
 
536
690
  ---
@@ -37,15 +37,31 @@ This list tracks the progress of implementing high-performance and robust enhanc
37
37
  - [x] **100% Code Coverage Maintenance**
38
38
  ## Phase 6: Maintenance & Refinement ⚙️
39
39
  - [x] **Modular Refactoring** (Core engines split)
40
- - [ ] **Lock Management**: Retry with exponential backoff for "Database is locked" in multi-process scenarios.
41
- - [ ] **Activity Logs**: Background logging via Python `logging` module.
42
- - [ ] **Atomic Rename Exports**: Write-to-temp-then-rename for export safety.
43
- - [ ] **Compression**: Optional MsgPack/Zstd for large values.
40
+ - [x] **Lock Management**: Cross-process `flock` mutual exclusion + reload-on-write around every mutating operation, with atomic temp-file+rename persistence (no more lost updates or file corruption from concurrent `kycli` processes sharing a workspace).
41
+ - [x] **Activity Logs**: Background logging via Python `logging` module (`kycli/logging_utils.py`, writes to `~/.kycli/kycli.log`).
42
+ - [x] **Atomic Rename Exports**: Write-to-temp-then-rename for export safety (`kye`/`kyaudit export`, and now the internal workspace persistence itself).
43
+ - [x] **Compression**: Transparent zlib compression for values above a size threshold (workspace-configurable).
44
+
44
45
  ## Phase 7: Community & Branding 🤝
45
46
  - [x] **Community Guidelines** (COC, Contributing, Security)
46
47
  - [x] **Issue Templates**
47
48
  - [x] **Official Branding/Logo**
48
49
  - [x] **GitHub Repository Cleanup**
49
50
 
51
+ ## Phase 8: Roadmap (Planned Features) 🧭
52
+ - [ ] **Batch Queue Ops**: `kypush --file` and `kypop --n 100` for throughput.
53
+ - [ ] **Delayed Jobs**: `kypush --delay 30s` with scheduled dequeue.
54
+ - [ ] **Visibility Timeout**: `kypop --lease 30s` + `kyack`/`kynack` for retry flows.
55
+ - [ ] **Workspace TTL Policies**: Default TTL per workspace + `kyttl set/get`.
56
+ - [ ] **Interactive CLI Prompts**: Fuzzy key search + history in non-TUI mode.
57
+ - [ ] **Config Profiles**: `kyprofile use prod` to switch db path, master key, defaults.
58
+ - [ ] **Output Formatting**: `--json` everywhere; `--pretty` for tables.
59
+ - [ ] **Key ACLs / Scopes**: Read-only mode, write lock, per-workspace access key.
60
+ - [ ] **Audit Export**: `kyaudit export` with time filters.
61
+ - [ ] **Stats Command**: `kystats` for size, counts, TTL expirations, queue depth.
62
+ - [ ] **Metrics Endpoint**: Optional local HTTP for queue depth + ops/sec.
63
+ - [ ] **Namespace/Prefix Views**: `kyws view <prefix>` for large stores.
64
+ - [ ] **Backup/Restore**: `kybackup` with encryption and versioned snapshots.
65
+
50
66
  ---
51
67
  *Optimized for Performance by Antigravity*