Registry / http-networking / brave-search

brave-search

JSON →
library0.2.0pypypi✓ verified 88d ago

A Python wrapper for the Brave Search API that provides convenient access to Brave's privacy-preserving search endpoints. Current version 0.2.0, compatible with Python 3.8-3.12. Active development with monthly releases.

pip install brave-search
INSTALL
IMPORT
SIG · BRAVE-SEARCH
B
brave-search
http-networkingpythonv0.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Brave
✓ from brave import Brave
✗ from brave_search import Brave
The package name on PyPI is 'brave-search', but the import module is 'brave'.

Instantiate with your API key (set as env var BRAVE_API_KEY) and perform a simple web search.

from brave import Brave import os api_key = os.environ.get('BRAVE_API_KEY', '') brave = Brave(api_key=api_key) search_results = brave.search(q='Python programming', count=5) for result in search_results.web_results: print(result.title, result.url)
Debug
Known issues
gotchaThe Python package name on PyPI is 'brave-search', but the import module is 'brave'. Doing 'import brave_search' will fail.
fix
Use 'pip install brave-search' and 'from brave import Brave'.
affects: <0.2.0
gotchaThe API key must be set as an environment variable 'BRAVE_API_KEY' or passed directly to the Brave constructor. If not set, the library may raise an authentication error.
fix
Set 'BRAVE_API_KEY' environment variable or pass key to 'Brave(api_key="...")'.
affects: >=0.1.0
deprecatedThe 'raw' parameter was added in v0.1.8 to bypass pydantic validation if it fails. In earlier versions, pydantic validation errors would block the response entirely.
fix
Upgrade to >=0.1.8 and pass 'raw=True' to the search method to get raw JSON if validation fails.
affects: <0.1.8
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'brave_search'
The import module name is 'brave', not 'brave_search'. The PyPI package is 'brave-search'.
fix
Install with 'pip install brave-search' and import as 'from brave import Brave'.
brave.exceptions.BraveAPIException: API key not provided. Please set BRAVE_API_KEY environment variable.
The library requires a Brave Search API key, which must be provided either via environment variable or constructor argument.
fix
Set 'BRAVE_API_KEY' environment variable or pass key to 'Brave(api_key="...")'.
pydantic.error_wrappers.ValidationError: 1 validation error for WebSearchResult title none is not an allowed value (type=type_error.none.not_allowed)
The Brave Search API sometimes returns responses that don't match the expected pydantic schema (e.g., missing title).
fix
Upgrade to >=0.1.8 and use 'raw=True' in the search call to bypass validation, or handle the error gracefully.
Upgrade
Version history
0.2.0latest on PyPI · released Apr 27, 2024
Audit
Dependencies
requestsrequiredUsed for synchronous HTTP requests to the Brave Search API
aiohttpoptionalUsed for asynchronous HTTP requests (optional async support)
pydanticrequiredUsed for response model validation and serialization
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
brave-search — pip install brave-search · libregistry