Skip to main content

Prism Perplexity for Python

Perplexity's Search API, embeddings and Agent API: the parts of Perplexity that Prism core does not carry. The Python port of particle-academy/prism-perplexity.

Zero runtime dependencies. Python 3.10+.

pip install prism-ai-perplexity
import os

from prism_perplexity import AgentClient, search, urllib_transport

http = urllib_transport(os.environ["PERPLEXITY_API_KEY"])

for result in search(http, "what changed in the MCP 2026-07-28 revision"):
    print(result["title"], result["url"])

agent = AgentClient(http)
run = agent.create("Summarise this week's changes to the OpenAI Responses API.")
done = agent.wait(run.id)

print(done.text())

urllib_transport(api_key, base_url, timeout) uses the standard library. Any callable that takes an HttpRequest (method, path, body) and returns an HttpResponse (status, json) works in its place, so tests need no network.

search(http, query, options) returns web results with no model call: the sources, without paying for an answer. query can be a string or a list of strings. Results are plain dicts, because Perplexity documents the payload as open-ended.

Embeddings

embeddings(http, model, inputs, contextualized=False) calls /embeddings, which embeds each input on its own. With contextualized=True it calls /contextualized-embeddings, which treats the inputs as chunks of one document and embeds each with the others in view.

Agent API

AgentClient starts a long-running run, polls it and cancels it.

  • create(input, options) starts a run in the background by default, so no request is held open for minutes.
  • retrieve(run_id) gets a snapshot; cancel(run_id) acknowledges a request. cancelling is neither terminal nor successful.
  • wait(run_id, max_attempts=300, interval_seconds=1.0) polls until the run finishes, and raises agent_wait_timed_out if it does not. Five minutes, because the reference measured a routine deep-research call at 57-59 seconds — a one-minute ceiling reports a failure that did not happen.
  • AgentResponse.text() joins the text parts of the output. is_successful() is true only for a completed run.
  • incomplete_reason() returns the string incomplete_details.reason, including an empty string, or None when absent or malformed.

A cancellation acknowledgement's response_id (or legacy id, only when response_id is absent) must match the requested ID exactly. A malformed or mismatched acknowledgement raises invalid_response; cancellation state is uncertain, so call retrieve(run_id) to check it. The client does not retry cancellation automatically. create() and retrieve() still use their own id field, and raw retains the provider body.

Errors

Every failure is a PerplexityError with a stable code: unreadable_response, provider_error, invalid_response, agent_wait_timed_out, invalid_argument. Match on the code, not the message.

Parity

prism-parity's perplexity-agent-response corpus compares how Agent API responses are read. This port and the TypeScript port agree on all forty-five cases; the original seventeen rows are unchanged. The PHP reference differs on most of them:

  • an empty usage is a list in PHP and a dict here;
  • a JSON array body is invalid_response in PHP and unreadable_response here;
  • a numeric-string created_at becomes a number in PHP and None here;
  • a refusal carries no machine-readable code in PHP.

Status handling, polling and citations agree in all three.

License

MIT. See LICENSE.

Metadata

Release files for prism-ai-perplexity 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prism-ai-perplexity 0.2.0
File Size Uploaded Provenance Actions
prism_ai_perplexity-0.2.0.tar.gz 8.8 kB With provenance Details for prism_ai_perplexity-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for prism-ai-perplexity 0.2.0
File Interpreter ABI Platform Actions
prism_ai_perplexity-0.2.0-py3-none-any.whl Python 3 none any Details for prism_ai_perplexity-0.2.0-py3-none-any.whl

Total release size: 18.6 kB

Release files / prism_ai_perplexity-0.2.0.tar.gz

Download URL prism_ai_perplexity-0.2.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9fb33d0603b5304b7f7f252394902c70eae0a2408dd696de1d9c49d16ec25378
BLAKE2b-256 checksum
How to use checksums
2d495ec049bda0e718cd33cd435122fbcfa1e953bb9a6c1ab7d7bb12c4603daa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / prism_ai_perplexity-0.2.0-py3-none-any.whl

Download URL prism_ai_perplexity-0.2.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d73eb84fe1cbb13f3e052a933cb47d91f108717ed5cb24ff226eba94e2316f93
BLAKE2b-256 checksum
How to use checksums
467124f45f9a94c7372e465a468c74b0d25f08aca7f244532bdacc75c579422a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for prism-ai-perplexity 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for prism_ai_perplexity-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page