Python Lovense API client
Project description
LovensePy
Python client for the Lovense API. Supports Standard API (LAN & Server), Standard Socket API, and Toy Events API.
Features
- Standard API LAN (Game Mode): GetToys, GetToyName, Function, Stop, Pattern, Preset, Position, PatternV2
- Standard API Server: Function, Pattern, Preset via Lovense cloud;
get_qr_codefor QR pairing - Standard Socket API: getToken, getSocketUrl, WebSocket client for QR flow and remote control
- Toy Events API: Real-time events (toy-list, button-down, function-strength-changed, etc.)
Installation
pip install lovensepy
Dependencies: httpx, pydantic, websockets
API Variants
| API | Client | Auth | Notes |
|---|---|---|---|
| Standard / local | LANClient |
Game Mode (IP + port) | Lovense Remote: 20011/30011. Connect: 34567 |
| Standard / server | ServerClient |
token + uid | uid from QR callback. Use get_qr_code for pairing |
| Socket / server | SocketAPIClient |
getToken, getSocketUrl | QR scan, commands via WebSocket |
| Socket / local | SocketAPIClient(use_local_commands=True) |
same + LAN | Commands via HTTPS to device |
| Socket / local only | LANClient |
IP + port only | No token, no WebSocket |
| Events API | ToyEventsClient |
access (appName) | Port 20010. Lovense Remote only |
Flow: Standard local → HTTP/HTTPS to device. Standard server → HTTPS to Lovense cloud. Socket → WebSocket to cloud (or HTTPS to device when use_local_commands=True). Events → WebSocket to device.
Usage
Standard API LAN (Game Mode)
Lovense Remote or Connect > Game Mode > Enable LAN. No token, no QR.
from lovensepy import LANClient, Actions, Presets
client = LANClient("My App", "192.168.1.100", port=20011)
print(client.get_toys())
client.function_request({Actions.ALL: 10}, time=5)
client.preset_request(Presets.PULSE, time=5)
client.stop()
Standard API Server
Requires developer token and uid (from QR pairing callback). Use get_qr_code to get QR for pairing.
from lovensepy import ServerClient, get_qr_code, Actions
# QR pairing: get_qr_code(token, uid) → user scans → callback receives uid
client = ServerClient(developer_token="...", uid="user_123")
client.function_request({Actions.VIBRATE: 10}, time=5)
Standard Socket API
platform must match Website Name from Lovense Developer Dashboard.
from lovensepy import get_token, get_socket_url, build_websocket_url, SocketAPIClient
auth_token = get_token(developer_token, uid, uname="User")
socket_info = get_socket_url(auth_token, platform="Your App")
ws_url = build_websocket_url(socket_info, auth_token)
client = SocketAPIClient(ws_url, on_event=lambda e, p: print(e, p))
await client.connect()
# Commands: client.send_command("Function", "Vibrate:10", time_sec=5)
By local (same LAN): use_local_commands=True — commands go via HTTPS to device after QR scan.
Toy Events API
Real-time events from toys. Lovense Remote only, port 20010.
from lovensepy import ToyEventsClient
client = ToyEventsClient("192.168.1.100", port=20010, app_name="My App", on_event=handler)
await client.connect()
High-level patterns
from lovensepy import LANClient, SyncPatternPlayer, features_for_toy
client = LANClient("My App", "192.168.1.100", port=20011)
toys = client.get_toys().get("data", {}).get("toys", {})
player = SyncPatternPlayer(client, toys)
player.play_sine_wave("toy_id", "Vibrate1", duration_sec=5)
player.play_combo([("t1", "Vibrate1"), ("t2", "Vibrate")], duration_sec=4)
player.stop("toy_id")
Architecture
- Clients: LANClient, ServerClient, SocketAPIClient, ToyEventsClient — command building, protocols
- Transport: HttpTransport (POST JSON), WsTransport (WebSocket)
- Security: Certificate fingerprint verification for HTTPS (port 30010/30011) when
verify_ssl=False
HTTPS Certificate
For local HTTPS (ports 30010/30011), lovensepy verifies the Lovense certificate fingerprint instead of disabling SSL. Fingerprint in lovensepy.security.LOVENSE_HTTPS_FINGERPRINT.
Examples
examples/lan_game_mode.py— LAN Game Modeexamples/patterns_demo.py— Sine waves, combosexamples/server_api.py— Server APIexamples/socket_api_full.py— Socket API with QRexamples/toy_events_full.py— Toy Events
Tests
| Mode | Test | Env Vars |
|---|---|---|
| Standard / local | test_standard_local.py |
LOVENSE_LAN_IP, LOVENSE_LAN_PORT (20011 Remote, 34567 Connect) |
| Standard / server | test_standard_server.py |
LOVENSE_DEV_TOKEN, LOVENSE_UID (or LOVENSE_QR_PAIRING=1 + ngrok) |
| Socket / server | test_socket_server.py |
LOVENSE_DEV_TOKEN, LOVENSE_UID, LOVENSE_PLATFORM |
| Socket / local | test_socket_server.py::test_by_local |
Same + same LAN |
| Socket / local only | test_socket_local.py |
LOVENSE_LAN_IP, LOVENSE_LAN_PORT |
| Toy Events | test_toy_events.py |
LOVENSE_LAN_IP, LOVENSE_TOY_EVENTS_PORT (20010) |
pip install -e ".[dev]"
# Unit tests (no devices)
pytest tests/test_unit.py -v
# Integration tests — set env vars per table above, then:
export LOVENSE_LAN_IP=192.168.1.100
export LOVENSE_LAN_PORT=34567 # Lovense Connect
export LOVENSE_DEV_TOKEN=your_token
export LOVENSE_UID=your_uid
export LOVENSE_PLATFORM="Your App"
export LOVENSE_TOY_EVENTS_PORT=20011 # Lovense Remote
export LOVENSE_QR_PAIRING=1
export LOVENSE_CALLBACK_PORT=8765 # start cloudflared --url http://localhost:8765
pytest tests/test_standard_local.py -v -s
pytest tests/test_standard_server.py -v -s
pytest tests/test_socket_server.py -v -s
pytest tests/test_socket_local.py -v -s
pytest tests/test_toy_events.py -v -s
Links
License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lovensepy-1.0.0.tar.gz.
File metadata
- Download URL: lovensepy-1.0.0.tar.gz
- Upload date:
- Size: 35.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d460ebf72a4b0c06c3a09a55d3fa12e43d0e5a6ed9feb225de1a7a4ca28a0943
|
|
| MD5 |
88d0ba32cb6234f0dde6e7e1187768f5
|
|
| BLAKE2b-256 |
8f827a9d46c49bf55d4b6137d7f58c8aaa19d72b6951ae3a48b9d8f764aae945
|
File details
Details for the file lovensepy-1.0.0-py3-none-any.whl.
File metadata
- Download URL: lovensepy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 46.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e6c884a7e109866e57b33e196704a97b4bb377093222822c6c6dbb83ff68d2b
|
|
| MD5 |
158a55a39eda716ac39adae927e54c3c
|
|
| BLAKE2b-256 |
40699b105bc878079b36aed76ab2faae9be672b74d586df2aebe1f4780bc524e
|