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())

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/:

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brave_api_python-1.1.1.tar.gz (216.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

brave_api_python-1.1.1-py3-none-any.whl (53.4 kB view details)

Uploaded Python 3

File details

Details for the file brave_api_python-1.1.1.tar.gz.

File metadata

  • Download URL: brave_api_python-1.1.1.tar.gz
  • Upload date:
  • Size: 216.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for brave_api_python-1.1.1.tar.gz
Algorithm Hash digest
SHA256 f8fea58f71589e01ac022cd8b4ca55f3e1455635c2434b9cfc904242e33e03d8
MD5 211386cca2c4643b6388a16e1c1ecf0a
BLAKE2b-256 30c20670719edee5622faed15fe58591050ad06db0bf1d7c8fd95ebd4c98dfc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for brave_api_python-1.1.1.tar.gz:

Publisher: publish.yml on iqbalmh18/brave-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file brave_api_python-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for brave_api_python-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 647c7cfa7250c4c1984a3ccdb961836b728ba181af9d264189622a994e57cafb
MD5 69ec338389f335cead72edaa3b6304b3
BLAKE2b-256 2bb1fec82a64158a9f042048b9224d6f82940c3ab2a750055f21cb5013d20112

See more details on using hashes here.

Provenance

The following attestation bundles were made for brave_api_python-1.1.1-py3-none-any.whl:

Publisher: publish.yml on iqbalmh18/brave-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 files

1.1.0

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

0.1.1

2 files

0.1.0

2 files

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