Skip to main content

Official Python SDK for PluginAI RAG Platform

Project description

PluginAI Python SDK

Official Python SDK for the PluginAI RAG platform. Turn your documents into an intelligent, API-accessible assistant, and query it from any Python app in under five minutes.

  • 🐍 Pure Python, one dependency (requests)
  • 🔁 Synchronous — works in scripts, notebooks, Flask, Django, FastAPI, anywhere
  • 💬 Built-in multi-turn conversation tracking
  • 🧯 Rich, catchable exception hierarchy
  • ✅ Python 3.8 – 3.12

Installation

pip install pluginai

Quickstart

from pluginai import PluginAI

client = PluginAI(
    api_key="your-api-key",
    workspace="your-workspace-name",
)

response = client.query("What is the refund policy?")
print(response.answer)

print(response) also works — a QueryResponse stringifies to its answer text.


Multi-turn conversations

Every query from the same client shares one conversation_id, so the backend keeps context across turns. Start over with reset_conversation().

client.query("What products do you offer?")
client.query("Which is cheapest?")     # remembers the previous turn

new_id = client.reset_conversation()   # fresh conversation from here on
client.query("Let's start over.")

Use it as a context manager to close the HTTP session automatically:

with PluginAI(api_key="...", workspace="...") as client:
    print(client.query("Hello").answer)

Agentic queries

For complex, multi-step questions, use agent_query() — same signature and return type as query(), but routed through the Agentic RAG pipeline:

response = client.agent_query(
    "Compare the 2023 and 2024 refund policies and summarize what changed."
)

Configuration

All constructor parameters:

Parameter Type Default Description
api_key str required Your workspace API key.
workspace str required The workspace name to query.
base_url str hosted PluginAI API PluginAI backend URL. Only override if you self-host (trailing slash stripped).
conversation_id str auto-generated Pass to continue an existing conversation.
timeout int 30 Per-request timeout, in seconds.
max_retries int 2 Retries on transient server errors (502/503/504) only.
on_error callable None Called with the exception right before any error is raised.

The response object

client.query(...) returns a QueryResponse:

Attribute / property Type Description
answer str The AI-generated answer text.
status str "success" or "no_data".
response_time float Seconds the backend took.
conversation_id str The conversation the query belonged to.
cached bool Reserved for future use (always False).
is_success bool True when status == "success".
has_data bool False when status == "no_data".

Error handling

Every SDK error inherits from PluginAIError, so you can catch that one base class or handle specific cases:

from pluginai import (
    PluginAI,
    AuthenticationError,
    NoDataError,
    QuotaExceededError,
    TimeoutError,
    PluginAIError,
)

try:
    response = client.query("What is the refund policy?")
    print(response.answer)
except AuthenticationError:
    print("Check your API key.")
except NoDataError:
    print("Upload documents to this workspace first.")
except QuotaExceededError:
    print("Upgrade your plan.")
except TimeoutError:
    print("Increase the `timeout` parameter.")
except PluginAIError as exc:
    print(f"Something went wrong: {exc}")
Exception Raised when
PluginAIError Base class for all SDK errors.
AuthenticationError HTTP 401/403 — wrong or inactive API key.
QuotaExceededError HTTP 403 mentioning a quota / usage limit.
WorkspaceNotFoundError HTTP 404 — workspace doesn't exist.
NoDataError Backend returned status == "no_data".
ConnectionError Backend unreachable.
TimeoutError Request exceeded timeout.
RateLimitError HTTP 429 — too many requests.
ServerError HTTP 5xx — backend error.

Every exception carries .message (str) and .status_code (int or None).


Framework integration

See the examples/ directory for runnable samples:

Tip: create the client once at app startup and reuse it — that keeps the connection pool warm instead of paying setup cost on every request.


Development

git clone <repo-url>
cd pluginai-python
pip install -e ".[dev]"      # or: pip install -r requirements-dev.txt
pytest tests/

Publishing to PyPI

pip install build twine
python -m build              # builds sdist + wheel into dist/
pytest tests/                # make sure everything is green
twine check dist/*
twine upload dist/*          # prompts for your PyPI token

License

MIT © Plugin AI

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

pluginai-1.0.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pluginai-1.0.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file pluginai-1.0.0.tar.gz.

File metadata

  • Download URL: pluginai-1.0.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for pluginai-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ebaeb9f736b958c9fd3b445590875f132e893d0c06eaf69ef25db265b04147d2
MD5 1ccca9442e9c7e2118d4a79275abafb8
BLAKE2b-256 550b80c86c2acf868451d3a0bed43c38f2693e6cd7810cfe5b5ecdf700a62d15

See more details on using hashes here.

File details

Details for the file pluginai-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pluginai-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for pluginai-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03b848fd86a6e8093077713b0613f1f1b8af0b97994671ffbba90da82706f5c8
MD5 69008d4963b49cc2ad82ffff3e9e2bda
BLAKE2b-256 aad49178bcaa961b0c46347a1b36a0413f5ca69f12c3b163237207d8f966c578

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