Skip to main content

PlayMind Labs — Behavioral Stability Intervention SDK for Python (server-side). Score player sessions and detect dysregulated behavior.

Project description

playmind

PlayMind Labs — Behavioral Stability Intervention SDK for Python

PyPI version

Server-side client for sportsbook operators integrating PlayMind's real-time tilt detection. Score a player's session and determine the right behavioral intervention — no manual API handling required.

Installation

pip install playmind

Quick Start

import asyncio
from playmind import PlayMindSDK

pm = PlayMindSDK(
    endpoint="https://api.playmindlabs.com",
    api_key="pm_live_abc123",
)

# Call on every bet placed or significant session event
async def main():
    result = await pm.check({
        "player_id": "sha256:...",           # one-way hash — never send raw IDs
        "session_id": "sess_abc123",
        "baseline": {
            "avg_stake_cents": 1000,
            "avg_bets_per_session": 5,
            "avg_session_duration_minutes": 30,
        },
        "events": [
            {"type": "bet_placed", "timestamp": "2026-01-01T10:00:00Z", "stake_cents": 1000, "odds": -110},
            {"type": "bet_settled", "timestamp": "2026-01-01T10:05:00Z", "outcome": "win"},
        ],
    })

    if result.state != "stable":
        print(f"Intervention: {result.intervention.type}{result.intervention.message}")

asyncio.run(main())

States

state Meaning
stable No action needed
moderate Gentle nudge recommended
high_risk Cooldown recommended (5 min)
critical Session pause recommended (30 min)

Configuration

from playmind import PlayMindSDK

pm = PlayMindSDK(
    endpoint="https://api.playmindlabs.com",
    api_key="pm_live_abc123",
    timeout=30,        # request timeout in seconds (default: 30)
    max_retries=3,     # retries on transient errors (default: 3)
)

API Reference

PlayMindSDK(endpoint, api_key, timeout=30, max_retries=3)

Creates a new SDK client. Validates that api_key is non-empty.

await pm.check(payload) -> TiltScoreResponse

Scores the session against the PlayMind API.

Payload fields:

  • player_id (required) — Anonymized player identifier
  • session_id (optional) — Current session identifier
  • baseline (required) — 7-day behavioral baseline
  • events (required for operator context) — Array of event objects
  • context (optional) — "operator" (default) or "bookie"
  • bets (required for bookie context) — Array of bet objects

Error Handling

Exception When
PlayMindAuthError 401 response — invalid API key
PlayMindAPIError Non-2xx response
PlayMindTimeoutError Request timed out
PlayMindValidationError Invalid parameters provided to the SDK
import asyncio
from playmind import PlayMindSDK, PlayMindAuthError, PlayMindAPIError, PlayMindTimeoutError

pm = PlayMindSDK(endpoint="...", api_key="...")

async def main():
    try:
        result = await pm.check(payload)
    except PlayMindAuthError:
        print("Check your API key")
    except PlayMindTimeoutError:
        print("PlayMind unreachable — fail open, continue without intervention")
    except PlayMindAPIError as e:
        print(f"API error {e.status_code}: {e.body}")

asyncio.run(main())

Async Support

The SDK uses httpx.AsyncClient internally and supports the async context manager:

import asyncio
from playmind import PlayMindSDK

async def main():
    async with PlayMindSDK(endpoint="...", api_key="...") as pm:
        result = await pm.check(payload)

asyncio.run(main())

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

playmind-0.1.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

playmind-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file playmind-0.1.1.tar.gz.

File metadata

  • Download URL: playmind-0.1.1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for playmind-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f99aec166bda2345a6b581fc44730991619dd66c23afa3d36793085976785743
MD5 cbb0271513b29aa922439f72a9869ca6
BLAKE2b-256 719013aaed2cd24c7b723dd64e2b1946f86018e1fbe955152214209709ef7646

See more details on using hashes here.

File details

Details for the file playmind-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: playmind-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for playmind-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c5f671c99e58c9ee2cb9ac74eac8460bde1af41cf8356925a8ed10deb019bf1
MD5 2c78c205ea5bf493b4f8d5516d74a4f5
BLAKE2b-256 20b3964d100f2fa730f739cf7b4aeeb8227bc69bf0eb4c332befa9117acca289

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page