Skip to main content

Python SDK for Nikki Services, PlayStore and Agent APIs.

Project description

nikkiServiceBase for Python

Easy-to-use Python client for connecting your service to the nikki.build playground using WebSocket.


What this library offers

  • Simple async WebSocket connection
  • Automatic handling of serviceDef.json + serviceToken.json
  • Strict validation at startup (fail-fast with clear errors)
  • Auto-reconnect (optional)
  • Clean callbacks: onConnect, onConnect, onError, onData
  • Two send methods:
    • await client.send(...) → normal send (raises on rate limit)
    • client.send_nowait(...) → safe for callbacks (never crashes, ignores rate limit)
  • Full size & rate-limit protection (exactly matches platform rules)
  • Production-ready, defensive, and very easy to use

Installation

  1. Install the only dependency:
pip install websockets

Quick Start

import asyncio
import time
from nikki_python.nikki_client import nikkiServiceBase


async def main():

    client = nikkiServiceBase(auto_reconnect=True)

    def onConnect_handler(details):   print(f"✅ CONNECTED ")
    def onDisconnect_handler(details): print(f"❌ DISCONNECTED → {details}")
    def onError_handler(error):       print(f"⚠️  ERROR → {error}")

    def onData_handler(data: dict):
        print(f"📨 RECEIVED: {data}")

        # inner = data.get("data", {})
        # said = inner.get("said", "")

        # if isinstance(said, str):
        #     has_on = "on" in said.lower()
        #     reply = {"state": has_on}
        #     print(f"   → said = '{said}' | contains 'on' = {has_on} → replying {reply}")

        #     client.send_nowait(reply)          # ← ONE LINE, super clean!


    client.onConnect = onConnect_handler
    client.onDisconnect = onDisconnect_handler
    client.onError = onError_handler
    client.onData = onData_handler

    await client.connect()

    print("📤 Sending 100 test messages (every 2 seconds)...")
    for i in range(100):
        test = {"state" : bool(i %2== 0)}
        try:
            await client.send(test)
            print(f"   Sent #{i+1}/100")
        except Exception as e:
            print(f"   Send failed: {e}")
        await asyncio.sleep(2)

    await asyncio.sleep(30)
    await client.disconnect()
    print("🏁 Test completed.")


if __name__ == "__main__":
    asyncio.run(main())

Configuration Files

Place these two files in the same folder as your script (or pass base_path):

  • serviceDef.json
  • serviceToken.json

Official Website

For full documentation, API reference, and more examples visit: https://nikki.build

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

nikki_python-2.2.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

nikki_python-2.2.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file nikki_python-2.2.0.tar.gz.

File metadata

  • Download URL: nikki_python-2.2.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for nikki_python-2.2.0.tar.gz
Algorithm Hash digest
SHA256 94ecc3ffe1a289d417940e4e194b47de642001c7d017735e3207f615245990f7
MD5 dfec1047d51d8410b2805d766db9378c
BLAKE2b-256 de1b5cbbd0e25061592fdac215c263a6790fb6d1df8c5463d816bf7ef919f81a

See more details on using hashes here.

File details

Details for the file nikki_python-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: nikki_python-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for nikki_python-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d47eb55ce8516c3c5778c2b63326469921ded7324fcd58fbb97aa31d106807c
MD5 55e0bb47b2bb13ca0b9d5c85a01f6c45
BLAKE2b-256 1155a3cf00d3217c889d03d52b05302307d7c9cd95fcd13403f1d6a056c265d3

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