Skip to main content

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")

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)

Source distribution for cyme-win 1.5.1
File Size Uploaded
cyme_win-1.5.1.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cyme-win 1.5.1
File Interpreter ABI Platform
cyme_win-1.5.1-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.5.1 This release

2 release files

1.5.0

2 release files

1.4.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page