pyneolink 0.3.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 (65) hide show
  1. pyneolink-0.3.0/CHANGELOG.md +26 -0
  2. pyneolink-0.3.0/LICENSE +21 -0
  3. pyneolink-0.3.0/MANIFEST.in +11 -0
  4. pyneolink-0.3.0/PKG-INFO +377 -0
  5. pyneolink-0.3.0/README.md +341 -0
  6. pyneolink-0.3.0/config.example.json +13 -0
  7. pyneolink-0.3.0/docs/00-index.md +17 -0
  8. pyneolink-0.3.0/docs/01-core-map.md +117 -0
  9. pyneolink-0.3.0/docs/02-connection-flow.md +129 -0
  10. pyneolink-0.3.0/docs/03-authentication-and-encryption.md +138 -0
  11. pyneolink-0.3.0/docs/04-baichuan-messages.md +146 -0
  12. pyneolink-0.3.0/docs/05-internal-helpers.md +83 -0
  13. pyneolink-0.3.0/docs/05-udp-p2p-transport.md +186 -0
  14. pyneolink-0.3.0/docs/06-sd-card-downloads.md +166 -0
  15. pyneolink-0.3.0/docs/07-media-and-streaming.md +159 -0
  16. pyneolink-0.3.0/docs/08-motion-voice-and-controls.md +103 -0
  17. pyneolink-0.3.0/examples/README.md +31 -0
  18. pyneolink-0.3.0/examples/battery_example.py +62 -0
  19. pyneolink-0.3.0/examples/camera_example.py +58 -0
  20. pyneolink-0.3.0/examples/motion_example.py +43 -0
  21. pyneolink-0.3.0/examples/record_example.py +50 -0
  22. pyneolink-0.3.0/examples/sd_card_example.py +80 -0
  23. pyneolink-0.3.0/examples/settings_example.py +89 -0
  24. pyneolink-0.3.0/examples/stream_example.py +53 -0
  25. pyneolink-0.3.0/examples/voice_example.py +59 -0
  26. pyneolink-0.3.0/pyneolink/__init__.py +43 -0
  27. pyneolink-0.3.0/pyneolink/battery.py +136 -0
  28. pyneolink-0.3.0/pyneolink/camera.py +491 -0
  29. pyneolink-0.3.0/pyneolink/cli.py +419 -0
  30. pyneolink-0.3.0/pyneolink/config.py +96 -0
  31. pyneolink-0.3.0/pyneolink/core/__init__.py +5 -0
  32. pyneolink-0.3.0/pyneolink/core/bc.py +203 -0
  33. pyneolink-0.3.0/pyneolink/core/const/__init__.py +6 -0
  34. pyneolink-0.3.0/pyneolink/core/const/flags.py +75 -0
  35. pyneolink-0.3.0/pyneolink/core/const/msg.py +116 -0
  36. pyneolink-0.3.0/pyneolink/core/const/payloads.py +367 -0
  37. pyneolink-0.3.0/pyneolink/core/crypto.py +82 -0
  38. pyneolink-0.3.0/pyneolink/core/discovery.py +186 -0
  39. pyneolink-0.3.0/pyneolink/core/media.py +181 -0
  40. pyneolink-0.3.0/pyneolink/core/state.py +38 -0
  41. pyneolink-0.3.0/pyneolink/core/udp_transport.py +604 -0
  42. pyneolink-0.3.0/pyneolink/core/xmlutil.py +36 -0
  43. pyneolink-0.3.0/pyneolink/internal/__init__.py +1 -0
  44. pyneolink-0.3.0/pyneolink/internal/battery.py +99 -0
  45. pyneolink-0.3.0/pyneolink/internal/camera.py +63 -0
  46. pyneolink-0.3.0/pyneolink/internal/snapshot.py +31 -0
  47. pyneolink-0.3.0/pyneolink/internal/voice.py +488 -0
  48. pyneolink-0.3.0/pyneolink/motion.py +254 -0
  49. pyneolink-0.3.0/pyneolink/recorder.py +163 -0
  50. pyneolink-0.3.0/pyneolink/sd_card.py +1329 -0
  51. pyneolink-0.3.0/pyneolink/settings/__init__.py +14 -0
  52. pyneolink-0.3.0/pyneolink/settings/ir.py +107 -0
  53. pyneolink-0.3.0/pyneolink/settings/pir.py +104 -0
  54. pyneolink-0.3.0/pyneolink/stream_server.py +765 -0
  55. pyneolink-0.3.0/pyneolink/voice.py +227 -0
  56. pyneolink-0.3.0/pyneolink.egg-info/PKG-INFO +377 -0
  57. pyneolink-0.3.0/pyneolink.egg-info/SOURCES.txt +63 -0
  58. pyneolink-0.3.0/pyneolink.egg-info/dependency_links.txt +1 -0
  59. pyneolink-0.3.0/pyneolink.egg-info/entry_points.txt +2 -0
  60. pyneolink-0.3.0/pyneolink.egg-info/requires.txt +9 -0
  61. pyneolink-0.3.0/pyneolink.egg-info/top_level.txt +1 -0
  62. pyneolink-0.3.0/pyproject.toml +72 -0
  63. pyneolink-0.3.0/requirements.txt +2 -0
  64. pyneolink-0.3.0/setup.cfg +4 -0
  65. pyneolink-0.3.0/tests/test_protocol.py +1548 -0
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 - Unreleased
4
+
5
+ Initial public alpha preparation.
6
+
7
+ ### Added
8
+
9
+ - UID/P2P camera connection with local, relay, and cached address paths.
10
+ - Baichuan login, command framing, BC XOR, and AES-CFB support.
11
+ - Camera info, UID, reboot, snapshot, LED/IR compatibility commands.
12
+ - SD-card listing with pagination and high/low recording download.
13
+ - Battery status with reconnect and online polling modes.
14
+ - Live MPEG-TS stream server and HLS timeshift buffer.
15
+ - Local MPEG-TS recording from live streams.
16
+ - Motion status and motion event watch mode.
17
+ - Voice/talk from microphone, audio file, or generated tone.
18
+ - Built-in siren trigger.
19
+ - Settings facade with PIR and IR light controls.
20
+ - CLI and SDK examples.
21
+
22
+ ### Notes
23
+
24
+ - This release is experimental and reverse engineered.
25
+ - Tested on a limited number of Reolink cameras.
26
+ - API compatibility is not guaranteed before `1.0.0`.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AlzGamer
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.
@@ -0,0 +1,11 @@
1
+ include README.md
2
+ include LICENSE
3
+ include CHANGELOG.md
4
+ include config.example.json
5
+ include requirements.txt
6
+ recursive-include docs *.md
7
+ recursive-include examples *.py *.md
8
+ recursive-include tests *.py
9
+ global-exclude __pycache__
10
+ global-exclude *.py[cod]
11
+ global-exclude .DS_Store
@@ -0,0 +1,377 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyneolink
3
+ Version: 0.3.0
4
+ Summary: Experimental Python client for Reolink cameras
5
+ Author-email: AlzGamer <dev@alzgamer.pro>
6
+ Maintainer-email: AlzGamer <dev@alzgamer.pro>
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://github.com/alzgamer-kr/pyneolink
9
+ Project-URL: Repository, https://github.com/alzgamer-kr/pyneolink
10
+ Project-URL: Issues, https://github.com/alzgamer-kr/pyneolink/issues
11
+ Project-URL: Changelog, https://github.com/alzgamer-kr/pyneolink/blob/main/CHANGELOG.md
12
+ Keywords: reolink,neolink,baichuan,camera,p2p,uid,ip-camera,security-camera
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Multimedia :: Video
23
+ Classifier: Topic :: System :: Networking
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.11
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: cryptography>=42
29
+ Provides-Extra: voice
30
+ Requires-Dist: sounddevice>=0.4; extra == "voice"
31
+ Provides-Extra: dev
32
+ Requires-Dist: build>=1.2; extra == "dev"
33
+ Requires-Dist: pytest>=8; extra == "dev"
34
+ Requires-Dist: twine>=5; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # PyNeolink
38
+
39
+ PyNeolink is a Python client for Reolink/Neolink-style Baichuan cameras. It focuses on UID/P2P access, camera information, SD-card recordings, live viewing, snapshots, local recording, motion events, battery status, voice/talk, and siren control.
40
+
41
+ Version: `0.3.0` alpha.
42
+
43
+ This project was developed with OpenAI Codex as an AI-assisted implementation effort. It is a Python port inspired by and based on protocol knowledge from the Rust `neolink` project, especially `QuantumEntangledAndy/neolink` and `surfzoid/neolink`. The reverse-engineering foundation belongs to the Neolink contributors. The goal is not to replace Neolink, but to make a working Python implementation available for people who want to study, adapt, or extend this protocol without working in Rust.
44
+
45
+ Neolink and Reolink protocol support are reverse engineered. This project is not affiliated with Reolink.
46
+
47
+ ## Status
48
+
49
+ PyNeolink is experimental alpha software. It works against a limited set of real cameras, but Reolink firmware and model behavior can differ. APIs may change before `1.0.0`.
50
+
51
+ ## What Works
52
+
53
+ - JSON camera configuration with `address` or `uid`
54
+ - Reolink UID/P2P lookup, registration, UDP relay, and local UDP connection
55
+ - Baichuan login and command framing
56
+ - BC XOR encryption and AES-CFB support through `cryptography`
57
+ - Camera information, UID, LED command, and reboot command
58
+ - Battery status, including reconnect and online polling modes
59
+ - SD-card recording list with pagination and time sorting
60
+ - SD-card recording download with high/low quality selection
61
+ - Snapshot download to bytes or JPEG file
62
+ - Local MPEG-TS recording from the live stream
63
+ - Live HTTP MPEG-TS viewing with H264/H265 video and AAC audio
64
+ - HLS timeshift viewing with an in-memory sliding buffer
65
+ - Motion status and motion event watch mode
66
+ - Two-way voice/talk from microphone, audio file, or generated test tone
67
+ - Camera siren trigger
68
+ - PIR status and PIR on/off settings
69
+ - IR light status and IR on/off/auto settings
70
+
71
+ ## Current Limits
72
+
73
+ - This is reverse engineered and tested against a small number of real cameras, so behavior may differ between models and firmware versions.
74
+ - Voice file playback uses `ffmpeg`/`ffprobe` for format validation and conversion. Install FFmpeg and make sure both commands are available in `PATH`.
75
+ - Microphone voice input needs the Python `sounddevice` package and a working local input device.
76
+ - Local stream recording writes MPEG-TS (`.ts`) files, not MP4.
77
+ - SD-card `remove()` and `format()` exist, but are intentionally guarded.
78
+ - PTZ, image settings, alarm schedules, floodlight settings, and Web UI are not implemented yet.
79
+
80
+ ## Install
81
+
82
+ From GitHub, before PyPI publication:
83
+
84
+ ```powershell
85
+ python -m pip install git+https://github.com/alzgamer-kr/pyneolink.git
86
+ ```
87
+
88
+ From PyPI, after publication:
89
+
90
+ ```powershell
91
+ python -m pip install pyneolink
92
+ ```
93
+
94
+ For microphone voice input:
95
+
96
+ ```powershell
97
+ python -m pip install "pyneolink[voice]"
98
+ ```
99
+
100
+ For local development from a checkout:
101
+
102
+ ```powershell
103
+ python -m venv .venv
104
+ .venv\Scripts\activate
105
+ python -m pip install -r requirements.txt
106
+ ```
107
+
108
+ The `cryptography` package is required for AES-encrypted cameras. It is installed automatically when installing the package.
109
+
110
+ ## FFmpeg
111
+
112
+ FFmpeg is a system dependency for audio-file voice playback and some media conversion paths. PyNeolink expects both `ffmpeg` and `ffprobe` to be available in `PATH`.
113
+
114
+ Official FFmpeg download page:
115
+
116
+ - Windows: https://ffmpeg.org/download.html
117
+ - Linux: https://ffmpeg.org/download.html
118
+ - macOS: https://ffmpeg.org/download.html
119
+
120
+ On Linux and macOS, using the OS package manager is usually the simplest path when available. On Windows, install one of the builds linked from the official FFmpeg download page and add its `bin` directory to `PATH`.
121
+
122
+ ## Configuration
123
+
124
+ Create a local `config.json`:
125
+
126
+ ```json
127
+ {
128
+ "bind": "0.0.0.0",
129
+ "bind_port": 8554,
130
+ "cameras": [
131
+ {
132
+ "name": "Home-Front",
133
+ "username": "admin",
134
+ "password": "password",
135
+ "uid": "ABCDEF0123456789",
136
+ "discovery": "relay"
137
+ }
138
+ ]
139
+ }
140
+ ```
141
+
142
+ `config.json` is ignored by Git because it can contain camera credentials.
143
+
144
+ ## CLI
145
+
146
+ Camera info:
147
+
148
+ ```powershell
149
+ python pyneolink/cli.py info --camera "Home-Front" --config config.json
150
+ python pyneolink/cli.py --info --camera "Home-Front"
151
+ ```
152
+
153
+ Battery:
154
+
155
+ ```powershell
156
+ python pyneolink/cli.py battery --camera "Home-Front"
157
+ python pyneolink/cli.py battery --camera "Home-Front" --watch --interval 60
158
+ python pyneolink/cli.py battery --camera "Home-Front" --watch --interval 60 --mode online
159
+ ```
160
+
161
+ Snapshots and local recording:
162
+
163
+ ```powershell
164
+ python pyneolink/cli.py snapshot --camera "Home-Front" --out snapshots/
165
+ python pyneolink/cli.py record --camera "Home-Front" --out recordings/ --duration 30 --quality high
166
+ python pyneolink/cli.py record --camera "Home-Front" --out recordings/live.ts --quality low
167
+ ```
168
+
169
+ Motion:
170
+
171
+ ```powershell
172
+ python pyneolink/cli.py motion --camera "Home-Front"
173
+ python pyneolink/cli.py motion --camera "Home-Front" --watch --duration 30
174
+ ```
175
+
176
+ PIR:
177
+
178
+ ```powershell
179
+ python pyneolink/cli.py pir --config config.json --camera "Home-Front" status
180
+ python pyneolink/cli.py pir --config config.json --camera "Home-Front" on
181
+ python pyneolink/cli.py pir --config config.json --camera "Home-Front" off
182
+ ```
183
+
184
+ IR light:
185
+
186
+ ```powershell
187
+ python pyneolink/cli.py ir --config config.json --camera "Home-Front" status
188
+ python pyneolink/cli.py ir --config config.json --camera "Home-Front" on
189
+ python pyneolink/cli.py ir --config config.json --camera "Home-Front" off
190
+ python pyneolink/cli.py ir --config config.json --camera "Home-Front" auto
191
+ python pyneolink/cli.py led --config config.json --camera "Home-Front" auto
192
+ ```
193
+
194
+ Voice and siren:
195
+
196
+ ```powershell
197
+ python pyneolink/cli.py voice --camera "Home-Front" --file alert.mp3
198
+ python pyneolink/cli.py voice --camera "Home-Front" --microphone --seconds 10
199
+ python pyneolink/cli.py voice --camera "Home-Front" --tone 1000 --seconds 3
200
+ python pyneolink/cli.py voice --camera "Home-Front" --siren
201
+ ```
202
+
203
+ Live view server:
204
+
205
+ ```powershell
206
+ python pyneolink/cli.py serve --config config.json
207
+ ```
208
+
209
+ Open direct MPEG-TS in VLC/ffplay:
210
+
211
+ ```text
212
+ http://127.0.0.1:8554/Home-Front/high
213
+ http://127.0.0.1:8554/Home-Front/low
214
+ ```
215
+
216
+ Open HLS timeshift in VLC/ffplay:
217
+
218
+ ```text
219
+ http://127.0.0.1:8554/Home-Front/high/hls.m3u8
220
+ http://127.0.0.1:8554/Home-Front/low/hls.m3u8
221
+ ```
222
+
223
+ HLS keeps a sliding in-memory buffer. By default it stores up to 100 MB and cuts segments around 2 seconds:
224
+
225
+ ```powershell
226
+ python pyneolink/cli.py serve --config config.json --hls-buffer-mb 100 --hls-segment-seconds 2
227
+ ```
228
+
229
+ When binding to `0.0.0.0`, do not open `0.0.0.0` in VLC. Use `127.0.0.1` on the same PC or the PC's LAN IP from another device.
230
+
231
+ ## Library Use
232
+
233
+ Camera information:
234
+
235
+ ```python
236
+ from pyneolink import Camera
237
+
238
+ with Camera(uuid="ABCDEF0123456789", username="admin", password="password") as camera:
239
+ info = camera.info()
240
+ print(info)
241
+ ```
242
+
243
+ Battery:
244
+
245
+ ```python
246
+ from pyneolink import Camera
247
+
248
+ with Camera(uuid="ABCDEF0123456789", username="admin", password="password") as camera:
249
+ battery = camera.battery()
250
+
251
+ with battery.info() as info:
252
+ print(info["level_percent"], info["is_charging"], info["adapter_status"])
253
+
254
+ with battery.info(interval=60, mode="reconnect", count=3) as updates:
255
+ for update in updates:
256
+ print(update["level_percent"], update["adapter_status"])
257
+ ```
258
+
259
+ SD-card download:
260
+
261
+ ```python
262
+ from pyneolink import Camera
263
+
264
+ with Camera(uuid="ABCDEF0123456789", username="admin", password="password") as camera:
265
+ sd = camera.sd_card()
266
+ files = sd.list(start="2026-06-03", end="2026-06-03")
267
+ videos = sd.filter(files, name=".mp4")
268
+ if videos:
269
+ sd.download(videos[-1], "downloads", quality="high", progress=True)
270
+ ```
271
+
272
+ Motion:
273
+
274
+ ```python
275
+ from pyneolink import Camera, EVENTS
276
+
277
+ with Camera(uuid="ABCDEF0123456789", username="admin", password="password") as camera:
278
+ motion = camera.motion()
279
+ print(motion.status())
280
+
281
+ with motion.watch(duration=30) as events:
282
+ for event in events:
283
+ if event == EVENTS.human and event.active:
284
+ print("human detected")
285
+ ```
286
+
287
+ Snapshot and local recording:
288
+
289
+ ```python
290
+ from pyneolink import Camera
291
+
292
+ with Camera(uuid="ABCDEF0123456789", username="admin", password="password") as camera:
293
+ camera.snapshot(out="snapshots")
294
+ camera.record(out="recordings", duration=30, stream="mainStream")
295
+ ```
296
+
297
+ Voice and siren:
298
+
299
+ ```python
300
+ from pyneolink import Camera
301
+
302
+ with Camera(uuid="ABCDEF0123456789", username="admin", password="password") as camera:
303
+ voice = camera.voice()
304
+ voice.play("alert.mp3")
305
+ voice.siren()
306
+ ```
307
+
308
+ Settings and PIR:
309
+
310
+ ```python
311
+ from pyneolink import Camera
312
+
313
+ with Camera(uuid="ABCDEF0123456789", username="admin", password="password") as camera:
314
+ settings = camera.settings()
315
+ print(settings.pir.status())
316
+ settings.pir.on()
317
+ settings.pir.off()
318
+ print(settings.ir.status())
319
+ settings.ir.on()
320
+ settings.ir.off()
321
+ settings.ir.auto()
322
+ ```
323
+
324
+ Live stream server from a dict:
325
+
326
+ ```python
327
+ from pyneolink import StreamServer
328
+
329
+ config = {
330
+ "bind": "0.0.0.0",
331
+ "bind_port": 8554,
332
+ "cameras": [
333
+ {
334
+ "name": "Home-Front",
335
+ "username": "admin",
336
+ "password": "password",
337
+ "uid": "ABCDEF0123456789",
338
+ "discovery": "relay",
339
+ }
340
+ ],
341
+ }
342
+
343
+ StreamServer(config, buffer_seconds=1.5, hls_buffer_mb=100, hls_segment_seconds=2).serve_forever()
344
+ ```
345
+
346
+ ## Examples
347
+
348
+ See the `examples/` directory:
349
+
350
+ - `camera_example.py`: info, snapshot, LED, and guarded reboot helpers
351
+ - `sd_card_example.py`: list, filter, download, remove, and guarded format calls
352
+ - `battery_example.py`: one-shot battery status plus reconnect/online polling
353
+ - `motion_example.py`: motion status and watch mode
354
+ - `record_example.py`: duration and manual local stream recording
355
+ - `voice_example.py`: file, microphone, tone, and siren helpers
356
+ - `settings_example.py`: PIR and IR status plus guarded setting helpers
357
+ - `stream_example.py`: live MPEG-TS and HLS timeshift server from a dict config
358
+
359
+ Each example keeps camera settings as a small local dict near the top of the file. Edit those values directly or replace the dict with your own configuration loader.
360
+
361
+ ## Internals
362
+
363
+ See `docs/` for a sorted internal documentation set that explains the core files, connection flow, login, encryption, Baichuan messages, UDP/P2P transport, SD-card downloads, media streaming, motion, voice, and camera controls.
364
+
365
+ ## Credits
366
+
367
+ PyNeolink exists because of the reverse-engineering work done by the Neolink community. In particular, the Rust `neolink` implementations and documentation were used as the protocol reference for this Python port.
368
+
369
+ This Python implementation was developed with OpenAI Codex. Human testing against real cameras guided the implementation and bug fixes.
370
+
371
+ ## Reference
372
+
373
+ The Rust `neolink/` checkout can be kept locally as a protocol reference, but it is ignored by Git in this workspace. The Python code here is intended to be understandable and hackable for people who want to experiment with Reolink cameras from Python.
374
+
375
+ ## Tested Cameras
376
+
377
+ - Reolink Argus Eco