cctvql 1.0.2__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 (78) hide show
  1. cctvql-1.0.2/LICENSE +21 -0
  2. cctvql-1.0.2/PKG-INFO +515 -0
  3. cctvql-1.0.2/README.md +457 -0
  4. cctvql-1.0.2/cctvql/__init__.py +11 -0
  5. cctvql-1.0.2/cctvql/__main__.py +119 -0
  6. cctvql-1.0.2/cctvql/_bootstrap.py +285 -0
  7. cctvql-1.0.2/cctvql/adapters/__init__.py +22 -0
  8. cctvql-1.0.2/cctvql/adapters/base.py +182 -0
  9. cctvql-1.0.2/cctvql/adapters/dahua.py +573 -0
  10. cctvql-1.0.2/cctvql/adapters/demo.py +680 -0
  11. cctvql-1.0.2/cctvql/adapters/frigate.py +409 -0
  12. cctvql-1.0.2/cctvql/adapters/hikvision.py +645 -0
  13. cctvql-1.0.2/cctvql/adapters/milestone.py +418 -0
  14. cctvql-1.0.2/cctvql/adapters/onvif.py +377 -0
  15. cctvql-1.0.2/cctvql/adapters/onvif_discovery.py +252 -0
  16. cctvql-1.0.2/cctvql/adapters/scrypted.py +399 -0
  17. cctvql-1.0.2/cctvql/adapters/synology.py +424 -0
  18. cctvql-1.0.2/cctvql/core/__init__.py +29 -0
  19. cctvql-1.0.2/cctvql/core/alerts.py +378 -0
  20. cctvql-1.0.2/cctvql/core/anomaly.py +331 -0
  21. cctvql-1.0.2/cctvql/core/auth.py +193 -0
  22. cctvql-1.0.2/cctvql/core/database.py +231 -0
  23. cctvql-1.0.2/cctvql/core/health_monitor.py +217 -0
  24. cctvql-1.0.2/cctvql/core/multi_query.py +269 -0
  25. cctvql-1.0.2/cctvql/core/nlp_engine.py +210 -0
  26. cctvql-1.0.2/cctvql/core/query_router.py +550 -0
  27. cctvql-1.0.2/cctvql/core/schema.py +216 -0
  28. cctvql-1.0.2/cctvql/core/session_store.py +44 -0
  29. cctvql-1.0.2/cctvql/core/user_store.py +190 -0
  30. cctvql-1.0.2/cctvql/core/vision.py +268 -0
  31. cctvql-1.0.2/cctvql/interfaces/__init__.py +3 -0
  32. cctvql-1.0.2/cctvql/interfaces/cli.py +173 -0
  33. cctvql-1.0.2/cctvql/interfaces/rest_api.py +1282 -0
  34. cctvql-1.0.2/cctvql/interfaces/voice.py +308 -0
  35. cctvql-1.0.2/cctvql/llm/__init__.py +14 -0
  36. cctvql-1.0.2/cctvql/llm/anthropic_backend.py +177 -0
  37. cctvql-1.0.2/cctvql/llm/base.py +112 -0
  38. cctvql-1.0.2/cctvql/llm/ollama_backend.py +147 -0
  39. cctvql-1.0.2/cctvql/llm/openai_backend.py +161 -0
  40. cctvql-1.0.2/cctvql/notifications/__init__.py +20 -0
  41. cctvql-1.0.2/cctvql/notifications/base.py +37 -0
  42. cctvql-1.0.2/cctvql/notifications/email_notifier.py +87 -0
  43. cctvql-1.0.2/cctvql/notifications/ntfy.py +53 -0
  44. cctvql-1.0.2/cctvql/notifications/registry.py +56 -0
  45. cctvql-1.0.2/cctvql/notifications/slack.py +61 -0
  46. cctvql-1.0.2/cctvql/notifications/telegram.py +48 -0
  47. cctvql-1.0.2/cctvql/notifications/webhook.py +50 -0
  48. cctvql-1.0.2/cctvql/py.typed +0 -0
  49. cctvql-1.0.2/cctvql.egg-info/PKG-INFO +515 -0
  50. cctvql-1.0.2/cctvql.egg-info/SOURCES.txt +76 -0
  51. cctvql-1.0.2/cctvql.egg-info/dependency_links.txt +1 -0
  52. cctvql-1.0.2/cctvql.egg-info/entry_points.txt +2 -0
  53. cctvql-1.0.2/cctvql.egg-info/requires.txt +36 -0
  54. cctvql-1.0.2/cctvql.egg-info/top_level.txt +1 -0
  55. cctvql-1.0.2/pyproject.toml +106 -0
  56. cctvql-1.0.2/setup.cfg +4 -0
  57. cctvql-1.0.2/tests/test_alerts.py +466 -0
  58. cctvql-1.0.2/tests/test_anomaly.py +413 -0
  59. cctvql-1.0.2/tests/test_bootstrap.py +159 -0
  60. cctvql-1.0.2/tests/test_dahua_adapter.py +363 -0
  61. cctvql-1.0.2/tests/test_database.py +229 -0
  62. cctvql-1.0.2/tests/test_demo_adapter.py +188 -0
  63. cctvql-1.0.2/tests/test_ha_integration.py +308 -0
  64. cctvql-1.0.2/tests/test_hikvision_adapter.py +313 -0
  65. cctvql-1.0.2/tests/test_llm_backends.py +212 -0
  66. cctvql-1.0.2/tests/test_milestone_adapter.py +251 -0
  67. cctvql-1.0.2/tests/test_multi_query.py +290 -0
  68. cctvql-1.0.2/tests/test_multi_tenant.py +535 -0
  69. cctvql-1.0.2/tests/test_nlp_engine.py +78 -0
  70. cctvql-1.0.2/tests/test_onvif_discovery.py +285 -0
  71. cctvql-1.0.2/tests/test_query_router.py +107 -0
  72. cctvql-1.0.2/tests/test_rest_api.py +439 -0
  73. cctvql-1.0.2/tests/test_schema.py +88 -0
  74. cctvql-1.0.2/tests/test_scrypted_adapter.py +235 -0
  75. cctvql-1.0.2/tests/test_synology_adapter.py +238 -0
  76. cctvql-1.0.2/tests/test_timeline.py +237 -0
  77. cctvql-1.0.2/tests/test_vision.py +270 -0
  78. cctvql-1.0.2/tests/test_voice.py +312 -0
