Skip to main content

🔍 Perplexity Search

Python 3.x License: MIT PRs Welcome GitHub Issues GitHub Stars

A powerful Python tool for performing technical searches using the Perplexity API, optimized for retrieving precise facts, code examples, and numerical data.

Perplexity Search Demo

📋 Table of Contents

Overview • Features • Installation • Usage • Configuration • Requirements • Error Handling • Contributing • FAQ • License

🌟 Overview

Perplexity Search is a command-line tool and Python library that leverages the power of Perplexity AI to provide accurate, technical search results. It's designed for developers, researchers, and technical users who need quick access to precise information, code examples, and technical documentation. It also includes an interactive mode for multi-turn conversations.

✨ Features

  • Interactive Mode: Engage in a conversational interface where you can ask multiple queries in sequence.
  • Conversation Context: Maintain context across multiple turns in interactive mode.
  • Markdown Output: Save conversation history to a markdown file.
  • Perform searches using different LLaMA models (small, large, huge)
  • Configurable API key support via environment variable or direct input
  • Command-line interface for easy usage
  • Focused on retrieving technical information with code examples
  • Returns responses formatted in markdown
  • Optimized for factual and numerical data
  • Debug logging

Installation

pip install plexsearch

Usage

As a Python Module

from perplexity_search import perform_search

# Using environment variable for API key
result = perform_search("What is Python's time complexity for list operations?")

# Or passing API key directly
result = perform_search("What are the differences between Python 3.11 and 3.12?", api_key="your-api-key")

# Specify a different model
result = perform_search("Show me example code for Python async/await", model="llama-3.1-sonar-huge-128k-online")

Command Line Interface

Interactive Mode

To enter interactive mode, simply run the command without any query arguments:

plexsearch

In interactive mode, you can type your queries one by one. Type exit or press Ctrl-D to quit the interactive session.

# Basic search
plexsearch "What is Python's time complexity for list operations?"

# Specify model
plexsearch --model llama-3.1-sonar-huge-128k-online "What are the differences between Python 3.11 and 3.12?"

# Use specific API key
plexsearch --api-key your-api-key "Show me example code for Python async/await"

# Multi-word queries work naturally
plexsearch tell me about frogs

# Disable streaming output
plexsearch --no-stream "tell me about frogs"

# Show numbered citations at the bottom of the response
plexsearch --citations "tell me about Python's GIL"

Note: Streaming is automatically disabled when running inside Aider to prevent
filling up the context window.

Configuration

API Key

Set your Perplexity API key in one of these ways:

  1. Environment variable:
    export PERPLEXITY_API_KEY=your-api-key
    # Or add to your ~/.bashrc or ~/.zshrc for persistence
    echo 'export PERPLEXITY_API_KEY=your-api-key' >> ~/.bashrc
    
  2. Pass directly in code or CLI: --api-key your-api-key

Available Models

The following models can be specified using the --model parameter:

  • llama-3.1-sonar-small-128k-online (Faster, lighter model)
  • llama-3.1-sonar-large-128k-online (Default, balanced model)
  • llama-3.1-sonar-huge-128k-online (Most capable model)

Conversation Logging

You can log your conversation to a file using the --log-file parameter.

Markdown Output

You can save your conversation to a markdown file using the --markdown-file parameter.

Requirements

  • Python 3.x
  • requests library
  • rich library
  • feedparser library
  • Perplexity API key (obtain from Perplexity API)

Error Handling

The tool includes error handling for:

  • Missing API keys
  • Invalid API responses
  • Network issues
  • Invalid model selections

Contributing

We welcome contributions! Please see our CONTRIBUTING.md for more details on how to contribute to this project. Check our CHANGELOG.md for recent updates and changes.

FAQ

Q: How do I get an API key for Perplexity?

A: You can obtain an API key by signing up on the Perplexity API website.

Q: What models are available for search?

A: The available models are small, large, and huge.

License

MIT License - see the LICENSE file for details

Metadata

Release files for plexsearch 0.2.2

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

Source distribution (sdist)

Source distribution for plexsearch 0.2.2
File Size Uploaded
plexsearch-0.2.2.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for plexsearch 0.2.2
File Interpreter ABI Platform
plexsearch-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.2 kB

Release files / plexsearch-0.2.2.tar.gz

Download URL plexsearch-0.2.2.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e04f4715f6b5d71d9eb05b9206384f990d6c5d70ca7bddd9a1bf80642c1a9c60
BLAKE2b-256 checksum
How to use checksums
4c5db4d3a59a9b92a5fe11af694419d3c4dbde0e21f3e028285a2660d0ecd6e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.7 Linux/5.15.0-126-generic

Release files / plexsearch-0.2.2-py3-none-any.whl

Download URL plexsearch-0.2.2-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03477a1903110426beafd447455a6261139185ee83dc3ecf6756967c8d6dd9c2
BLAKE2b-256 checksum
How to use checksums
aca5cbfe25295834946983d28452e7310015af34f6b16b6b9875fe71e6e7391c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.7 Linux/5.15.0-126-generic

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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