Perplexity Batch Query Tool â
Automates batch queries to Perplexity.ai using Playwright and Brave browser.
Features â
- Batch process multiple queries from a text file
- Save results to JSONL and MongoDB
- Model selection support
- Incremental output files
- Tab-per-query isolation
Configuration â
Set environment variables to customize behavior:
Browser Settings â
AUTOMATION_PROFILE: Name of separate profile for automation (default:AutomationProfile)BRAVE_EXE: Path to Brave executable (default:C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe)BRAVE_USER_DATA: Path to Brave user data directoryBRAVE_PROFILE: Profile directory name to use instead of automation profile (e.g.,Default)BRAVE_PROFILE_PATH: Full path to specific profile directoryHEADLESS: Run in headless mode - not recommended (0or1, default:0)
Query Settings â
INPUT_FILE: Input file with queries (default:queries.txt)OUTPUT_FILE: Output JSONL file (default:results.jsonl)DELAY_SEC: Delay between queries in seconds (default:2.0)TIMEOUT_MS: Timeout for page operations in milliseconds (default:120000)MODEL: Specify which model to use (e.g.,"GPT-4","Claude","Pro")
MongoDB Settings â
MONGO_URI: MongoDB connection URI (default:mongodb://localhost:27017/)MONGO_DB: Database name (default:perplexity_)MONGO_COLLECTION: Collection name (default:queries)
Model Selection â
You can specify which Perplexity model to use for queries:
bash
# Windows PowerShell
$env:MODEL="GPT-4"
python run_perplexity_batch.py
# Windows CMD
set MODEL=Claude
python run_perplexity_batch.pyCommon model names:
"GPT-4"or"gpt-4""Claude"or"claude-3.5-sonnet""Pro"or"sonar-pro"
The script will attempt to select the specified model in the Perplexity UI. If model selection fails, it will fall back to the default model and continue processing.
Input File Format â
The queries.txt file supports two formats:
- Simple format (one query per line):
What is the capital of France?
Explain quantum computing- CSV format (id,query):
q1,What is the capital of France?
q2,Explain quantum computingOutput â
Results are saved to:
- JSONL file: Incremental files like
results_001.jsonl,results_002.jsonl, etc. - MongoDB: If configured and available
Each result includes:
id: Query identifiertimestamp: ISO timestampquery: The original queryanswer: Perplexity's responseurl: URL of the result pagemodel: The model used (if specified)
Usage â
Quick Start â
powershell
# Simple - just run it!
.\run.ps1
# Or run directly
python run_perplexity_batch.pyHow it works:
- â
Uses a separate profile called
AutomationProfile(not your Default profile) - â Your main Brave browser can stay open
- â Browser window opens minimized in the background
- â First run will create the profile and require Perplexity login
- â Subsequent runs reuse the logged-in session
First-Time Setup â
Option 1: Manual login (Recommended)
- Run the script once:
.\run.ps1 - Log into Perplexity in the browser window that opens
- Close the automation browser
- Future runs will use the saved session
Option 2: Clone your existing profile
powershell
# Close all Brave windows first!
.\clone_profile.ps1This copies your Default profile (with all logins) to AutomationProfile.
Customization â
powershell
# With custom model
$env:MODEL="Grok 4"
.\run.ps1
# With custom input/output files
$env:INPUT_FILE="my_queries.txt"
$env:OUTPUT_FILE="my_results.jsonl"
.\run.ps1Alternative: Use Your Main Profile â
If you want to use your main profile's cookies/session:
powershell
$env:BRAVE_PROFILE="Default"
python run_perplexity_batch.pyâ ī¸ Note: This requires closing all Brave windows first.
Requirements â
Install dependencies:
bash
pip install -r requirements.txtImportant Notes â
- Default mode: Uses separate automation profile - your main browser can stay open!
- Using your main profile: Requires closing all Brave windows and disabling "Continue running background apps"
- Ensure you're logged into Perplexity.ai in the profile being used
- Model selection requires appropriate Perplexity subscription for premium models
- First run with automation profile will require logging into Perplexity