cctvql-1.0.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 arunrajiah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
cctvql-1.0.2/PKG-INFO ADDED
@@ -0,0 +1,515 @@
1
+ Metadata-Version: 2.4
2
+ Name: cctvql
3
+ Version: 1.0.2
4
+ Summary: Conversational query layer for CCTV systems — ask your cameras anything in plain English
5
+ Author-email: arunrajiah <arunrajiah@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/arunrajiah/cctvql
8
+ Project-URL: Repository, https://github.com/arunrajiah/cctvql
9
+ Project-URL: Issues, https://github.com/arunrajiah/cctvql/issues
10
+ Project-URL: Documentation, https://github.com/arunrajiah/cctvql/wiki
11
+ Keywords: cctv,nlp,surveillance,frigate,onvif,llm,conversational-ai,nvr,voice,whisper,speech-to-text
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Multimedia :: Video
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: System :: Monitoring
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: httpx>=0.27
28
+ Requires-Dist: pyyaml>=6.0
29
+ Requires-Dist: fastapi>=0.111
30
+ Requires-Dist: uvicorn[standard]>=0.30
31
+ Requires-Dist: pydantic>=2.0
32
+ Requires-Dist: websockets>=12.0
33
+ Requires-Dist: python-multipart>=0.0.12
34
+ Requires-Dist: aiosqlite>=0.20
35
+ Provides-Extra: mqtt
36
+ Requires-Dist: paho-mqtt>=2.0; extra == "mqtt"
37
+ Provides-Extra: onvif
38
+ Requires-Dist: onvif-zeep>=0.2.12; extra == "onvif"
39
+ Provides-Extra: voice
40
+ Requires-Dist: openai>=1.0; extra == "voice"
41
+ Requires-Dist: faster-whisper>=1.0; extra == "voice"
42
+ Provides-Extra: notifications
43
+ Requires-Dist: aiosmtplib>=3.0; extra == "notifications"
44
+ Provides-Extra: all
45
+ Requires-Dist: cctvql[mqtt,notifications,onvif,voice]; extra == "all"
46
+ Provides-Extra: dev
47
+ Requires-Dist: pytest>=8.0; extra == "dev"
48
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
49
+ Requires-Dist: pytest-mock>=3.12; extra == "dev"
50
+ Requires-Dist: httpx>=0.27; extra == "dev"
51
+ Requires-Dist: respx>=0.20; extra == "dev"
52
+ Requires-Dist: ruff>=0.4; extra == "dev"
53
+ Requires-Dist: mypy>=1.10; extra == "dev"
54
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
55
+ Requires-Dist: pre-commit>=3.7; extra == "dev"
56
+ Requires-Dist: types-PyYAML>=6.0; extra == "dev"
57
+ Dynamic: license-file
58
+
59
+ <div align="center">
60
+
61
+ # cctvQL
62
+
63
+ **Ask your CCTV system anything in plain English.**
64
+
65
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
66
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://python.org)
67
+ [![CI](https://github.com/arunrajiah/cctvql/actions/workflows/ci.yml/badge.svg)](https://github.com/arunrajiah/cctvql/actions)
68
+ [![codecov](https://img.shields.io/badge/coverage-64%25-yellow)](https://github.com/arunrajiah/cctvql/actions)
69
+ [![PyPI](https://img.shields.io/pypi/v/cctvql)](https://pypi.org/project/cctvql/)
70
+ [![Docker](https://img.shields.io/badge/docker-ready-blue)](https://hub.docker.com/r/arunrajiah/cctvql)
71
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
72
+ [![CodeQL](https://github.com/arunrajiah/cctvql/actions/workflows/codeql.yml/badge.svg)](https://github.com/arunrajiah/cctvql/actions/workflows/codeql.yml)
73
+
74
+ cctvQL is an open-source **conversational query layer** for CCTV and surveillance systems.
75
+ It wraps any camera system — Frigate, ONVIF, Hikvision, Dahua and more — with a natural language interface powered by local or cloud LLMs.
76
+
77
+ [Quick Start](#quick-start) · [Documentation](#documentation) · [Adapters](#supported-systems) · [Contributing](#contributing)
78
+
79
+ </div>
80
+
81
+ ---
82
+
83
+ ## What It Does
84
+
85
+ ```
86
+ you > Was there anyone near the front door last night?
87
+
88
+ cctvQL > Yes — 3 person detections on "Front Door" between 22:14 and 23:47.
89
+ • 22:14 — person (96%) in zone: driveway
90
+ • 23:02 — person (88%)
91
+ • 23:47 — person (91%) in zone: porch
92
+
93
+ you > Show me the clip from 23:47
94
+
95
+ cctvQL > Clip from Front Door (23:47–23:49, 112s):
96
+ http://192.168.1.100:5000/api/events/abc123/clip.mp4
97
+ ```
98
+
99
+ No dashboards. No complex queries. Just ask.
100
+
101
+ ---
102
+
103
+ ## Features
104
+
105
+ - **Natural language queries** — ask about events, cameras, clips, and system health in plain English
106
+ - **Multi-turn conversations** — context-aware follow-up questions backed by SQLite session persistence
107
+ - **Vendor-agnostic** — adapter pattern supports any CCTV system; ships with Frigate, ONVIF, Hikvision, Dahua
108
+ - **Pluggable LLM backends** — Ollama (local/private), OpenAI, Anthropic, or any OpenAI-compatible API
109
+ - **REST API** — integrate with Home Assistant, Grafana, custom dashboards, or mobile apps
110
+ - **PTZ control** — pan, tilt, zoom and preset recall via REST API for supported cameras
111
+ - **Event export** — download event history as CSV or JSON from `/events/export`
112
+ - **Alert rules** — create rules to notify when specific labels appear on specific cameras in time windows
113
+ - **Multi-channel notifications** — Telegram, Slack, ntfy, email, and webhook; all fire concurrently
114
+ - **WebSocket streaming** — real-time event push to any connected client via `ws://host/ws/events`
115
+ - **Prometheus metrics** — `/metrics` endpoint for Grafana, alerting, and observability
116
+ - **Camera health monitoring** — background poller tracks per-camera online/offline status
117
+ - **Optional API key auth** — protect your endpoint with `CCTVQL_API_KEY` env var
118
+ - **Multi-tenant support** — JWT auth, per-user camera permissions, admin user management (`CCTVQL_MULTI_TENANT=1`)
119
+ - **Anomaly detection** — statistical spike/silence detection per camera; ask "anything unusual today?"
120
+ - **Demo adapter** — try cctvQL without any hardware; realistic mock data built-in
121
+ - **Interactive CLI** — terminal-based conversational REPL
122
+ - **Real-time events** — MQTT subscription for live alerts (Frigate)
123
+ - **Home Assistant integration** — native custom integration with sensors, binary sensors (per-camera motion), PTZ and query services; installable via HACS
124
+ - **Docker-ready** — running in under 5 minutes with persistent SQLite storage
125
+
126
+ ---
127
+
128
+ ## Screenshots
129
+
130
+ <div align="center">
131
+
132
+ **Web UI — landing**
133
+ ![cctvQL landing screen showing camera sidebar and example query chips](docs/screenshots/01_landing.png)
134
+
135
+ **Camera list query**
136
+ ![Response showing all 4 cameras with status and zones](docs/screenshots/02_camera_list.png)
137
+
138
+ **Event history**
139
+ ![Recent motion events on the Front Door camera with timestamps and confidence scores](docs/screenshots/03_events.png)
140
+
141
+ **Alert rule creation**
142
+ ![Natural language alert setup — person detected after 10pm](docs/screenshots/04_alert_setup.png)
143
+
144
+ **Multi-turn conversation with vision AI**
145
+ ![Multi-turn conversation including a GPT-4o Vision analysis of an event snapshot](docs/screenshots/05_conversation.png)
146
+
147
+ </div>
148
+
149
+ ---
150
+
151
+ ## Quick Start
152
+
153
+ ### Try it now — no hardware needed
154
+
155
+ ```bash
156
+ pip install cctvql
157
+ cctvql chat --adapter demo --llm ollama
158
+ ```
159
+
160
+ The demo adapter ships with 4 cameras, 20 realistic events, and 5 clips — no Frigate or ONVIF device required. Use it to explore the query interface, build integrations, or write tests.
161
+
162
+ ### Docker (recommended — 5 minutes)
163
+
164
+ ```bash
165
+ # 1. Clone and configure
166
+ git clone https://github.com/arunrajiah/cctvql.git
167
+ cd cctvql
168
+ cp config/example.yaml config/config.yaml
169
+
170
+ # 2. Edit config/config.yaml with your Frigate URL and LLM settings
171
+ nano config/config.yaml
172
+
173
+ # 3. Start
174
+ docker compose up -d
175
+
176
+ # 4. Try it
177
+ curl -X POST http://localhost:8000/query \
178
+ -H "Content-Type: application/json" \
179
+ -d '{"query": "Show me all cameras"}'
180
+ ```
181
+
182
+ API docs: `http://localhost:8000/docs`
183
+
184
+ ### pip
185
+
186
+ ```bash
187
+ pip install cctvql
188
+
189
+ # Interactive chat
190
+ cctvql chat --config config/config.yaml
191
+
192
+ # REST API server
193
+ cctvql serve --config config/config.yaml --port 8000
194
+ ```
195
+
196
+ ### From source
197
+
198
+ ```bash
199
+ git clone https://github.com/arunrajiah/cctvql.git
200
+ cd cctvql
201
+ pip install -e ".[dev,mqtt,onvif]"
202
+ cctvql chat
203
+ ```
204
+
205
+ ---
206
+
207
+ ## Documentation
208
+
209
+ | Topic | Link |
210
+ |-------|-------|
211
+ | Configuration reference | [docs/configuration.md](docs/configuration.md) |
212
+ | REST API reference | [docs/api.md](docs/api.md) |
213
+ | Notifications setup | [docs/notifications.md](docs/notifications.md) |
214
+ | Session & event persistence | [docs/persistence.md](docs/persistence.md) |
215
+ | Writing an adapter | [docs/adapters.md](docs/adapters.md) |
216
+ | LLM backend setup | [docs/llm-backends.md](docs/llm-backends.md) |
217
+ | Home Assistant integration | [docs/home-assistant.md](docs/home-assistant.md) |
218
+ | Docker deployment | [docs/docker.md](docs/docker.md) |
219
+ | Frigate + cctvQL sidecar | [deploy/frigate-sidecar/](deploy/frigate-sidecar/) |
220
+ | Troubleshooting | [docs/troubleshooting.md](docs/troubleshooting.md) |
221
+
222
+ ---
223
+
224
+ ## Supported Systems
225
+
226
+ | System | Type | Adapter | Status |
227
+ |--------|------|---------|--------|
228
+ | [Frigate NVR](https://frigate.video) | NVR | `frigate` | ✅ Full support (REST + MQTT) — [sidecar template](deploy/frigate-sidecar/) |
229
+ | Any ONVIF camera/NVR | Camera/NVR | `onvif` | ✅ Full support |
230
+ | Demo / Mock | Built-in | `demo` | ✅ No hardware needed — try cctvQL now |
231
+ | Hikvision | NVR/Camera | `hikvision` | ✅ Full support (ISAPI) |
232
+ | Dahua | NVR/Camera | `dahua` | ✅ Full support (CGI) |
233
+ | [Synology Surveillance Station](https://www.synology.com/en-global/surveillance) | NVR | `synology` | ✅ Full support (Web API) |
234
+ | [Milestone XProtect](https://www.milestonesys.com/) | Enterprise NVR | `milestone` | ✅ Full support (REST API) |
235
+ | [Scrypted](https://scrypted.app) | Smart home NVR | `scrypted` | ✅ Full support (Bearer token) |
236
+ | **Your system** | Any | — | [Write an adapter!](docs/adapters.md) |
237
+
238
+ > Writing an adapter takes ~100 lines. See the [adapter guide](docs/adapters.md).
239
+
240
+ ---
241
+
242
+ ## Supported LLM Backends
243
+
244
+ | Backend | Privacy | Cost | Quality |
245
+ |---------|---------|------|---------|
246
+ | [Ollama](https://ollama.com) (llama3, mistral, phi3…) | 🔒 100% local | Free | ⭐⭐⭐⭐ |
247
+ | OpenAI (gpt-4o-mini, gpt-4o) | ☁️ Cloud | Paid | ⭐⭐⭐⭐⭐ |
248
+ | Anthropic (claude-haiku, claude-sonnet) | ☁️ Cloud | Paid | ⭐⭐⭐⭐⭐ |
249
+ | [LM Studio](https://lmstudio.ai) | 🔒 Local | Free | ⭐⭐⭐⭐ |
250
+ | Any OpenAI-compatible API | Varies | Varies | Varies |
251
+
252
+ **Recommended for privacy:** Ollama with `llama3` or `mistral`. No data leaves your network.
253
+
254
+ ---
255
+
256
+ ## Configuration
257
+
258
+ ```yaml
259
+ # config/config.yaml
260
+ llm:
261
+ active: ollama
262
+ backends:
263
+ ollama:
264
+ provider: ollama
265
+ host: http://localhost:11434
266
+ model: llama3
267
+
268
+ adapters:
269
+ active: frigate
270
+ systems:
271
+ frigate:
272
+ type: frigate
273
+ host: http://192.168.1.100:5000
274
+ mqtt_host: 192.168.1.100 # optional, for real-time events
275
+
276
+ # Optional: alert notifications (any combination of channels)
277
+ notifications:
278
+ telegram:
279
+ bot_token: "123456:ABC-DEF..."
280
+ chat_id: "-1001234567890"
281
+ slack:
282
+ webhook_url: "https://hooks.slack.com/services/..."
283
+ ntfy:
284
+ topic: my-cctvql-alerts
285
+ ```
286
+
287
+ **Database path** (conversation history + event log):
288
+ ```bash
289
+ export CCTVQL_DB_PATH=/data/cctvql.db
290
+ ```
291
+
292
+ See [docs/configuration.md](docs/configuration.md) for the full reference.
293
+ Notification channels: [docs/notifications.md](docs/notifications.md).
294
+ Session persistence: [docs/persistence.md](docs/persistence.md).
295
+
296
+ ---
297
+
298
+ ## REST API
299
+
300
+ ```bash
301
+ # Natural language query (multi-turn, session history persisted to SQLite)
302
+ POST /query
303
+ {"query": "Did anyone come to the front door after midnight?", "session_id": "my-session"}
304
+
305
+ # List cameras
306
+ GET /cameras
307
+
308
+ # Get events with filters
309
+ GET /events?camera=driveway&label=person&limit=10
310
+
311
+ # Export events as CSV or JSON
312
+ GET /events/export
313
+ GET /events/export?fmt=json&camera=Front+Door&label=person
314
+
315
+ # PTZ control (pan/tilt/zoom)
316
+ POST /cameras/{camera_id}/ptz
317
+ {"action": "left", "speed": 50}
318
+
319
+ # PTZ presets
320
+ GET /cameras/{camera_id}/ptz/presets
321
+
322
+ # System health
323
+ GET /health
324
+
325
+ # Per-camera health status
326
+ GET /health/cameras
327
+
328
+ # Alert rules (CRUD)
329
+ GET /alerts
330
+ POST /alerts
331
+ GET /alerts/{id}
332
+ PATCH /alerts/{id}
333
+ DELETE /alerts/{id}
334
+
335
+ # Anomaly detection (statistical spike/silence analysis)
336
+ GET /anomalies
337
+ GET /anomalies?hours=6&camera=Front+Door&threshold=1.5
338
+
339
+ # Prometheus metrics (for Grafana / alerting)
340
+ GET /metrics
341
+
342
+ # Clear conversation session (also removes from database)
343
+ DELETE /sessions/{session_id}
344
+ ```
345
+
346
+ Real-time event streaming via WebSocket:
347
+ ```
348
+ ws://localhost:8000/ws/events
349
+ ```
350
+
351
+ Optional API key auth — set `CCTVQL_API_KEY` env var to require `X-API-Key` header on all requests.
352
+
353
+ Interactive Swagger docs available at `http://localhost:8000/docs`.
354
+
355
+ See [docs/api.md](docs/api.md) for full endpoint documentation.
356
+
357
+ ---
358
+
359
+ ## Architecture
360
+
361
+ ```
362
+ ┌─────────────────────────────────────────────────────────┐
363
+ │ User Interface │
364
+ │ CLI Chat │ REST API │ Home Assistant │
365
+ └─────────────────────────┬───────────────────────────────┘
366
+ │
367
+ ┌─────────────────────────▼───────────────────────────────┐
368
+ │ NLP Engine │
369
+ │ Natural Language → QueryContext (intent + params) │
370
+ └─────────────────────────┬───────────────────────────────┘
371
+ │
372
+ ┌──────────────▼──────────────┐
373
+ │ LLM Registry │
374
+ │ Ollama │ OpenAI │ Anthropic │
375
+ └──────────────┬──────────────┘
376
+ │
377
+ ┌─────────────────────────▼───────────────────────────────┐
378
+ │ Query Router │
379
+ │ Routes intent to adapter → formats human response │
380
+ └─────────────────────────┬───────────────────────────────┘
381
+ │
382
+ ┌──────────────▼──────────────┐
383
+ │ Adapter Registry │
384
+ │ Frigate │ ONVIF │ Your NVR │
385
+ └──────────────┬──────────────┘
386
+ │
387
+ ┌─────────────────────────▼───────────────────────────────┐
388
+ │ Your CCTV System │
389
+ │ NVR / IP Cameras / Recording Storage │
390
+ └─────────────────────────────────────────────────────────┘
391
+ ```
392
+
393
+ ---
394
+
395
+ ## Project Structure
396
+
397
+ ```
398
+ cctvql/
399
+ ├── cctvql/
400
+ │ ├── core/
401
+ │ │ ├── schema.py # Vendor-agnostic data models
402
+ │ │ ├── nlp_engine.py # Natural language → QueryContext
403
+ │ │ └── query_router.py # QueryContext → adapter → response
404
+ │ ├── adapters/
405
+ │ │ ├── base.py # BaseAdapter interface (implement to add a system)
406
+ │ │ ├── frigate.py # Frigate NVR (REST + MQTT)
407
+ │ │ └── onvif.py # Generic ONVIF adapter
408
+ │ ├── llm/
409
+ │ │ ├── base.py # BaseLLM interface + LLMRegistry
410
+ │ │ ├── ollama_backend.py # Local LLM via Ollama
411
+ │ │ ├── openai_backend.py # OpenAI / compatible APIs
412
+ │ │ └── anthropic_backend.py
413
+ │ ├── interfaces/
414
+ │ │ ├── cli.py # Interactive terminal chat
415
+ │ │ └── rest_api.py # FastAPI REST server
416
+ │ ├── _bootstrap.py # Config loader and wiring
417
+ │ └── __main__.py # Entry point (cctvql chat / serve)
418
+ ├── config/
419
+ │ └── example.yaml # Annotated config reference
420
+ ├── docs/ # Full documentation
421
+ ├── tests/
422
+ ├── Dockerfile
423
+ ├── docker-compose.yml
424
+ └── pyproject.toml
425
+ ```
426
+
427
+ ---
428
+
429
+ ## Contributing
430
+
431
+ Contributions are what make cctvQL useful for everyone. The single highest-impact contribution is **writing an adapter** for a CCTV system you already have.
432
+
433
+ ```bash
434
+ git clone https://github.com/arunrajiah/cctvql.git
435
+ cd cctvql
436
+ pip install -e ".[dev,mqtt,onvif]"
437
+ pytest tests/ # all tests should pass
438
+ ```
439
+
440
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full guide.
441
+
442
+ ```bash
443
+ # Common developer commands
444
+ make dev # install with all extras + pre-commit hooks
445
+ make test # run test suite
446
+ make coverage # tests + coverage report
447
+ make lint # ruff linter
448
+ make type-check # mypy
449
+ make demo # interactive demo (no real hardware needed)
450
+ ```
451
+
452
+ **Most wanted contributions:**
453
+ - Hikvision adapter
454
+ - Dahua adapter
455
+ - Synology Surveillance Station adapter
456
+ - Vision-based event description (send snapshot to LLM)
457
+ - Home Assistant custom integration
458
+
459
+ ---
460
+
461
+ ## FAQ
462
+
463
+ **Does my camera data leave my network?**
464
+ Only if you use a cloud LLM backend (OpenAI, Anthropic). With Ollama, everything — including the AI processing — stays on your local machine.
465
+
466
+ **Which Frigate version is supported?**
467
+ Frigate 0.12+ is tested. Most features work with 0.9+.
468
+
469
+ **Can I use this with any ONVIF camera?**
470
+ Yes. ONVIF Profile S is supported for live streaming and snapshots. Profile G adds recording/clip support.
471
+
472
+ **Can I query multiple camera systems at once?**
473
+ Yes — use `"multi": true` in your query request to fan out across all registered adapters simultaneously.
474
+
475
+ **Is there a Home Assistant integration?**
476
+ A native Home Assistant custom integration is planned. For now, use the REST API endpoint from HA automations.
477
+
478
+ ---
479
+
480
+ ## Roadmap
481
+
482
+ - [x] Vision analysis — pass event snapshots to multimodal LLMs for rich descriptions
483
+ - [x] Hikvision adapter
484
+ - [x] Dahua adapter
485
+ - [x] Web UI (lightweight chat interface)
486
+ - [x] Multi-system queries (query across multiple NVRs simultaneously)
487
+ - [x] Alert rules via natural language ("notify me when a person enters Zone A after 10pm")
488
+ - [x] Voice interface (Whisper STT + TTS output)
489
+ - [x] Multi-channel notifications — Telegram, Slack, ntfy, email, webhook
490
+ - [x] PTZ control via REST API (pan, tilt, zoom, presets)
491
+ - [x] Session persistence — conversation history survives server restarts (SQLite)
492
+ - [x] Event log — every detection written to SQLite; exportable as CSV/JSON
493
+ - [x] Camera health monitoring — per-camera online/offline status with background polling
494
+ - [x] Prometheus metrics — cameras online/offline, alert rule count
495
+ - [x] Home Assistant custom integration — sensors, binary sensors, services, HACS-ready
496
+ - [x] ONVIF discovery — auto-detect cameras on the local network (`cctvql discover` CLI + `GET /discover/onvif`)
497
+ - [x] Event timeline UI — visual heatmap timeline at `/timeline` with camera rows, time buckets, tooltips, auto-refresh
498
+ - [ ] Face recognition — identify known individuals across camera feeds
499
+ - [x] Anomaly detection — statistical spike/silence detection per camera with z-score baseline (`GET /anomalies`)
500
+ - [x] Multi-tenant support — JWT auth, per-user camera permissions, admin user management (`CCTVQL_MULTI_TENANT=1`)
501
+ - [ ] Mobile app (React Native)
502
+
503
+ ---
504
+
505
+ ## License
506
+
507
+ MIT © 2026 [arunrajiah](https://github.com/arunrajiah)
508
+
509
+ See [LICENSE](LICENSE) for the full text.
510
+
511
+ ---
512
+
513
+ <div align="center">
514
+ If cctvQL is useful to you, please ⭐ the repo — it helps others find it!
515
+ </div>