Skip to main content

🦁 Brave Search Python Client supporting Web, Image, News and Video search.

Project description

[PRE-ALPHA] 🦁 Brave Search Python Client

License PyPI - Python Version CI Quality Gate Security Maintainability Technical Debt Coverage Ruff GitHub - Version GitHub - Commits PyPI - Version PyPI - Status Docker - Version Docker - Size

⚠️ WARNING: This project is currently in pre-alpha phase, i.e. partly functional. Feel free to already watch or star the repository to stay updated on its progress.

Overview

Brave Search Python Client supporting Web, Image, News and Video search.

Example Use

Streamlit App

Streamlit App deployed on Streamlit Community Cloud

TK (Screencast)

Jupyter Notebook

Jupyter Notebook

Show more

Minimal Python Script:

import asyncio
import json
import os

from dotenv import load_dotenv

from brave_search_python_client import (
    BraveSearch,
    CountryCode,
    ImagesSearchRequest,
    LanguageCode,
    NewsSearchRequest,
    VideosSearchRequest,
    WebSearchRequest,
)

# Load .env file and check for Brave Search API Key
load_dotenv()
api_key = os.getenv("BRAVE_SEARCH_API_KEY")
if not api_key:
    raise Exception("BRAVE_SEARCH_API_KEY found in environment")


async def search():
    """Run various searches using the Brave Search Python Client"""

    # Initialize the BraveSearch client, using the API key from the environment
    bs = BraveSearch()

    # Perform a web search
    response = await bs.web(WebSearchRequest(q="jupyter"))

    # Print results as JSON
    print("# Web search")
    print("## JSON response")
    print(json.dumps(response.model_dump(), indent=2))

    # Iterate over web hits and render links in markdown
    print("## Iterate and render")
    for result in response.web.results if response.web else []:
        print(f"[{result.title}]({result.url})")

    # Advanced search with parameters
    response = await bs.web(
        WebSearchRequest(
            q="python programming",
            country=CountryCode.DE,
            search_lang=LanguageCode.DE,
        )
    )

    print("# Advanced search results")
    for result in response.web.results if response.web else []:
        print(f"[{result.title}]({result.url})")

    # Search and render images
    print("# Images")
    response = await bs.images(ImagesSearchRequest(q="cute cats"))
    for image in response.results if response.results else []:
        print(f"![{image.source}]({image.url})")

    # Search and render videos
    print("# Videos")
    response = await bs.videos(VideosSearchRequest(q="singularity is close"))
    for video in response.results if response.results else []:
        print(f"![{video.title}]({video.url})")

    # Search and render news
    print("# News")
    response = await bs.news(NewsSearchRequest(q="AI"))
    for item in response.results if response.results else []:
        print(f"![{item.title}]({item.url})")


# Execute the search function
# Alternatively use await(search()) in an async function
asyncio.run(search())

Command Line Interface (CLI)

Run with uvx

Create .env file with API key:

./setup--dot-env YOUR_BRAVE_SEARCH_API_KEY

Show available commands:

uvx brave-search-python-client --help

Search the web for "hello world":

uvx brave-search-python-client web "hello world"

Show options for web search

uvx brave-search-python-client web --help

Search images:

uvx brave-search-python-client images "hello world"

Show options for image search

uvx brave-search-python-client images --help

Search videos:

uvx brave-search-python-client videos "hello world"

Show options for videos search

uvx brave-search-python-client videos --help

Search news:

uvx brave-search-python-client news "hello world"

Show options for news search

uvx brave-search-python-client news --help

Run with Docker

Show options for news search

docker run helmuthva/brave-search-python-client news --help

Docker

Note: Replace YOUR_BRAVE_SEARCH_API_KEY with your API key in the following examples.

Show available commands:

docker run helmuthva/brave-search-python-client --help

Search the web:

docker run --env BRAVE_SEARCH_API_KEY=YOUR_BRAVE_SEARCH_API_KEY helmuthva/brave-search-python-client web "hello world"

Show options for web search

docker run helmuthva/brave-search-python-client web --help

Search images:

docker run --env BRAVE_SEARCH_API_KEY=YOUR_BRAVE_SEARCH_API_KEY helmuthva/brave-search-python-client images "hello world"

Show options for image search

docker run helmuthva/brave-search-python-client images --help

Search videos:

docker run --env BRAVE_SEARCH_API_KEY=YOUR_BRAVE_SEARCH_API_KEY helmuthva/brave-search-python-client videos "hello world"

Show options for video search

docker run helmuthva/brave-search-python-client videos --help

Search news:

docker run --env BRAVE_SEARCH_API_KEY=YOUR_BRAVE_SEARCH_API_KEY helmuthva/brave-search-python-client news "hello world"

Show options for news search

docker run helmuthva/brave-search-python-client news --help

Extra: MCP Server

TK

Contributing

Please read our Contributing Guidelines for how to setup your development environment, and guidance for making pull requests.

Resources

Star History

Star History Chart

Project details


Release history Release notifications | RSS feed

This version

0.0.9

Download files

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

Source Distribution

brave_search_python_client-0.0.9.tar.gz (13.8 MB view details)

Uploaded Source

Built Distribution

brave_search_python_client-0.0.9-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file brave_search_python_client-0.0.9.tar.gz.

File metadata

File hashes

Hashes for brave_search_python_client-0.0.9.tar.gz
Algorithm Hash digest
SHA256 cb6fbddc2a662356207f7c4dd1a6381b0d35e04a4b1e4b4bfcc9ef07f0ed275b
MD5 063ff0f2c32132ff9cb3a0497c792cd3
BLAKE2b-256 421040711f9b178ea75b79f7685e629c96d4fe5da08086a1e32e8482fc71baf1

See more details on using hashes here.

File details

Details for the file brave_search_python_client-0.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for brave_search_python_client-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 951bfe81ed00cc9683d15dd03bae3b5f19e495975d5793e1bd6d64c9d3de6691
MD5 a305be33e47a0858b9a8678d545e87a7
BLAKE2b-256 e691784dd4fb4d562c282fbdd6523b62df290287e78807242acb1f592475b0ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page