Skip to main content

Brave Search API wrapper

Project description

Brave Search API

Overview

Python wrapper for the Brave Search API.

Brave Search doesn’t track you or your queries, it's a privacy-preserving alternative to Google Search. It offers many endpoints for developers to build on top of. This module is a wrapper for the Brave Search API.

This repo is under active development, functionality may change. If you have any suggestions or requests, please open an issue.

Installation

To get started, install the package using pip:

pip install brave-search

Usage

The module supports both synchronous and asynchronous requests. Your Brave API key can either be passed as an environment variable under BRAVE_API_KEY or as an argument to the Brave class.

from brave import Brave

brave = Brave()

query = "cobalt mining"
num_results = 10

search_results = brave.search(q=query, count=num_results)

The search_results object will include all the data returned by the Brave Search API. You can access Web, News and Video results from the websearch endpoint as follows:

web_results = search_results.web_results
news_results = search_results.news_results
video_results = search_results.video_results

The module also supports asynchronous requests:

from brave import AsyncBrave

brave = AsyncBrave()

query = "cobalt mining"
num_results = 10

search_results = await brave.search(q=query, count=num_results)

Features

Download PDFs:

Use the download_pdfs method to download all PDFs found in the search results. This method returns a list of file paths to the downloaded PDFs. You can use Goggles to boost PDFs in your search results.

from brave import Brave

brave = Brave()

query = "cobalt mining"
num_results = 10

search_results = brave.search(q=query, count=num_results)

search_results.download_pdfs()

Aggregate Price Data

Use the product_prices method to get a list of prices for a set of search results. This method returns a list of prices found in the search results. If no prices are found, an empty list is returned. This method does not currently support converting currencies.

    from brave import Brave

    brave = Brave()

    query = "Blue Tack"
    num_results = 10
    country = "US"
    search_results = brave.search(q=query, count=num_results, country=country)
    print(search_results.product_prices())
    # >> [6.28, 5.98, 4.99, 13.18, 6.59, 7.8, 5.56, 10.79, 5.02, 10.56, 16.95, 9.99, 23.59, 16.31, 11.96]
    print(search_results.product_price_ranges())
    # >> (4.99, 23.59)

Aggregate Review Data

Use the average_product_review_score method to get the average review score for a set of search results. This method converts all review scores to a 100 point scale.

from brave import Brave

brave = Brave()

query = "Blue Tack"
num_results = 10
search_results = brave.search(q=query, count=num_results)
print(search_results.average_product_review_score())
# >> 88.13333333333333

Goggles

Brave is a powerful search engine that allows for the usage of goggles to rerank your search results to meet your use-case. Goggles enable any individual—or community of people—to alter the ranking of Brave Search by using a set of instructions (rules and filters). Anyone can create, apply, or extend a Goggle. Essentially Goggles act as a custom re-ranking on top of the Brave search index.

Here we use a goggle which prioritizes academic and archival sources.

from brave import Brave

query = "cobalt mining"
goggle_url = "https://raw.githubusercontent.com/CSamuelAnderson/Brave-goggles/main/academic-and-archival.goggle"
num_results = 10
result_filter = "web" # must be comma separated string

search_results = brave.search(q=query, goggles_id=goggle_url, count=num_results, result_filter=result_filter)

You can also make use of Goggles that have been directly contributed to this package:

from brave import Brave
from brave.goggles import thought_leadership

query = "cobalt mining"
num_results = 10

search_results = brave.search(q=query, goggles_id=thought_leadership, count=num_results)

Local Installation

This package uses Poetry for dependency management. To start developing here, you need to install Poetry

Once you have Poetry installed on your system simply run:

make init

Developing

Check the CONTRIBUTING.md for information about how to develop on this project.

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

brave_search-0.1.1.tar.gz (24.3 kB view details)

Uploaded Source

Built Distributions

brave_search-0.1.1-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

brave_search-0.1.1-py2.py3-none-any.whl (37.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file brave_search-0.1.1.tar.gz.

File metadata

  • Download URL: brave_search-0.1.1.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/21.4.0

File hashes

Hashes for brave_search-0.1.1.tar.gz
Algorithm Hash digest
SHA256 344a96df2d9837aeda7d2a137271e9dc32c79fc12ce6e7f72a17e97b1fb942f9
MD5 c65a8a1738026426ab111184517eb9c8
BLAKE2b-256 ecf28b18ad7812022e471894bfa0adcfe2c9468157477d974315b04ec478e441

See more details on using hashes here.

File details

Details for the file brave_search-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: brave_search-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 37.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/21.4.0

File hashes

Hashes for brave_search-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e97e6a9abb8bcccccf988dafa98303ebea35a058f2dbd0f76d1d4a38862ac91
MD5 24ab858dea60691703cb9bb6e21ecd08
BLAKE2b-256 730a197d859dd6c247a154a7ac94b1734af8926f83e401f0ab7e58fd88a13273

See more details on using hashes here.

File details

Details for the file brave_search-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: brave_search-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 37.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/21.4.0

File hashes

Hashes for brave_search-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fef6cf19362e26358ba20d1be5e47f41abf79d2d55028acc4f3e323f5122ee83
MD5 917f4382118b6cc860960aecbf2766f4
BLAKE2b-256 76fb792df3bb0fb2d51f7d6459dffaff26e9d672065ac588f25b62a93ab87eb0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page