chat-object logo

chat-object
Elegant, Pythonic chat/message objects for LLMs

Overview

doctest coverage license python version PyPI version PyPI Downloads

chat-object is a lightweight, intuitive Python library for building, managing, and formatting chat messages for LLM (Large Language Model) applications. Effortlessly create chat histories, prompts, and message objects that work seamlessly with OpenAI, Anthropic, and other LLM APIs.

Features

  • Simple, Pythonic API for chat and prompt construction

  • Automatic formatting for OpenAI/Anthropic message schemas

  • Convenience utilities for rapid prototyping and development

  • Type-safe, explicit roles (System, User, Assistant)

  • Flexible prompt composition with natural string operations

Quick Start

Install the package:

pip install chat-object

Basic usage:

import openai
from chat_object import Chat, Message, Role

client = openai.OpenAI()

chat = Chat(
    Message(Role.System, "You are a helpful assistant"),
    Message(Role.User, "Hello!")
)

response = client.chat.completions.create(
    model="gpt-5-nano",
    messages=chat.as_dict()
)

print(response.choices[0].message.content)

Installation

From PyPI:

pip install chat-object

From GitHub:

pip install git+https://github.com/fresh-milkshake/chat-object.git

From source:

git clone https://github.com/fresh-milkshake/chat-object.git
cd chat-object
pip install -e .

Documentation

Indices and tables