Skip to main content
Brave API banner

PyPI version Python versions CI Semantic release

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.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())
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/:

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

Star History Chart

License

MIT. See LICENSE.

Metadata

Release files for brave-api-python 1.1.1

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

Source distribution (sdist)

Source distribution for brave-api-python 1.1.1
File Size Uploaded Provenance Actions
brave_api_python-1.1.1.tar.gz 216.0 kB With provenance Details for brave_api_python-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for brave-api-python 1.1.1
File Interpreter ABI Platform Actions
brave_api_python-1.1.1-py3-none-any.whl Python 3 none any Details for brave_api_python-1.1.1-py3-none-any.whl

Total release size: 269.4 kB

Release files / brave_api_python-1.1.1.tar.gz

Download URL brave_api_python-1.1.1.tar.gz
Size 216.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f8fea58f71589e01ac022cd8b4ca55f3e1455635c2434b9cfc904242e33e03d8
BLAKE2b-256 checksum
How to use checksums
30c20670719edee5622faed15fe58591050ad06db0bf1d7c8fd95ebd4c98dfc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / brave_api_python-1.1.1-py3-none-any.whl

Download URL brave_api_python-1.1.1-py3-none-any.whl
Size 53.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
647c7cfa7250c4c1984a3ccdb961836b728ba181af9d264189622a994e57cafb
BLAKE2b-256 checksum
How to use checksums
2bb1fec82a64158a9f042048b9224d6f82940c3ab2a750055f21cb5013d20112
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Security for brave-api-python 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for brave_api_python-1.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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