An async Python client for Brave Search, providing streaming AI answers and structured web search in a single, typed interface - with a built-in Model Context Protocol (MCP) server.
Features
- Async Brave Ask client with blocking and streaming responses
- Multi-turn conversations and multimodal image input
- Structured search for web, images, news, videos, and Brave Goggles
- Pagination, autocomplete suggestions, and typed Pydantic models
- Configurable language, region, safe search, timeout, retries, and proxies
- FastMCP server with stdio and HTTP transports
Documentation
The complete documentation is available at brave-api-python.readthedocs.io.
It includes detailed guides, configuration, MCP setup, examples, error handling, and the generated API reference.
Installation
Requires Python 3.11+.
uv add brave-api-python
For MCP support:
uv add "brave-api-python[mcp]"
With pip:
pip install brave-api-python
From source:
git clone https://github.com/iqbalmh18/brave-api.git
cd brave-api
uv sync --group dev
Quick start
Ask
import asyncio
from brave_api import BraveClient
async def main() -> None:
async with BraveClient() as client:
result = await client.ask("What is quantum computing?")
print(result.text)
print(f"Sources: {len(result.urls)}")
asyncio.run(main())
Search
async with BraveClient() as client:
result = await client.search("Python asyncio tutorial")
for item in result.web[:3]:
print(item.title, item.url)
All public methods are asynchronous and should normally be used inside
async with BraveClient().
Search verticals
Every search method returns the same SearchResult response envelope:
async with BraveClient() as client:
web = await client.search("Python asyncio")
images = await client.search_images("Python logo")
news = await client.search_news("Python release")
videos = await client.search_videos("Python tutorial")
goggles = await client.search_goggles("privacy search")
print(web.web)
print(images.images)
print(news.news)
print(videos.videos)
print(goggles.web)
Pagination uses Brave's page-based offset value, where 0 is the first page:
async with BraveClient() as client:
first_page = await client.search_news("Python release", offset=0)
second_page = await client.search_news("Python release", offset=1)
Use spellcheck=False for exact keyword matching. Use client.suggest() for
autocomplete suggestions.
Streaming
from brave_api import BraveClient, StreamEventType
async with BraveClient() as client:
async for event in client.ask_stream("Explain WebAssembly"):
if event.type is StreamEventType.TEXT_DELTA:
print(event.delta, end="", flush=True)
Configuration
from brave_api import BraveClient, ClientConfig
config = ClientConfig(
language="id",
ui_lang="id-id",
country="id",
safesearch="moderate",
timeout=60.0,
max_retries=3,
proxies=["http://user:password@proxy.example:8080"],
)
async with BraveClient(config) as client:
result = await client.search("berita teknologi")
See the configuration guide for all supported options.
MCP server
Install the optional MCP dependency:
uv add "brave-api-python[mcp]"
Run locally over stdio:
brave-api-mcp
Or run an HTTP server:
brave-api-mcp --http --host 127.0.0.1 --port 8000
Available search tools include search, search_images, search_news,
search_videos, search_goggles, and suggest, in addition to ask.
Examples
Runnable examples are available in examples/:
search_verticals.py— all search verticals and paginationsearch_suggest.py— web search and autocompletestreaming.py— streaming eventsmultimodal.py— image inputconfiguration.py— configuration and proxies
Run one with:
uv run python examples/search_verticals.py
Development
uv sync --group dev
uv run pytest
uv run ruff check .
uv run ruff format --check .
uv run pyright
For API details, error handling, conversations, and complete MCP configuration, see the full documentation.
Star History
License
MIT. See LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brave_api_python-1.1.0.tar.gz.
File metadata
- Download URL: brave_api_python-1.1.0.tar.gz
- Upload date:
- Size: 215.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
051db68a3b26d34e700fa507819126bd01e9df66d5fd1c1b15097a43f3ac533e
|
|
| MD5 |
92142ecdddbecca1c6f74eaed9d6f92b
|
|
| BLAKE2b-256 |
3a75ef293dae5366bd15e1e06bb85a2c06c9a639a4e0df2fdebb04fccfeaf67d
|
Provenance
The following attestation bundles were made for brave_api_python-1.1.0.tar.gz:
Publisher:
publish.yml on iqbalmh18/brave-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brave_api_python-1.1.0.tar.gz -
Subject digest:
051db68a3b26d34e700fa507819126bd01e9df66d5fd1c1b15097a43f3ac533e - Sigstore transparency entry: 2490880731
- Sigstore integration time:
-
Permalink:
iqbalmh18/brave-api@dceaf448f20667350d7aabd4c55fc744d5fd61fc -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/iqbalmh18
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dceaf448f20667350d7aabd4c55fc744d5fd61fc -
Trigger Event:
push
-
Statement type:
File details
Details for the file brave_api_python-1.1.0-py3-none-any.whl.
File metadata
- Download URL: brave_api_python-1.1.0-py3-none-any.whl
- Upload date:
- Size: 53.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da5ae466b62ab075a91b732e458abb6adfd9f9fbd1894c18301ebbf97cb615b1
|
|
| MD5 |
3d0cb15b0b84bc7f329f260d82c524cf
|
|
| BLAKE2b-256 |
f17653c6bb436ef5f95f0fedaf6cc71e6e3e6efa0abb40dc9ab3ece52040e0c4
|
Provenance
The following attestation bundles were made for brave_api_python-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on iqbalmh18/brave-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brave_api_python-1.1.0-py3-none-any.whl -
Subject digest:
da5ae466b62ab075a91b732e458abb6adfd9f9fbd1894c18301ebbf97cb615b1 - Sigstore transparency entry: 2490880898
- Sigstore integration time:
-
Permalink:
iqbalmh18/brave-api@dceaf448f20667350d7aabd4c55fc744d5fd61fc -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/iqbalmh18
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dceaf448f20667350d7aabd4c55fc744d5fd61fc -
Trigger Event:
push
-
Statement type: