Python
Add the SDK to a Python desktop app or program on Windows, macOS or Linux. Before you start, get your account approved and create an SDK key (steps 1 and 2 of the overview).
| Downloads | Language bindings (for python/idlepay.py) plus the library for each system below, from your SDK page (approved accounts only) |
| Module | idlepay, a single file using only the standard library (ctypes). It isn't on PyPI. |
| Requires | Python 3.8 or later (64-bit on Windows) |
| Your app runs on | Package | Library file |
|---|---|---|
| Windows (64-bit) | windows-amd64 | idlepay.dll |
| macOS (Apple silicon and Intel) | macos | libidlepay.dylib |
| Linux x86-64 | linux-amd64 | libidlepay.so |
| Linux ARM64 | linux-arm64 | libidlepay.so |
| Linux ARMv7 (32-bit) | linux-armv7 | libidlepay.so |
Download the package for each OS from the Downloads tab on your SDK page (approved accounts only). Every download also has idlepay.h. On Windows the library is 64-bit x86 only, so your app must run as a 64-bit x86 process. The macOS library works on both Apple silicon and Intel.
1. Add the files to your app
Put idlepay.py and the library for your system in the same folder, inside your app:
myapp/ main.py idlepay.py idlepay.dll Windows libidlepay.dylib macOS libidlepay.so Linux
import idlepay loads the library from its own folder. If you keep it elsewhere, set IDLEPAY_LIB to its full path before the import. An OSError at import means the library is missing, or is for another system or CPU.
2. Ask the user, and remember the answer
Keep the user's choice and the SDK calls together. Put your SDK key in SDK_KEY:
import atexit, json, os, sys, time
from pathlib import Path
import idlepay
SDK_KEY = "ipsk_..." # from the SDK page of your dashboard
def app_dir():
"""A per-user folder of your app that isn't synced to other computers."""
if sys.platform == "win32":
return Path(os.environ["LOCALAPPDATA"]) / "MyApp"
if sys.platform == "darwin":
return Path.home() / "Library" / "Application Support" / "MyApp"
return Path.home() / ".local" / "share" / "myapp"
CONSENT_FILE = app_dir() / "sharing-consent.json"
def saved_consent():
"""True or False once the user answered, None before."""
try:
return json.loads(CONSENT_FILE.read_text())["consent"]
except (OSError, ValueError, KeyError):
return None
def save_consent(allowed):
CONSENT_FILE.parent.mkdir(parents=True, exist_ok=True)
CONSENT_FILE.write_text(json.dumps({
"consent": allowed, "at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "disclosure": "v1"}))
def start_sharing():
idlepay.start(key=SDK_KEY, data_dir=str(app_dir() / "idlepay"), consent=True)
atexit.register(idlepay.stop)
Ask once (see sample wording). For example with Tkinter:
from tkinter import messagebox
answer = saved_consent()
if answer is None:
answer = messagebox.askyesno(
"Support MyApp by sharing your connection",
"With your permission, MyApp shares a small part of your unused internet connection with IdlePay. ...")
save_consent(answer)
if answer:
start_sharing()
Add a setting that turns sharing off (save_consent(False) and idlepay.stop()) and on again. Also keep a consent record.
startreturns at once; the SDK runs on its own threads. It raisesRuntimeErrorwith the reason if it can't start, for example "already started".stopwaits a few seconds at most.- Sharing runs while your program runs, so it suits apps that stay open or run in the background.
3. Check that it works
print(idlepay.status())
# {'running': True, 'state': 'online', 'message': '', 'public_ip': '203.0.113.7', 'device_id': 123456}
On a computer on a home connection, state should be online within about a minute, and the device appears on your SDK page. Anything else comes with a message that says why: see the messages.
4. Pause and reconnect
idlepay.set_paused(True) # your own reason: on battery, a metered connection... idlepay.set_paused(False) idlepay.reconnect() # optional: the network changed, reconnect now
To cap traffic per device, pass max_daily_mb=500 to start. Sharing then pauses until midnight UTC once the device has shared that much.
5. Ship it
- Bundlers (PyInstaller, Nuitka, cx_Freeze, Briefcase): include the library as a binary in the same folder as the bundled
idlepaymodule, or setIDLEPAY_LIBto where you put it beforeimport idlepay. - macOS: sign
libidlepay.dylibwith your Developer ID along with your app, before notarizing. A library downloaded with a browser is quarantined: while testing, clear it withxattr -d com.apple.quarantine libidlepay.dylib.
Updating the SDK
Replace idlepay.py and the libraries with the new version's and release your app. Devices keep their link to your account.