A modular, language-agnostic client library for Pollinations AI — with first-class Python and JavaScript implementations, a shared API AST, and tests. PolliLib focuses on clear defaults, portability, and symmetry across languages.
- Unified client design in Python and JavaScript (ESM).
- Image generation, text generation, chat completions (non-stream + SSE stream), tools/function-calling, vision (image URL + local file), and speech-to-text.
- Public feeds (SSE) for images and text with optional image bytes or data URLs.
- Random seed defaults (5–8 digits) applied consistently across image and text/chat APIs.
- Optional
referrerandtokensupported on all endpoints that accept them. - Language-agnostic API AST in
/ASTto keep the two implementations in sync.
AST/ # Language-agnostic API AST (JSON) + README
javascript/ # JavaScript ESM library + tests
polliLib/ # Core modules (base, images, text, chat, vision, stt, feeds)
tests/ # Node test suite (node:test)
package.json # Library metadata (no server, library-only)
python/ # Python library + tests
polliLib/ # Core modules and __main__ examples
tests/ # pytest suite
requirements.txt # Dev/test dependencies
AGENTS.md # Repo guidance for agents (stage+commit only)
README.md # You are here
- Requirements: Python 3.10+.
- Install deps:
python -m pip install -r python/requirements.txt - Import via module path (without packaging):
import os, sys
sys.path.append(os.path.join(os.getcwd(), 'python'))
from polliLib import PolliClient, generate_image, generate_text
# Image (defaults: model=flux, 512x512, nologo=true, random seed)
path = generate_image(
'A serene lake at sunrise, photorealistic, 35mm',
out_path='images/example.jpeg',
)
print('Saved image to', path)
# Text (default model=openai, random seed)
text = generate_text('Write a haiku about lakes at sunrise')
print(text)- Tests:
pytest python/tests - Examples:
python -m polliLib(runs minimal examples; streaming feeds are commented to avoid endless loops).
- Requirements: Node 18+ (global
fetchavailable). For older Node, pass afetchin the client constructor. - Import and use:
import {
PolliClient,
generate_image,
generate_text,
chat_completion_stream,
} from './javascript/polliLib/index.js';
// Image (defaults: model=flux, 512x512, nologo=true, random seed)
const imgPath = await generate_image(
'A serene lake at sunrise, photorealistic, 35mm',
{ outPath: 'images/example.jpeg' }
);
console.log('Saved image to', imgPath);
// Text (default model=openai, random seed)
const text = await generate_text('Write a haiku about lakes at sunrise');
console.log(text);
// Chat streaming (SSE)
for await (const chunk of chat_completion_stream([
{ role: 'user', content: 'Tell me about 35mm photography aesthetics' }
])) {
process.stdout.write(chunk);
}- Tests:
node --test javascript/tests
- Seeds: If omitted, a random 5–8 digit seed is generated.
- Images: Defaults —
model=flux,width=512,height=512,nologo=true. Whenout_path/outPathis provided, bytes stream to disk; otherwise the function returns binary data (Pythonbytes, JSBuffer). - Text:
model='openai'by default.as_json/asJsonoptionally parses JSON responses with a string fallback. - Chat: Non-streaming returns assistant content (or full JSON when requested). Streaming yields content chunks via SSE; terminator is
[DONE]. - Tools/Function-calling: Provide tool specs and optional local functions; tool calls are executed locally and appended to conversation history up to
max_rounds. - Vision: Accepts image URLs or local files (encoded as data URLs) and returns content; optional JSON output.
- Speech-to-Text: Accepts
mp3orwav, encodes to base64 input_audio, returns transcribed text. - Feeds: Public image/text feeds via SSE. Optional byte/data URL inclusion for image events.
- Optional
referrerandtoken: Include them where supported; both may be supplied.
- Purpose: Keep Python and JavaScript APIs aligned, document contracts, and simplify cross-language porting.
- Files:
polli.ast.json(manifest + shared types) and per-module ASTs (base,images,text,chat,vision,stt,feeds,client). - Maintenance rules:
- Update AST whenever public API surfaces change (names, params/defaults, returns, streaming contracts, errors).
- Record Python snake_case vs JS camelCase and timeout units (seconds vs milliseconds).
- Validate behavior with both test suites before committing AST changes.
- Python tests:
python -m pip install -r python/requirements.txt && pytest python/tests - JS tests:
node --test javascript/tests - Formatting: Follow existing style (no new tooling unless already configured).
- Do not push from automation. Follow AGENTS.md: stage and commit only; maintainers will push.
- See
CONTRIBUTING.mdfor detailed guidance. - Highlights:
- Stage + commit only (no pushes). Optionally create tags if requested.
- Update
/ASTwhenever changing public APIs. - Add or update tests in
python/testsandjavascript/tests. - Keep parameters and defaults consistent across languages.
- Document new features in language READMEs and the root README.
- Packaging: The repo currently favors direct source usage for Python/JS. If publishing to PyPI/npm is desired, add packaging metadata and update READMEs accordingly.
- Environment: For Python imports without packaging, ensure your
PYTHONPATHincludes thepythonfolder (as shown above). - Node fetch: On Node <18 or in browsers lacking
fetch, pass afetchimplementation tonew PolliClient({ fetch }).
- See repository terms (no license file included). If you need explicit licensing, open an issue to discuss.
- Built for Pollinations AI. This project aims to provide a clean, modular client with mirrored Python and JavaScript APIs and a shared AST to accelerate cross-language evolution.