Package: brave-search
Brave Search APIOverviewPython wrapper for theBrave 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.InstallationTo get started, install the package using pip:pipinstallbrave-searchUsageThe module supports both synchronous and asynchronous requests. Your Brave API key can either be passed as an environment variable underBRAVE_API_KEYor as an argument to the Brave class.frombraveimportBravebrave=Brave()query="cobalt mining"num_results=10search_results=brave.search(q=query,count=num_results)Thesearch_resultsobject will include all the data returned by the Brave Search API.
You can accessWeb,NewsandVideoresults from the websearch endpoint as follows:web_results=search_results.web_resultsnews_results=search_results.news_resultsvideo_results=search_results.video_resultsThe module also supports asynchronous requests:frombraveimportAsyncBravebrave=AsyncBrave()query="cobalt mining"num_results=10search_results=awaitbrave.search(q=query,count=num_results)FeaturesDownload PDFs:Use thedownload_pdfsmethod 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.frombraveimportBravebrave=Brave()query="cobalt mining"num_results=10search_results=brave.search(q=query,count=num_results)search_results.download_pdfs()Aggregate Price DataUse theproduct_pricesmethod 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.frombraveimportBravebrave=Brave()query="Blue Tack"num_results=10country="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 DataUse theaverage_product_review_scoremethod to get the average review score for a set of search results. This method converts all review scores to a 100 point scale.frombraveimportBravebrave=Brave()query="Blue Tack"num_results=10search_results=brave.search(q=query,count=num_results)print(search_results.average_product_review_score())# >> 88.13333333333333GogglesBrave is a powerful search engine that allows for the usage ofgogglesto rerank your search results to meet your use-case.Gogglesenable 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.frombraveimportBravequery="cobalt mining"goggle_url="https://raw.githubusercontent.com/CSamuelAnderson/Brave-goggles/main/academic-and-archival.goggle"num_results=10result_filter="web"# must be comma separated stringsearch_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:frombraveimportBravefrombrave.gogglesimportthought_leadershipquery="cobalt mining"num_results=10search_results=brave.search(q=query,goggles_id=thought_leadership,count=num_results)Local InstallationThis package uses Poetry for dependency management. To start developing here, you need to install PoetryFollow the instructions on theofficial docsOnce you have Poetry installed on your system simply run:makeinitDevelopingCheck theCONTRIBUTING.mdfor information about how to develop on this project.