Skip to content

Commit a5301db

Browse files
committed
Initial release: poe 0.1.0 — Python client for api.poe.com/v1/chat/completions
- PoeClient with chat() and stream() methods - OpenAI-compatible chat completions API - SSE streaming support via httpx - Trusted publisher PyPI workflow (pypi.yml) - CI workflow for PRs and main branch
0 parents  commit a5301db

10 files changed

Lines changed: 450 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Test Python ${{ matrix.python-version }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.9", "3.12", "3.13"]
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -e ".[dev]"
28+
29+
- name: Run tests
30+
run: pytest tests/ -v

.github/workflows/pypi.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
# Allow manual trigger
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
id-token: write # Required for trusted publishing (OIDC)
13+
14+
jobs:
15+
test:
16+
name: Run tests
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
python-version: ["3.9", "3.12", "3.13"]
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -e ".[dev]"
33+
34+
- name: Run tests
35+
run: pytest tests/ -v
36+
37+
build:
38+
name: Build package
39+
runs-on: ubuntu-latest
40+
needs: test
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Set up Python
45+
uses: actions/setup-python@v5
46+
with:
47+
python-version: "3.13"
48+
49+
- name: Install build tools
50+
run: python -m pip install --upgrade pip build
51+
52+
- name: Build sdist and wheel
53+
run: python -m build
54+
55+
- name: Upload build artifacts
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: dist
59+
path: dist/
60+
61+
publish:
62+
name: Publish to PyPI
63+
runs-on: ubuntu-latest
64+
needs: build
65+
environment:
66+
name: pypi
67+
url: https://pypi.org/p/poe
68+
steps:
69+
- name: Download build artifacts
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: dist
73+
path: dist/
74+
75+
- name: Publish to PyPI
76+
uses: pypa/gh-action-pypi-publish@release/v1
77+
# Uses trusted publishing (OIDC) — no API token needed.
78+
# Trusted publisher already configured on PyPI for:
79+
# repo: poe-platform/poe-python
80+
# workflow: pypi.yml

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
4+
*.egg-info/
5+
dist/
6+
build/
7+
*.egg
8+
.eggs/
9+
.pytest_cache/
10+
.mypy_cache/
11+
.venv/
12+
venv/
13+
env/
14+
*.so
15+
.DS_Store
16+
*.swp
17+
*.swo

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Poe Platform
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# poe
2+
3+
Official Python client for the [Poe](https://poe.com) chat completions API.
4+
5+
## Installation
6+
7+
```bash
8+
pip install poe
9+
```
10+
11+
## Quick Start
12+
13+
```python
14+
from poe import PoeClient
15+
16+
client = PoeClient(api_key="your-poe-api-key")
17+
18+
# Simple chat
19+
response = client.chat("What is Python?", model="GPT-4o")
20+
print(response["choices"][0]["message"]["content"])
21+
```
22+
23+
## Streaming
24+
25+
```python
26+
for chunk in client.stream("Tell me a story", model="GPT-4o"):
27+
print(chunk, end="", flush=True)
28+
```
29+
30+
## Options
31+
32+
```python
33+
client = PoeClient(
34+
api_key="your-key",
35+
timeout=120.0, # request timeout in seconds
36+
)
37+
38+
response = client.chat(
39+
"Explain quantum computing",
40+
model="GPT-4o",
41+
temperature=0.7,
42+
max_tokens=1024,
43+
system_prompt="You are a helpful physics teacher.",
44+
)
45+
```
46+
47+
## Context Manager
48+
49+
```python
50+
with PoeClient(api_key="your-key") as client:
51+
resp = client.chat("Hello!")
52+
print(resp["choices"][0]["message"]["content"])
53+
```
54+
55+
## API Key
56+
57+
Get your API key from [poe.com/api_key](https://poe.com/api_key).
58+
59+
## License
60+
61+
MIT

pyproject.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "poe"
7+
version = "0.1.0"
8+
description = "Python client for the Poe API (api.poe.com)"
9+
readme = "README.md"
10+
license = "MIT"
11+
requires-python = ">=3.9"
12+
authors = [
13+
{ name = "Poe Platform", email = "support@poe.com" },
14+
]
15+
classifiers = [
16+
"Development Status :: 3 - Alpha",
17+
"Intended Audience :: Developers",
18+
"License :: OSI Approved :: MIT License",
19+
"Programming Language :: Python :: 3",
20+
"Programming Language :: Python :: 3.9",
21+
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
24+
"Programming Language :: Python :: 3.13",
25+
"Topic :: Software Development :: Libraries :: Python Modules",
26+
]
27+
dependencies = [
28+
"httpx>=0.25.0",
29+
]
30+
31+
[project.optional-dependencies]
32+
dev = [
33+
"pytest>=7.0",
34+
"pytest-asyncio>=0.21",
35+
]
36+
37+
[tool.hatch.build.targets.wheel]
38+
packages = ["src/poe"]
39+
40+
[project.urls]
41+
Homepage = "https://github.com/poe-platform/poe-python"
42+
Repository = "https://github.com/poe-platform/poe-python"
43+
Documentation = "https://developer.poe.com"
44+
Issues = "https://github.com/poe-platform/poe-python/issues"

src/poe/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Python client for the Poe API."""
2+
3+
from poe.client import PoeClient
4+
5+
__all__ = ["PoeClient"]
6+
__version__ = "0.1.0"

0 commit comments

Comments
 (0)