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.0.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.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: playlab_api-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 05a9dcc743bf8ceaf5e61e6994129231538fdf953078521bcf6313d8f6333763
MD5 fd0cfc31e9bd79b8e5bdf96fb42fb306
BLAKE2b-256 44f619125277f3ee9dcbf141fe8af7505428356113942fe282007c111e1b0703

See more details on using hashes here.

File details

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

File metadata

  • Download URL: playlab_api-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67546829d9c47224d9272390e67b4f5dda537a44b1ba8bb1dcaac12c719ed1c5
MD5 126dd3a5cb75adf71fb45a39a787d149
BLAKE2b-256 670b972f31638f5799df62f24fd434fb2855e2ef112c5a0c9c97b502f5844e52

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