mpytool 2.0.0__tar.gz → 2.1.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 (35) hide show
  1. mpytool-2.1.0/PKG-INFO +451 -0
  2. mpytool-2.1.0/README.md +437 -0
  3. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool/conn.py +29 -0
  4. mpytool-2.1.0/mpytool/conn_serial.py +111 -0
  5. mpytool-2.1.0/mpytool/mpy.py +1299 -0
  6. mpytool-2.1.0/mpytool/mpy_comm.py +281 -0
  7. mpytool-2.1.0/mpytool/mpytool.py +1499 -0
  8. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool/terminal.py +1 -1
  9. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool/utils.py +4 -3
  10. mpytool-2.1.0/mpytool.egg-info/PKG-INFO +451 -0
  11. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool.egg-info/SOURCES.txt +1 -0
  12. {mpytool-2.0.0 → mpytool-2.1.0}/pyproject.toml +4 -1
  13. mpytool-2.1.0/tests/test_integration.py +1323 -0
  14. mpytool-2.1.0/tests/test_mpy.py +434 -0
  15. mpytool-2.1.0/tests/test_mpytool.py +363 -0
  16. {mpytool-2.0.0 → mpytool-2.1.0}/tests/test_utils.py +29 -0
  17. mpytool-2.0.0/PKG-INFO +0 -233
  18. mpytool-2.0.0/README.md +0 -219
  19. mpytool-2.0.0/mpytool/conn_serial.py +0 -34
  20. mpytool-2.0.0/mpytool/mpy.py +0 -337
  21. mpytool-2.0.0/mpytool/mpy_comm.py +0 -152
  22. mpytool-2.0.0/mpytool/mpytool.py +0 -913
  23. mpytool-2.0.0/mpytool.egg-info/PKG-INFO +0 -233
  24. mpytool-2.0.0/tests/test_integration.py +0 -551
  25. mpytool-2.0.0/tests/test_mpy.py +0 -27
  26. {mpytool-2.0.0 → mpytool-2.1.0}/LICENSE +0 -0
  27. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool/__init__.py +0 -0
  28. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool/conn_socket.py +0 -0
  29. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool/logger.py +0 -0
  30. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool.egg-info/dependency_links.txt +0 -0
  31. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool.egg-info/entry_points.txt +0 -0
  32. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool.egg-info/requires.txt +0 -0
  33. {mpytool-2.0.0 → mpytool-2.1.0}/mpytool.egg-info/top_level.txt +0 -0
  34. {mpytool-2.0.0 → mpytool-2.1.0}/setup.cfg +0 -0
  35. {mpytool-2.0.0 → mpytool-2.1.0}/tests/test_errors.py +0 -0
