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

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.0.tar.gz (215.9 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.0-py3-none-any.whl (53.4 kB view details)

Uploaded Python 3

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

Hashes for brave_api_python-1.1.0.tar.gz
Algorithm Hash digest
SHA256 051db68a3b26d34e700fa507819126bd01e9df66d5fd1c1b15097a43f3ac533e
MD5 92142ecdddbecca1c6f74eaed9d6f92b
BLAKE2b-256 3a75ef293dae5366bd15e1e06bb85a2c06c9a639a4e0df2fdebb04fccfeaf67d

See more details on using hashes here.

Provenance

The following attestation bundles were made for brave_api_python-1.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for brave_api_python-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da5ae466b62ab075a91b732e458abb6adfd9f9fbd1894c18301ebbf97cb615b1
MD5 3d0cb15b0b84bc7f329f260d82c524cf
BLAKE2b-256 f17653c6bb436ef5f95f0fedaf6cc71e6e3e6efa0abb40dc9ab3ece52040e0c4

See more details on using hashes here.

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

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

Release history Release notifications | RSS feed

1.1.1

2 files

This release

1.1.0 This release

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