Skip to main content

A Python client for the Playlab API

Project description

Playlab Python Client

A Python client for interacting with the Playlab API.

Requirements

  • Python 3.7 or later
  • Required Python packages (installed automatically):
    • requests>=2.31.0
    • readline (on non-Windows platforms)

Installation

pip install playlab-python

Quick Start

Basic Usage

from playlab_python import PlaylabClient

# Initialize the client
client = PlaylabClient(
    api_key="your_api_key_here",
    project_id="your_project_id_here"
)

# Create a new conversation
conversation = client.create_conversation()
conversation_id = conversation["conversation"]["id"]

# Send a message and get the response
response = client.send_message(conversation_id, "Hello, AI!")

# Stream a response with real-time updates
def on_chunk(chunk):
    print(chunk, end="", flush=True)

full_response = client.stream_message(
    conversation_id,
    "Tell me a story",
    on_chunk=on_chunk
)

# List all messages in a conversation
messages = client.list_messages(conversation_id)

Interactive Chat Example

The package includes an interactive chat example that you can run directly:

from playlab_python import start_chat

# Start an interactive chat session
start_chat(
    api_key="your_api_key_here",
    project_id="your_project_id_here"
)

Or run it from the command line:

# Set environment variables
export PLAYLAB_API_KEY="your_api_key_here"
export PLAYLAB_PROJECT_ID="your_project_id_here"

# Run the interactive chat (either way works)
playlab-chat
# or
python -m playlab_python

Environment Variables

You can set your API key and project ID using environment variables:

export PLAYLAB_API_KEY="your_api_key_here"
export PLAYLAB_PROJECT_ID="your_project_id_here"

Then initialize the client without parameters:

client = PlaylabClient()

Features

  • Create new conversations
  • Send messages and receive responses
  • Stream responses in real-time
  • List conversation messages
  • Support for file attachments
  • Environment variable configuration
  • Interactive chat interface

API Reference

PlaylabClient

The main client class for interacting with the Playlab API.

Methods

  • create_conversation(instruction_variables=None, use_form=False): Create a new conversation
  • send_message(conversation_id, message, file_path=None, use_form=False): Send a message in a conversation
  • list_messages(conversation_id): List all messages in a conversation
  • stream_message(conversation_id, message, on_chunk=None, use_form=False): Send a message and stream the response

Interactive Chat

The package provides an interactive chat interface through the start_chat function:

from playlab_python import start_chat

start_chat(api_key="your_api_key_here", project_id="your_project_id_here")

This will start an interactive session where you can:

  • Type messages and press Enter to send
  • See AI responses in real-time
  • Type "exit" to end the conversation

License

MIT License

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

playlab_api-0.1.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

playlab_api-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: playlab_api-0.1.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for playlab_api-0.1.1.tar.gz
Algorithm Hash digest
SHA256 552f4df81f8325a41fee8b1e7afadc8fcd94386b8631317cd8997b553d485abc
MD5 e2431a440a0f62d00c465201330244ec
BLAKE2b-256 29b8ab459e3d553ed8fc8a140ffc5a6c49bcd5dc176519261b1dc948662778d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: playlab_api-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for playlab_api-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1965b146bb6e857631dec2590cf74b3bd52252e0af75c4f002e119baea6da695
MD5 1d8ac907f422d757beca06db2caf4977
BLAKE2b-256 f3cfd7f987cbbb5be5f2c4ce4c4c22463f5d16692854f80a59b93d689e0c0b07

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