Skip to main content

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

Project description

Perplexity WebUI Scraper

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

PyPI Python License


Installation

uv pip install perplexity-webui-scraper

Requirements

  • Perplexity Pro/Max account
  • Session token (__Secure-next-auth.session-token cookie from your browser)

Getting Your Session Token

You can obtain your session token in two ways:

Option 1: Automatic (CLI Tool)

The package includes a CLI tool to automatically generate and save your session token:

get-perplexity-session-token

This interactive tool will:

  1. Ask for your Perplexity email
  2. Send a verification code to your email
  3. Accept either a 6-digit code or magic link
  4. Extract and display your session token
  5. Optionally save it to your .env file

Features:

  • Secure ephemeral session (cleared on exit)
  • Automatic .env file management
  • Support for both OTP codes and magic links
  • Clean terminal interface with status updates

Option 2: Manual (Browser)

If you prefer to extract the token manually:

  1. Log in at perplexity.ai
  2. Open DevTools (F12) → Application/Storage → Cookies
  3. Copy the value of __Secure-next-auth.session-token
  4. Store in .env: PERPLEXITY_SESSION_TOKEN="your_token"

Quick Start

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-up
conversation.ask("Explain it simpler")
print(conversation.answer)

Streaming

for chunk in conversation.ask("Explain AI", stream=True):
    print(chunk.answer)

With Options

from perplexity_webui_scraper import (
    ConversationConfig,
    Coordinates,
    Models,
    SourceFocus,
)

config = ConversationConfig(
    model=Models.RESEARCH,
    source_focus=[SourceFocus.WEB, SourceFocus.ACADEMIC],
    language="en-US",
    coordinates=Coordinates(latitude=40.7128, longitude=-74.0060),
)

conversation = client.create_conversation(config)
conversation.ask("Latest AI research", files=["paper.pdf"])

API

Perplexity(session_token, config?)

Parameter Type Description
session_token str Browser cookie
config ClientConfig Timeout, TLS, etc.

Conversation.ask(query, model?, files?, citation_mode?, stream?)

Parameter Type Default Description
query str - Question (required)
model Model Models.BEST AI model
files list[str | PathLike] None File paths
citation_mode CitationMode CLEAN Citation format
stream bool False Enable streaming

Models

Model Description
Models.RESEARCH Research - Fast and thorough for routine research
Models.LABS Labs - Multi-step tasks with advanced troubleshooting
Models.BEST Best - Automatically selects the most responsive model based on the query
Models.SONAR Sonar - Perplexity's fast model
Models.GPT_52 GPT-5.2 - OpenAI's latest model
Models.GPT_52_THINKING GPT-5.2 Thinking - OpenAI's latest model with thinking
Models.CLAUDE_45_OPUS Claude Opus 4.5 - Anthropic's Opus reasoning model
Models.CLAUDE_45_OPUS_THINKING Claude Opus 4.5 Thinking - Anthropic's Opus reasoning model with thinking
Models.GEMINI_3_PRO Gemini 3 Pro - Google's newest reasoning model
Models.GEMINI_3_FLASH Gemini 3 Flash - Google's fast reasoning model
Models.GEMINI_3_FLASH_THINKING Gemini 3 Flash Thinking - Google's fast reasoning model with thinking
Models.GROK_41 Grok 4.1 - xAI's latest advanced model
Models.GROK_41_THINKING Grok 4.1 Thinking - xAI's latest reasoning model
Models.KIMI_K2_THINKING Kimi K2 Thinking - Moonshot AI's latest reasoning model
Models.CLAUDE_45_SONNET Claude Sonnet 4.5 - Anthropic's newest advanced model
Models.CLAUDE_45_SONNET_THINKING Claude Sonnet 4.5 Thinking - Anthropic's newest reasoning model

CitationMode

Mode Output
DEFAULT text[1]
MARKDOWN text[1](url)
CLEAN text (no citations)

ConversationConfig

Parameter Default Description
model Models.BEST Default model
citation_mode CLEAN Citation format
save_to_library False Save to library
search_focus WEB Search type
source_focus WEB Source types
time_range ALL Time filter
language "en-US" Response language
timezone None Timezone
coordinates None Location (lat/lng)

CLI Tools

Session Token Generator

get-perplexity-session-token

Interactive tool to automatically obtain your Perplexity session token via email authentication. The token can be automatically saved to your .env file for immediate use.

Disclaimer

This is an unofficial library. It uses internal APIs that may change without notice. Use at your own risk. Not for production use.

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.3.4.tar.gz (15.2 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.3.4-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: perplexity_webui_scraper-0.3.4.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for perplexity_webui_scraper-0.3.4.tar.gz
Algorithm Hash digest
SHA256 385f6a42081e2c4799926b9e855ea177e6f85ca07b2adc629e10f3ebdfe8b22a
MD5 cdfc3107e810f01dcedb22b80480d541
BLAKE2b-256 e36b06ef454af274e35b399c731c9a351477f8e4e4a84ee001ab46d759cc63cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: perplexity_webui_scraper-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for perplexity_webui_scraper-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b6b14e6f6894ccff030f82468c890ccc13585f69649643c0ab9aabc787a4aa5c
MD5 07bd4b3eba5bba836a7c3c0bf84411ac
BLAKE2b-256 b973b10621d646c53ddad21ecee8334adb252465730ec7de32b722ab667d47ad

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