mpytool-2.1.0/PKG-INFO ADDED
@@ -0,0 +1,451 @@
1
+ Metadata-Version: 2.4
2
+ Name: mpytool
3
+ Version: 2.1.0
4
+ Summary: MPY tool - manage files on devices running MicroPython
5
+ Author-email: Pavel Revak <pavel.revak@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/pavelrevak/mpytool
8
+ Keywords: MPY,micropython
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: pyserial>=3.0
13
+ Dynamic: license-file
14
+
15
+ # mpytool
16
+
17
+ MPY tool - manage files on devices running MicroPython
18
+
19
+ It is an alternative to the official [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html).
20
+
21
+ ## Features
22
+
23
+ - **Fast file transfers** - optimized chunked transfer with automatic compression
24
+ - **Skip unchanged files** - compares size + SHA256 hash, re-upload in <1s
25
+ - **Auto-detect serial port** - no need to specify `-p` when only one device connected
26
+ - **Robust REPL handling** - works reliably with USB-UART bridges (CP2102, CH340)
27
+ - **Multiple reset options** - soft, MCU, hardware (RTS), bootloader entry
28
+ - **General-purpose serial terminal** - `repl` and `monitor` work with any serial device
29
+ - **Python API** - suitable for IDE integration and automation
30
+ - **Raw-paste mode** - flow-controlled code execution with reduced RAM usage (API)
31
+ - **Shell completion** - ZSH and Bash with remote path completion
32
+ - **Network support** - connect over TCP
33
+
34
+ ## Installation
35
+
36
+ ```
37
+ pip3 install mpytool
38
+ ```
39
+
40
+ ### Installation from git (latest development version)
41
+
42
+ ```bash
43
+ pip3 install git+https://github.com/pavelrevak/mpytool.git
44
+ ```
45
+
46
+ ### Installation in virtualenv
47
+
48
+ Create a dedicated virtualenv for CLI tools (keeps your system Python clean):
49
+
50
+ ```bash
51
+ # Create virtualenv (once)
52
+ python3 -m venv ~/.venv/tools
53
+
54
+ # Install mpytool
55
+ ~/.venv/tools/bin/pip install mpytool
56
+
57
+ # Run directly
58
+ ~/.venv/tools/bin/mpytool --help
59
+ ```
60
+
61
+ To use `mpytool` command without full path, add the venv bin to end of your PATH:
62
+
63
+ **ZSH** (`~/.zshrc`):
64
+ ```bash
65
+ export PATH="$PATH:$HOME/.venv/tools/bin"
66
+ ```
67
+
68
+ **Bash** (`~/.bashrc`):
69
+ ```bash
70
+ export PATH="$PATH:$HOME/.venv/tools/bin"
71
+ ```
72
+
73
+ Then restart your shell (`exec zsh` or `exec bash`) and use `mpytool` directly.
74
+
75
+ Adding venv bin at the end of PATH keeps your system `python` and `pip` as default, while making `mpytool` available when not found elsewhere.
76
+
77
+ ## Examples:
78
+
79
+ help:
80
+ ```
81
+ $ mpytool --help
82
+ ```
83
+
84
+ list files:
85
+ ```
86
+ $ mpytool -p /dev/ttyACM0 ls
87
+ $ mpytool -p /dev/ttyACM0 ls lib
88
+ ```
89
+
90
+ tree files:
91
+ ```
92
+ $ mpytool -p /dev/ttyACM0 tree
93
+ ```
94
+
95
+ copy files (: prefix = device path):
96
+ ```
97
+ $ mpytool cp main.py :/ # upload file to device root
98
+ $ mpytool cp main.py lib.py :/lib/ # upload multiple files to directory
99
+ $ mpytool cp myapp/ :/ # upload directory (creates /myapp/)
100
+ $ mpytool cp myapp/ :/lib/ # upload directory into /lib/
101
+ $ mpytool cp :/main.py ./ # download file to current directory
102
+ $ mpytool cp :/ ./backup/ # download entire device to backup/
103
+ $ mpytool cp :/old.py :/new.py # copy file on device
104
+ $ mpytool cp -f main.py :/ # force upload even if unchanged
105
+ ```
106
+
107
+ Unchanged files are automatically skipped (compares size and SHA256 hash).
108
+ Use `-f` or `--force` to upload all files regardless.
109
+
110
+ transfer options:
111
+ ```
112
+ $ mpytool cp -z main.py :/ # force compression (auto-detected by default)
113
+ $ mpytool cp --no-compress data.bin :/ # disable compression
114
+ $ mpytool -c 8K cp main.py :/ # set chunk size (512, 1K, 2K, 4K, 8K, 16K, 32K)
115
+ ```
116
+
117
+ Compression is auto-detected based on device RAM and deflate module availability.
118
+ Chunk size is auto-detected based on free RAM (larger chunks = faster transfer).
119
+
120
+ move/rename on device:
121
+ ```
122
+ $ mpytool mv :/old.py :/new.py # rename file
123
+ $ mpytool mv :/file.py :/lib/ # move file to directory
124
+ $ mpytool mv :/a.py :/b.py :/lib/ # move multiple files to directory
125
+ ```
126
+
127
+ legacy upload/download (still available):
128
+ ```
129
+ $ mpytool put boot.py /
130
+ $ mpytool get boot.py >> boot.py
131
+ ```
132
+
133
+ make directory, delete files:
134
+ ```
135
+ $ mpytool mkdir a/b/c/d xyz/abc # create directories
136
+ $ mpytool rm mydir # delete directory and contents
137
+ $ mpytool rm mydir/ # delete contents only, keep directory
138
+ $ mpytool rm / # delete everything on device
139
+ ```
140
+
141
+ reset and REPL:
142
+ ```
143
+ $ mpytool reset # soft reset (Ctrl-D, runs boot.py/main.py)
144
+ $ mpytool sreset # soft reset in raw REPL (clears RAM only)
145
+ $ mpytool mreset # MCU reset (machine.reset, auto-reconnect)
146
+ $ mpytool rtsreset # hardware reset via RTS signal (serial only)
147
+ $ mpytool bootloader # enter bootloader (machine.bootloader)
148
+ $ mpytool dtrboot # enter bootloader via DTR/RTS (ESP32 only)
149
+ $ mpytool reset monitor # reset and monitor output
150
+ $ mpytool repl # enter REPL mode
151
+ $ mpytool sleep 2 # sleep for 2 seconds (useful between commands)
152
+ ```
153
+
154
+ serial terminal and monitor (general purpose):
155
+ ```
156
+ $ mpytool repl # auto-detect port, 115200 baud
157
+ $ mpytool -p /dev/ttyUSB0 repl # specify port
158
+ $ mpytool -b 9600 repl # specify baudrate
159
+ $ mpytool -p /dev/ttyUSB0 -b 9600 monitor # monitor at 9600 baud
160
+ ```
161
+
162
+ Both `repl` and `monitor` can be used as general-purpose serial tools - not just for MicroPython devices. Use them to interact with any serial device (Arduino, ESP with custom firmware, GPS modules, etc.). When only one serial port is detected, it is used automatically. Default baudrate is 115200.
163
+
164
+ execute Python code on device:
165
+ ```
166
+ $ mpytool exec "print('Hello!')"
167
+ $ mpytool exec "import sys; print(sys.version)"
168
+ ```
169
+
170
+ show device information:
171
+ ```
172
+ $ mpytool info
173
+ Platform: rp2
174
+ Version: 3.4.0; MicroPython v1.27.0 on 2025-12-09
175
+ Impl: micropython
176
+ Machine: Raspberry Pi Pico with RP2040
177
+ Serial: e660123456789abc
178
+ Memory: 36.4 KB / 240 KB (15.15%)
179
+ Flash: 120 KB / 1.38 MB (8.52%)
180
+ ```
181
+
182
+ On devices with WiFi or Ethernet, MAC addresses are also shown:
183
+ ```
184
+ MAC WiFi: aa:bb:cc:dd:ee:01
185
+ MAC WiFi AP: aa:bb:cc:dd:ee:02
186
+ ```
187
+
188
+ flash operations (RP2 and ESP32):
189
+ ```
190
+ # RP2 - user flash (entire filesystem area)
191
+ $ mpytool flash # show flash info and filesystem type
192
+ $ mpytool flash read backup.bin # backup entire user flash
193
+ $ mpytool flash write backup.bin # restore from backup
194
+ $ mpytool flash erase # quick erase (reset filesystem)
195
+ $ mpytool flash erase --full # full erase
196
+
197
+ # ESP32 - partitions (by label)
198
+ $ mpytool flash # list all partitions with filesystem info
199
+ Label Type Subtype Address Size Block Actual FS Flags
200
+ ------------------------------------------------------------------------------------------
201
+ factory app factory 0x10000 1.94M running
202
+ nvs data nvs 0x9000 24.0K
203
+ vfs data littlefs 0x200000 2.00M 4 KB littlefs2
204
+
205
+ Boot partition: factory
206
+ Next OTA: (none)
207
+
208
+ $ mpytool flash read vfs backup.bin # backup partition to file
209
+ $ mpytool flash write nvs nvs_backup.bin # restore partition from file
210
+ $ mpytool flash erase vfs # quick erase partition
211
+ $ mpytool flash erase vfs --full # full erase partition
212
+ ```
213
+
214
+ OTA firmware update (ESP32):
215
+ ```
216
+ $ mpytool ota firmware.app-bin # flash to next OTA partition
217
+ $ mpytool ota firmware.app-bin -- mreset # flash and reboot
218
+ ```
219
+
220
+ multiple commands separated by `--`:
221
+ ```
222
+ $ mpytool cp main.py boot.py :/ -- reset -- monitor
223
+ $ mpytool delete old.py -- cp new.py :/ -- reset
224
+ ```
225
+
226
+ auto-detect serial port (if only one device is connected):
227
+ ```
228
+ $ mpytool ls lib/
229
+ uhttp/
230
+ 23.2 KB wlan.py
231
+ 4.95 KB wlan_http.py
232
+ ```
233
+
234
+ tree view:
235
+ ```
236
+ $ mpytool tree
237
+ 142 KB ./
238
+ 41.3 KB ├─ html/
239
+ 587 B │ ├─ index.html
240
+ 40.8 KB │ └─ wlan.html
241
+ 97.7 KB ├─ lib/
242
+ 69.6 KB │ ├─ uhttp/
243
+ 93 B │ │ ├─ __init__.py
244
+ 26.3 KB │ │ ├─ client.py
245
+ 43.2 KB │ │ └─ server.py
246
+ 23.2 KB │ ├─ wlan.py
247
+ 4.95 KB │ └─ wlan_http.py
248
+ 23 B ├─ boot.py
249
+ 3.03 KB └─ main.py
250
+ ```
251
+
252
+ connect over network (TCP, default port 23):
253
+ ```
254
+ $ mpytool -a 192.168.1.100 ls
255
+ $ mpytool -a 192.168.1.100:8266 tree
256
+ ```
257
+
258
+ set baudrate (default 115200):
259
+ ```
260
+ $ mpytool -p /dev/ttyACM0 -b 9600 ls
261
+ ```
262
+
263
+ show version:
264
+ ```
265
+ $ mpytool -V
266
+ ```
267
+
268
+ Command aliases:
269
+ - `dir` = `ls`
270
+ - `cat` = `get`
271
+ - `del`, `rm` = `delete`
272
+ - `follow` = `monitor`
273
+
274
+ ## Python API
275
+
276
+ ```python
277
+ >>> import mpytool
278
+ >>> conn = mpytool.ConnSerial(port='/dev/ttyACM0', baudrate=115200)
279
+ >>> mpy = mpytool.Mpy(conn)
280
+ >>> mpy.ls()
281
+ [('lib', None), ('boot.py', 215), ('main.py', 3102)]
282
+ >>> mpy.get('boot.py')
283
+ b'import machine\nimport time\n...'
284
+ >>> mpy.put(b'print("Hello")', 'test.py')
285
+ >>> mpy.delete('test.py')
286
+ ```
287
+
288
+ Raw-paste mode for efficient code execution (MicroPython 1.17+):
289
+ ```python
290
+ >>> mpy.comm.exec_raw_paste("print('Hello')") # flow-controlled, less RAM
291
+ b'Hello\r\n'
292
+ ```
293
+
294
+ See [README_API.md](README_API.md) for full API documentation.
295
+
296
+ ## Progress and verbose output
297
+
298
+ Progress is shown by default during file transfers:
299
+ ```
300
+ $ mpytool cp main.py lib.py :/lib/
301
+ [1/2] 100% 1.2KB main.py -> :/lib/main.py
302
+ [2/2] 100% 3.4KB lib.py -> :/lib/lib.py
303
+ ```
304
+
305
+ use `-v` or `--verbose` to also show commands being executed:
306
+ ```
307
+ $ mpytool -v rm /old.py
308
+ delete: /old.py
309
+ ```
310
+
311
+ use `-q` or `--quiet` to disable all output:
312
+ ```
313
+ $ mpytool -q cp main.py :/
314
+ ```
315
+
316
+ ## Output Example
317
+
318
+ Complete workflow - upload changed files, reset device, and monitor output:
319
+ ```
320
+ $ mpytool cp ~/Work/mpy/wlan/main.py ~/Work/mpy/wlan/html :/ -- cp ~/Work/mpy/wlan/wlan_http.py ~/Work/mpy/wlan/wlan.py ~/Work/mpy/uhttp/uhttp :/lib/ -- cp ~/Tmp/test0.bin :/lib/ -- reset -- monitor
321
+ COPY (chunk: 16K, compress: on)
322
+ [1/9] 100% 3.03K ../mpy/wlan/main.py -> :/main.py (compressed)
323
+ [2/9] skip 587B ../mpy/wlan/html/index.html -> :/html/index.html (unchanged)
324
+ [3/9] 100% 40.8K ../mpy/wlan/html/wlan.html -> :/html/wlan.html (compressed)
325
+ [4/9] skip 4.95K ../mpy/wlan/wlan_http.py -> :/lib/wlan_http.py (unchanged)
326
+ [5/9] 100% 23.1K ../mpy/wlan/wlan.py -> :/lib/wlan.py (compressed)
327
+ [6/9] skip 43.2K ../mpy/uhttp/uhttp/server.py -> :/lib/uhttp/server.py (unchanged)
328
+ [7/9] skip 26.3K ../mpy/uhttp/uhttp/client.py -> :/lib/uhttp/client.py (unchanged)
329
+ [8/9] skip 93B ../mpy/uhttp/uhttp/__init__.py -> :/lib/uhttp/__init__.py (unchanged)
330
+ [9/9] skip 10.0K ../../Tmp/test0.bin -> :/lib/test0.bin (unchanged)
331
+ 66.9K 29.7K/s 2.3s speedup 6.5x (3 transferred, 6 skipped)
332
+ RESET
333
+ MONITOR (Ctrl+C to stop)
334
+
335
+ starting web server...
336
+ Config file not created
337
+ AP started: ESP32 (WPA2_PSK, IP: 192.168.4.1)
338
+ Scanning...
339
+ ```
340
+
341
+ ## Debug output
342
+
343
+ - `-d` print warnings (yellow)
344
+ - `-dd` print info messages (purple)
345
+ - `-ddd` print debug messages (blue)
346
+
347
+ For reporting bugs, please include `-ddd` output in the issue.
348
+
349
+ ## Performance
350
+
351
+ `mpytool` uses optimized chunked transfer with automatic compression, which allows copying files very quickly. See [README_BENCH.md](README_BENCH.md) for detailed benchmarks.
352
+
353
+ ### Summary
354
+
355
+ - **Large files upload: 3x - 5x faster** than mpremote
356
+ - **Small files upload: 2x - 3x faster** than mpremote
357
+ - **Skip unchanged: 1.5x - 2.5x faster** than mpremote
358
+
359
+ ## Shell Completion
360
+
361
+ Tab completion for ZSH and Bash with support for commands, options, and remote file paths on the device.
362
+
363
+ Completion files are in `completions/` directory:
364
+ - `_mpytool` - ZSH completion
365
+ - `mpytool.bash` - Bash completion
366
+
367
+ ### ZSH
368
+
369
+ **Completion file:** `completions/_mpytool`
370
+
371
+ **Where to put it:**
372
+ - `~/.zsh/completions/_mpytool` (user directory, recommended)
373
+ - `/usr/local/share/zsh/site-functions/_mpytool` (system-wide)
374
+
375
+ **Configuration in `~/.zshrc`:**
376
+ ```bash
377
+ fpath=(~/.zsh/completions $fpath)
378
+ autoload -Uz compinit && compinit
379
+ ```
380
+
381
+ **Quick install (or update):**
382
+ ```bash
383
+ mkdir -p ~/.zsh/completions
384
+ curl -fsSL https://raw.githubusercontent.com/pavelrevak/mpytool/main/completions/_mpytool -o ~/.zsh/completions/_mpytool
385
+ grep -q '\.zsh/completions' ~/.zshrc || echo 'fpath=(~/.zsh/completions $fpath); autoload -Uz compinit && compinit' >> ~/.zshrc
386
+ exec zsh
387
+ ```
388
+
389
+ ### Bash
390
+
391
+ **Completion file:** `completions/mpytool.bash`
392
+
393
+ **Where to put it:**
394
+ - `/etc/bash_completion.d/mpytool` (Linux system-wide, requires sudo)
395
+ - `/usr/local/etc/bash_completion.d/mpytool` (macOS Homebrew)
396
+ - `~/.mpytool-completion.bash` (user directory)
397
+
398
+ **Configuration in `~/.bashrc`** (only for user directory):
399
+ ```bash
400
+ source ~/.mpytool-completion.bash
401
+ ```
402
+
403
+ **Quick install (Linux system-wide):**
404
+ ```bash
405
+ sudo curl -fsSL https://raw.githubusercontent.com/pavelrevak/mpytool/main/completions/mpytool.bash -o /etc/bash_completion.d/mpytool && exec bash
406
+ ```
407
+
408
+ **Quick install (macOS Homebrew):**
409
+ ```bash
410
+ curl -fsSL https://raw.githubusercontent.com/pavelrevak/mpytool/main/completions/mpytool.bash -o /usr/local/etc/bash_completion.d/mpytool && exec bash
411
+ ```
412
+
413
+ **Quick install (user directory):**
414
+ ```bash
415
+ curl -fsSL https://raw.githubusercontent.com/pavelrevak/mpytool/main/completions/mpytool.bash -o ~/.mpytool-completion.bash
416
+ grep -q 'mpytool-completion' ~/.bashrc || echo 'source ~/.mpytool-completion.bash' >> ~/.bashrc
417
+ exec bash
418
+ ```
419
+
420
+ ### Completion features
421
+
422
+ - Tab completion for all commands and aliases
423
+ - Remote file/directory completion (cached for 60 seconds)
424
+ - Support for `--` command separator
425
+ - Works with both relative and absolute paths
426
+
427
+ ## Requirements
428
+
429
+ Working only with MicroPython boards, not with CircuitPython
430
+
431
+ - python v3.10+
432
+ - pyserial v3.0+
433
+
434
+ ### Running on:
435
+
436
+ - Linux
437
+ - MacOS
438
+ - Windows (limited support - REPL mode is disabled)
439
+
440
+ ## Credits
441
+
442
+ (c) 2022-2026 by Pavel Revak
443
+
444
+ ### License
445
+
446
+ MIT
447
+
448
+ ### Support
449
+
450
+ - Basic support is free over GitHub issues.
451
+ - Professional support is available over email: [Pavel Revak](mailto:pavel.revak@gmail.com?subject=[GitHub]%20mpytool).