Skip to main content

Python scraper to extract AI responses from Perplexity's web interface.

Project description

Logo

Perplexity WebUI Scraper

Python scraper to extract AI responses from Perplexity's web interface.

PyPI Python License


📚 Full Documentation & Advanced Guide: https://henrique-coder.github.io/perplexity-webui-scraper


What is this?

This library lets you interact with Perplexity AI programmatically using the same web endpoints as the browser — no official API key required. It supports conversations, file uploads, streaming, an MCP server for AI agents, and a drop-in OpenAI-compatible REST API.

  • Requirements: A Perplexity Pro or Max account and your browser session token.
  • Key Features: Full model support (GPT-5.4, Opus 4.6, Deep Research…), file attachments, streaming, MCP Server, OpenAI-compatible API.

Installation

# Core library only
uv add perplexity-webui-scraper

# Interactive session token generator (adds rich)
uv add "perplexity-webui-scraper[cli]"

# MCP Server for AI agents (adds fastmcp)
uv add "perplexity-webui-scraper[mcp]"

# OpenAI-compatible API server (adds fastapi + uvicorn + typer)
uv add "perplexity-webui-scraper[api]"

# Everything at once
uv add "perplexity-webui-scraper[cli,mcp,api]"

Quick Start

1. Get your session token

# Interactive CLI wizard — walks you through email auth
uv run get-perplexity-session-token

Or retrieve __Secure-next-auth.session-token manually from your browser cookies on perplexity.ai.

2. Basic usage

from perplexity_webui_scraper import Perplexity

client = Perplexity(session_token="YOUR_TOKEN")
conversation = client.create_conversation()

conversation.ask("What is quantum computing?")
print(conversation.answer)

# Follow-ups preserve context automatically
conversation.ask("Explain it simpler")
print(conversation.answer)

3. Streaming

for chunk in conversation.ask("Explain AI", stream=True):
    if chunk.last_chunk:
        print(chunk.last_chunk, end="", flush=True)

4. Choose a model

from perplexity_webui_scraper import ConversationConfig

conversation = client.create_conversation(ConversationConfig(model="gpt-5.4-thinking"))
conversation.ask("Solve this step by step: ...")
print(conversation.answer)

Available CLIs

Command Extra Description
get-perplexity-session-token cli Interactive email auth wizard to generate a session token
perplexity-webui-scraper-mcp mcp Start the MCP server (used via MCP config, not directly)
perplexity-webui-scraper-api api Start the OpenAI-compatible REST API server

OpenAI-Compatible API

Run a local server that accepts OpenAI-formatted requests and forwards them to Perplexity. Works as a drop-in replacement for any OpenAI client — authentication is done per-request via Authorization: Bearer, exactly like the real API.

# Start the server (no token needed at startup)
perplexity-webui-scraper-api

# Custom host and port
perplexity-webui-scraper-api --host 0.0.0.0 --port 8080

# Development mode with auto-reload
perplexity-webui-scraper-api --reload

CLI options

Option Short Default Description
--host -H 127.0.0.1 Bind address
--port -p 8000 Port to listen on
--reload False Enable auto-reload (dev)
--log-level info Uvicorn log level

Authentication

Pass your Perplexity session token as the API key in every request — exactly like the OpenAI API:

# curl
curl http://localhost:8000/v1/chat/completions \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "best", "messages": [{"role": "user", "content": "Hello!"}]}'

# Streaming
curl -N http://localhost:8000/v1/chat/completions \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-5.4", "messages": [{"role": "user", "content": "Hello!"}], "stream": true}'
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="YOUR_SESSION_TOKEN",  # sent as Authorization: Bearer automatically
)

response = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

API endpoints

Method Path Description
GET /v1/models List all available models
POST /v1/chat/completions Chat completion (streaming + non-streaming)
GET /docs Interactive Swagger UI
GET /redoc ReDoc documentation

Fields not supported by Perplexity (e.g. temperature, top_p) are accepted for client compatibility but silently ignored.

MCP Server

Expose every Perplexity model as a separate tool for AI agents (Claude Desktop, Antigravity, etc.):

{
  "mcpServers": {
    "perplexity-webui-scraper": {
      "command": "uvx",
      "args": [
        "--from",
        "perplexity-webui-scraper[mcp]@latest",
        "perplexity-webui-scraper-mcp"
      ],
      "env": { "PERPLEXITY_SESSION_TOKEN": "your_token_here" }
    }
  }
}

See the full MCP documentation for all tools and configuration details.

Disclaimer

This is an unofficial library. It uses internal APIs that may change without notice. Use at your own risk. By using this library, you agree to Perplexity AI's Terms of Service.

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

perplexity_webui_scraper-0.7.1.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

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

perplexity_webui_scraper-0.7.1-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file perplexity_webui_scraper-0.7.1.tar.gz.

File metadata

  • Download URL: perplexity_webui_scraper-0.7.1.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for perplexity_webui_scraper-0.7.1.tar.gz
Algorithm Hash digest
SHA256 8c416db4a41cb0fe2fa986523c1eec59fca39535b2b585fdd11fe631bc97f4f1
MD5 e1beb90148b2c78158649e01a77da34e
BLAKE2b-256 fd5cb7f6937a4239c0986557c2cc26b1e7db30dedba258909598d4f7e3f13421

See more details on using hashes here.

File details

Details for the file perplexity_webui_scraper-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: perplexity_webui_scraper-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for perplexity_webui_scraper-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc18eac03a876eb8412eaa0ddc63797b9196cabccffa7b0f25f57182fec610ef
MD5 f00aed7c368448c394f0c893fc66da63
BLAKE2b-256 8ae0f04bbabd7aed49b580823ba0182b54abc60800991691bc089072b2d63b44

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