AI-driven human mouse behavior SDK: trajectories, click timing, drag and scroll wheel simulation
pip install human-mouse-sdk Copy PIP instructions
AI-driven human mouse behavior SDK. It turns a model trained on the Balabit Mouse Dynamics Challenge dataset into a small Python API that produces:
The SDK ships no model weights. You pass the checkpoint path when creating the generator (or set an environment variable), so the same package can load whatever model build you deploy.
pip install human-mouse-sdk # with real desktop control (adds pynput) pip install "human-mouse-sdk[live]" For GPU inference install the CUDA build of PyTorch first, then the SDK:
pip install torch --index-url https://download.pytorch.org/whl/cu124 pip install human-mouse-sdk From a local checkout:
cd sdk pip install -e . # editable install # or build artifacts uv build # dist/human_mouse_sdk- -*.whl Model checkpoints Main checkpoint You need a human_mouse_model.pt file (produced by the repository's train.py and updated by train_scroll.py, or provided by your team). Pass its path explicitly:
from human_mouse_sdk import HumanMouseGenerator gen = HumanMouseGenerator(checkpoint_path="/models/human_mouse_model.pt") or use an environment variable:
export HUMAN_MOUSE_CHECKPOINT=/models/human_mouse_model.pt gen = HumanMouseGenerator() # reads HUMAN_MOUSE_CHECKPOINT If neither is provided, construction raises ValueError. If the path does not exist, it raises FileNotFoundError.
The scroll model (ScrollBurstMDN) is stored under the scroll_model_state key. It is resolved in this order:
# explicit standalone scroll_model.pt (overrides an embedded state) gen = HumanMouseGenerator( checkpoint_path="/models/human_mouse_model.pt", scroll_checkpoint_path="/models/scroll_model.pt", ) # or via environment variable # export HUMAN_MOUSE_SCROLL_CHECKPOINT=/models/scroll_model.pt # or load / replace it later at runtime gen.load_scroll_checkpoint("/models/scroll_model.pt") print(gen.has_scroll_model) # True when the MDN is loaded print(gen.scroll_checkpoint_path) # file it was loaded from If no scroll checkpoint is found, the generator still works, but scroll calls fall back to empirical notch-interval quantiles (has_scroll_model == False).
gen = HumanMouseGenerator(checkpoint_path=CKPT, device="auto") # default gen = HumanMouseGenerator(checkpoint_path=CKPT, device="cpu") gen = HumanMouseGenerator(checkpoint_path=CKPT, device="cuda") gen = HumanMouseGenerator(checkpoint_path=CKPT, device="cuda:1") "auto" picks CUDA when torch.cuda.is_available() else CPU. On CPU the SDK caps PyTorch at 4 threads to keep latency predictable.
HumanMouseGenerator( checkpoint_path: str | None = None, device: str = "auto", scroll_checkpoint_path: str | None = None, ) Parameter Type Default Description checkpoint_path str | None None Main model checkpoint. Falls back to HUMAN_MOUSE_CHECKPOINT; required. device str "auto" "auto", "cpu", "cuda", "cuda:N". scroll_checkpoint_path str | None None Optional standalone scroll model. Falls back to HUMAN_MOUSE_SCROLL_CHECKPOINT, then embedded state, then a sibling scroll_model.pt. Useful attributes:
plan = gen.generate_trajectory( x0=100, y0=100, # start (px) x1=900, y1=600, # end (px) is_drag=False, # sample a drag (button held) trajectory speed=1.0, # >1 faster, <1 slower temperature=0.85, # sampling randomness polling_hz=125, # output sampling rate ) Parameter Type Default Description x0, y0 int — Start position in screen pixels. x1, y1 int — Target position in screen pixels. is_drag bool False Use the drag-conditioned trajectory distribution. speed float 1.0 Duration multiplier: speed=2.0 ≈ half duration, 0.5 ≈ double. temperature float 0.85 Latent/timing sampling spread. Lower = more conservative, higher = more varied. polling_hz int 125 Resampling rate of the integer step trace. Returns a TrajectoryPlan:
import time plan = gen.generate_trajectory(200, 200, 1200, 700) start = time.perf_counter() for x, y, t_cum, _dt in plan.steps: wait = t_cum - (time.perf_counter() - start) if wait > 0: time.sleep(wait) backend.move_pointer(x, y) # your mouse backend generate_click_plan click = gen.generate_click_plan( action_type="left_click", prev_distance=plan.distance, # optional context prev_duration=plan.duration, # optional context temperature=0.85, ) Parameter Type Default Description action_type str "left_click" One of "left", "left_click", "right", "right_click", "double", "double_click", "drag". Unknown values behave like a left click. prev_distance float | None None Distance of the preceding movement (px); defaults to last_distance. prev_duration float | None None Duration of the preceding movement (s); defaults to last_duration. temperature float 0.85 Sampling randomness. Returns a ClickPlan:
def do_click(x, y, double=False): move = gen.generate_trajectory(*current_pos(), x, y) replay(move) c = gen.generate_click_plan("double_click" if double else "left_click") time.sleep(c.pre_click_delay) press_and_release(c.hold_duration) if double: time.sleep(c.double_click_gap) press_and_release(c.second_hold_duration) time.sleep(c.post_click_delay) Scroll wheel APIs All scroll methods accept direction="down" or "up" (case-insensitive; any other value is treated as "up"), speed (duration multiplier) and temperature (sampling spread).
flick = gen.generate_scroll_gesture( direction="down", max_clicks=9, # sampled burst length is 3..max_clicks speed=1.0, temperature=0.85, ) print(flick.total_clicks) # e.g. 6 print(flick.burst_lengths) # [6] A single burst of notches, no inter-burst reset pause. Burst length is sampled by ScrollBurstMDN and clamped to [min(3, max_clicks), max_clicks] (so max_clicks=9 → 3–9). Use this for "one wheel event = one human flick" demos or per-event injection. generate_scroll_detail — multi-burst sequence seq = gen.generate_scroll_detail( clicks=18, # total notches direction="up", speed=1.0, temperature=0.85, ) print(seq.burst_lengths) # e.g. [12, 2, 4] print(seq.inter_burst_pauses) # e.g. [0.24, 0.67] seconds Splits clicks into several finger flicks with inter-burst reset pauses. len(inter_burst_pauses) == len(burst_lengths) - 1. Use this to scroll a long page in a human rhythm. generate_scroll_plan — raw steps steps = gen.generate_scroll_plan(clicks=6, direction="down") # [(dy, delay_after_notch_sec), ...] e.g. [(-1, 0.021), (-1, 0.034), ...] for dy, delay in steps: backend.scroll(dy) # map dy to your wheel unit time.sleep(delay) Returns the same (dy, delay) list used by HumanMouseController.scroll(). dy is -1 for down and +1 for up (one notch per step).
Cadence semantics: within a flick, intervals follow a U-shaped accelerate–decelerate profile (longer at the edges, shorter mid-burst); between flicks the finger repositions for a few hundred milliseconds.
When has_scroll_model == False, the same APIs work using empirical quantile tables from the main checkpoint (or from the standalone scroll checkpoint's scroll_interval_quantiles). Load the MDN checkpoint for the trained cadence.
pause = gen.sample_idle_pause("normal") # seconds Style Intended behavior Approximate quantile range used "quick" Fast visual scanning 10–40% "normal" Typical interaction rhythm 20–75% "thinking" / "reading" Longer cognitive pause 65–95% Unknown styles fall back to "normal". Values are sampled from the empirical pause distribution and clipped to sane minimums by the underlying sampler.
gen.load_scroll_checkpoint("/models/scroll_model.pt") # -> True Accepts a standalone scroll_model.pt or any checkpoint containing scroll_model_state. Updates has_scroll_model and scroll_checkpoint_path. Merges scroll_interval_quantiles into priors when present. Raises FileNotFoundError if the file is missing and ValueError if the file has no scroll_model_state. HumanMouseController Optional high-level driver that executes generated plans on the real desktop cursor (Windows/macOS/X11 via pynput). It is a thin wrapper around HumanMouseGenerator.
HumanMouseController( checkpoint_path=None, device="cpu", dry_run=False, polling_hz=125, scroll_checkpoint_path=None, ) Parameter Default Description checkpoint_path None Main checkpoint (or HUMAN_MOUSE_CHECKPOINT). device "cpu" Inference device (controller defaults to CPU for timing stability). dry_run False If True, no OS calls and no real waits; the virtual cursor is updated only. polling_hz 125 Pointer update rate used by generated trajectories. scroll_checkpoint_path None Optional standalone scroll model. If pynput is missing or no display is available, construction prints a warning and switches to dry_run=True instead of failing.
bot = HumanMouseController(checkpoint_path="human_mouse_model.pt", dry_run=True) plan = bot.move_to(300, 300) # instant, no OS calls print(plan.distance, bot.position) Use live control only on machines and applications you are authorised to automate. The SDK does not bypass anti-bot systems or OS security policies.
import time def replay(plan, move, click=None, sleep=time.sleep): t0 = time.perf_counter() for x, y, t_cum, _dt in plan.steps: wait = t_cum - (time.perf_counter() - t0) if wait > 0: sleep(wait) move(x, y) def human_click(gen, move, press, release, x, y): plan = gen.generate_trajectory(*current_position(), x, y) replay(plan, move) c = gen.generate_click_plan("left_click") time.sleep(c.pre_click_delay) press() time.sleep(c.hold_duration) release() time.sleep(c.post_click_delay) 2. PyAutoGUI integration import time import pyautogui from human_mouse_sdk import HumanMouseGenerator pyautogui.FAILSAFE = True gen = HumanMouseGenerator(checkpoint_path="human_mouse_model.pt") plan = gen.generate_trajectory(*pyautogui.position(), 900, 500) t0 = time.perf_counter() for x, y, t_cum, _dt in plan.steps: wait = t_cum - (time.perf_counter() - t0) if wait > 0: time.sleep(wait) pyautogui.moveTo(x, y, duration=0) click = gen.generate_click_plan("left_click") time.sleep(click.pre_click_delay) pyautogui.mouseDown() time.sleep(click.hold_duration) pyautogui.mouseUp() time.sleep(click.post_click_delay) For scrolling, convert dy (±1) to your backend's wheel unit. PyAutoGUI uses positive values for up, so dy = -1 (down) maps directly:
for dy, delay in gen.generate_scroll_gesture("down").steps: pyautogui.scroll(120 * dy) # dy = -1 -> scroll down time.sleep(delay) 3. Multiple independent samples plans = [gen.generate_trajectory(100, 100, 800, 600) for _ in range(5)] print([p.duration for p in plans]) print([p.human_score_pct for p in plans]) 4. Reproducibility Sampling uses both NumPy and PyTorch RNGs:
import numpy as np import torch np.random.seed(42) torch.manual_seed(42) plan = gen.generate_trajectory(100, 100, 800, 600, temperature=0.0) temperature=0.0 gives the most deterministic trajectory, but small floating-point / CUDA non-determinism can still cause tiny differences.
gen_cpu = HumanMouseGenerator(checkpoint_path=CKPT, device="cpu") gen_gpu = HumanMouseGenerator(checkpoint_path=CKPT, device="cuda") CPU is often preferable for interactive use: small batches on GPU may add transfer latency without throughput benefit.
LicenseRef-Proprietary View SPDX License List
automation click-timing human-like human-mouse mouse-simulation pytorch scroll-wheel trajectory
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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.
None of the files in this release were uploaded with provenance metadata.
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.




