Skip to content

Client

The Perplexity client is the main entry point for the library. Create one instance per session token and reuse it across conversations.

perplexity_webui_scraper.core.client.Perplexity

Perplexity(session_token: str, config: ClientConfig | None = None)

Web scraper client for Perplexity AI conversations.

The primary entry point. Create a single instance per session token and reuse it to share the underlying HTTP session and rate limiter.

Example
with Perplexity(session_token="...") as client:
    conversation = client.create_conversation()
    conversation.ask("Hello, world!")
    print(conversation.answer)
PARAMETER DESCRIPTION
session_token

The __Secure-next-auth.session-token cookie value. Obtained via the get-session-token CLI tool.

TYPE: str

config

Optional client settings (timeouts, retries, logging).

TYPE: ClientConfig | None DEFAULT: None

RAISES DESCRIPTION
ValueError

If session_token is empty.

Source code in src/perplexity_webui_scraper/core/client.py
def __init__(
    self,
    session_token: str,
    config: ClientConfig | None = None,
) -> None:
    if not session_token or not session_token.strip():
        raise ValueError("session_token cannot be empty")

    cfg = config or ClientConfig()
    configure_logging(level=cfg.logging_level, log_file=cfg.log_file)

    self._http = HTTPClient(
        session_token,
        timeout=cfg.timeout,
        impersonate=cfg.impersonate,
        max_retries=cfg.max_retries,
        retry_base_delay=cfg.retry_base_delay,
        retry_max_delay=cfg.retry_max_delay,
        retry_jitter=cfg.retry_jitter,
        requests_per_second=cfg.requests_per_second,
        rotate_fingerprint=cfg.rotate_fingerprint,
        max_init_query_length=cfg.max_init_query_length,
    )

    logger.info("Perplexity client initialized")

Functions

create_conversation

create_conversation(config: ConversationConfig | None = None) -> Conversation

Create and return a new :class:~perplexity_webui_scraper.Conversation.

PARAMETER DESCRIPTION
config

Optional per-conversation settings. Defaults to :class:~perplexity_webui_scraper.config.ConversationConfig defaults.

TYPE: ConversationConfig | None DEFAULT: None

RETURNS DESCRIPTION
Conversation

A new :class:~perplexity_webui_scraper.Conversation instance

Conversation

ready to receive queries.

Source code in src/perplexity_webui_scraper/core/client.py
def create_conversation(
    self,
    config: ConversationConfig | None = None,
) -> Conversation:
    """Create and return a new :class:`~perplexity_webui_scraper.Conversation`.

    Args:
        config: Optional per-conversation settings.  Defaults to
            :class:`~perplexity_webui_scraper.config.ConversationConfig`
            defaults.

    Returns:
        A new :class:`~perplexity_webui_scraper.Conversation` instance
        ready to receive queries.
    """
    return Conversation(self._http, config or ConversationConfig())

close

close() -> None

Close the HTTP session and release all underlying resources.

Source code in src/perplexity_webui_scraper/core/client.py
def close(self) -> None:
    """Close the HTTP session and release all underlying resources."""
    self._http.close()