cyme_win
Windows USB hotplug monitor based on cyme, simple and easy to use.
Installation
pip install cyme_win
Quick Start
import cyme_win
# Download cyme.exe (first time only)
cyme_win.download_cyme()
# Simple callback - one line to monitor USB hotplug
cyme_win.watch(lambda d: print(f"{d['event']}: {d['name']} ({d['vid_pid']})"))
import time
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
Device Info
The callback receives a dict with these fields:
| Field | Description | Example |
|---|---|---|
event |
Event type | "connect" / "disconnect" |
name |
Device name | "SanDisk USB Flash Drive" |
vendor_id |
Vendor ID | "0781" |
product_id |
Product ID | "5567" |
vid_pid |
Combined format | "0781:5567" |
location |
Linux-style location | "0-15" |
manufacturer |
Manufacturer name | "SanDisk" |
serial |
Device serial number | "4C5300012345" |
speed |
Transfer speed | "480.0 Mb/s" |
device_class |
USB device class | "mass-storage" |
bus |
Bus number | 0 |
port |
Port number | 15 |
Examples
Example 1: Distinguish connect/disconnect events
import cyme_win
def on_device(d):
symbol = "+" if d["event"] == "connect" else "-"
print(f"[{symbol}] {d['name']}")
print(f" VID/PID: {d['vid_pid']}")
print(f" Location: {d['location']}")
cyme_win.watch(on_device)
import time
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Stopped")
Example 2: Monitor specific devices
import cyme_win
def on_storage(d):
# Only monitor mass storage devices
if d.get("device_class") == "mass-storage":
print(f"USB Drive {d['event']}: {d['name']}")
print(f" Serial: {d['serial']}")
print(f" Speed: {d['speed']}")
cyme_win.watch(on_storage)
Example 3: Using class API (multiple callbacks)
import cyme_win
def log_device(d):
with open("usb_log.txt", "a") as f:
f.write(f"{d['event']} | {d['name']} | {d['vid_pid']}\n")
def notify(d):
print(f"Notify: {d['event']} - {d['name']}")
# Create monitor, add multiple callbacks
monitor = cyme_win.USBMonitor()
monitor.add_callback(log_device)
monitor.add_callback(notify)
monitor.start()
import time
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
monitor.stop()
Example 4: Using context manager
import cyme_win
with cyme_win.USBMonitor().add_callback(lambda d: print(d)):
print("Monitoring... Press Ctrl+C to exit")
import time
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
Example 5: Get full device info
import cyme_win
def show_details(d):
print(f"\n{'='*50}")
print(f"Event: {d['event']}")
print(f"Name: {d['name']}")
print(f"VID:PID: {d['vid_pid']}")
print(f"Manufacturer: {d['manufacturer']}")
print(f"Serial: {d['serial']}")
print(f"Speed: {d['speed']}")
print(f"Location: {d['location']} (bus {d['bus']}, port {d['port']})")
print(f"Class: {d['device_class']}")
print(f"{'='*50}\n")
cyme_win.watch(show_details)
import time
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
API Reference
download_cyme(target_dir=None)
Download cyme.exe to specified directory (default: current working directory).
cyme_win.download_cyme() # Current directory
cyme_win.download_cyme("E:/my_project") # Specified directory
watch(callback, cyme_path=None)
Global singleton mode, simplest way to use.
# Auto-find cyme.exe
cyme_win.watch(lambda d: print(d))
# Specify cyme.exe path
cyme_win.watch(lambda d: print(d), cyme_path="E:/tools/cyme.exe")
stop()
Stop global monitoring.
cyme_win.stop()
USBMonitor class
| Method | Description |
|---|---|
__init__(cyme_path=None) |
Create monitor, optionally specify cyme.exe path |
add_callback(fn) |
Add event callback, returns self for chaining |
start() |
Start monitoring |
stop() |
Stop monitoring |
# Auto-find cyme.exe
monitor = cyme_win.USBMonitor()
# Specify cyme.exe path
monitor = cyme_win.USBMonitor(cyme_path="E:/tools/cyme.exe")
Links
- cyme project: https://github.com/tuna-f1sh/cyme
- cyme releases: https://github.com/tuna-f1sh/cyme/releases
License
MIT
Metadata
Release files for cyme-win 1.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cyme_win-1.5.1.tar.gz | 7.8 kB | Without provenance | Details for cyme_win-1.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cyme_win-1.5.1-py3-none-any.whl | Python 3 | none | any | Details for cyme_win-1.5.1-py3-none-any.whl |
Total release size: 15.5 kB
Release files / cyme_win-1.5.1.tar.gz
| Download URL | cyme_win-1.5.1.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e90ba0a8e1f6a6d87fe1899d8018014d2427b6363f8e4250f5a9fa0af7f28350
|
|
BLAKE2b-256 checksum How to use checksums |
b456321eec45d6aa83580d4b6e61c72a2df22e88d01b21810845e3fd45d378ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Release files / cyme_win-1.5.1-py3-none-any.whl
| Download URL | cyme_win-1.5.1-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
436b0622f5e0c360e72f1701f25dd50815a021737c07c0b5effb0f7018c9e6ab
|
|
BLAKE2b-256 checksum How to use checksums |
8da108866aaa78572aa9dfcaebe5a68603175c34823b8fd53f1a1970618adad5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Security for cyme-win 1.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.