gptsession
Simple, stateful conversations with OpenAI's chat models, including truncation and token metering.
gptsession is a lightweight Python module for managing structured, multi-turn conversations with OpenAI’s ChatGPT models. It supports multiple concurrent sessions, automatic token tracking, message truncation, and full conversation recording.
📦 Installation
pip install gptsession
✨ Features
- Supports multiple parallel chat sessions
- Token-aware truncation based on model limits
- Tracks actual tokens sent and received
- Maintains full untruncated conversation history
- Clean, minimal API:
setup(),say(),system(),model(), etc.
🚀 Quick Start
import gptsession
gptsession.setup(open("mykey.txt").read().strip())
gptsession.new()
gptsession.model("gpt-3.5-turbo")
gptsession.system("You are a helpful assistant.")
reply = gptsession.say("Hello! Can you explain recursion?")
print("ChatGPT:", reply)
if gptsession.truncated():
print("[Note: Earlier messages were removed to stay within token limits.]")
🔄 Multiple Sessions Example
import gptsession as gpt
gpt.setup(open("mykey.txt").read().strip())
s1 = gpt.new()
gpt.system("You are a bird.")
s2 = gpt.new()
gpt.system("You are a robot.")
gpt.sel(s1)
print(gpt.say("Where do you live?"))
gpt.sel(s2)
print(gpt.say("Where do you live?"))
📄 License
MIT License
© 2025 Lion Kimbro
🌐 Project Links
Release files for gptsession 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gptsession-1.0.0.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gptsession-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.9 kB
Release files / gptsession-1.0.0.tar.gz
| Download URL | gptsession-1.0.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9992d3217479c526e278bac599871141bb4fa6671b344b0c01df35c24cc0d7f9
|
|
BLAKE2b-256 checksum How to use checksums |
5da35c372879ca9a010e920427a0287cbb0134a399867ea5c1700c04fd341f91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.4
|
Release files / gptsession-1.0.0-py3-none-any.whl
| Download URL | gptsession-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d563f9462d3cdcbd15b432c850fd769bb08a1152c253bfdbf1021404c85921d4
|
|
BLAKE2b-256 checksum How to use checksums |
4a96e5c56f7ea580a13cd75ff86e4c15c57e2a6747b7e379f8b6ab6f8fcc06f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.4
|