Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

helmut-hoffer-von-ankershoffen/brave-search-python-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LicensePyPI - Python VersionCIRead the DocsQuality GateSecurityMaintainabilityTechnical DebtCode SmellsCodeQLDependabotRenovate enabledCoverageRuffMyPyGitHub - VersionGitHub - CommitsPyPI - VersionPyPI - StatusDocker - VersionDocker - SizeCopierOpen in Dev ContainersOpen in GitHub Codespaces

Note

🧠 This project was scaffolded using the templateoe-python-template withcopier.


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

Use Cases:

  1. Integrate into your Python code to help users find what they're looking for.
  2. Add to your AI applications to give LLMs access to current web information.
  3. Use the built-in CLI in shell scripts to get search results in JSON format.

Overview

Adding Brave Search Python Client to your project as a dependency is easy.

uv add brave-search-python-client# add dependency to your project

If you don't have uv installed followthese instructions.If you still prefer pip over the modern and fast package manageruv, you can install the library like this:

pip install brave-search-python-client# add dependency to your project

Obtain your Brave Search API key bysigning up here - the free tier includes 2,000requests per month. For guidance on how to integrate the Brave Search Pythonclient into your code base check out the examples below and explore thereference documentation.If you just want to try out the client without having to write code you can usethe integrated CLI:

export BRAVE_SEARCH_API_KEY=YOUR_API_KEY# replace YOUR_API_KEYuvx brave-search-python-client web"hello world"# search for hello world

All advanced search options of Brave Search are supportedby the clientand in the CLI:

# Find all German content about AI added in the last 24 hoursuvx brave-search-python-client web --country=DE --search-lang=de --units=metric --freshness=pd ai

The CLI provides extensive help:

uvx brave-search-python-client --help# all CLI commandsuvx brave-search-python-client web --help# all options for web searchuvx brave-search-python-client images --help# all options image searchuvx brave-search-python-client videos --help# all options video searchuvx brave-search-python-client news --help# all options news search

CLI

Operational Excellence

This project is designed with operational excellence in mind, using modernPython tooling and practices. It includes:

  1. Various examples demonstrating usage: a.Simple Python scriptb.Streamlit web applicationdeployed onStreamlit Community Cloud c.JupyterandMarimonotebook
  2. Complete reference documentationon Read the Docs
  3. Transparent test coverageincluding unit and E2E tests (reported on Codecov)
  4. Matrix tested withmultiple python versionsto ensure compatibility (powered byNox)
  5. Compliant with modern linting and formatting standards (powered byRuff)
  6. Up-to-date dependencies (monitored byRenovate andDependabot)
  7. A-grade code qualityin security, maintainability, and reliability with low technical debt andcodesmell (verified by SonarQube)
  8. Additional code security checks usingCodeQL
  9. Security Policy
  10. License compliant with the Open Source Initiative (OSI)
  11. 1-liner for installation and execution of command line interface (CLI) viauv(x) orDocker
  12. Setup for developing inside adevcontainerincluded (supports VSCode and GitHub Codespaces)

Usage Examples

Streamlit App

Watch it

Try it out! -Show the code

Minimal Python Script:

"""Example script demonstrating the usage of the Brave Search Python Client.For web, image, video and news search."""importasyncioimportosfromdotenvimportload_dotenvfromrich.consoleimportConsolefrombrave_search_python_clientimport (BraveSearch,CountryCode,ImagesSearchRequest,LanguageCode,NewsSearchRequest,VideosSearchRequest,WebSearchRequest,)# Load .env file and get Brave Search API key from environmentload_dotenv()api_key=os.getenv("BRAVE_SEARCH_API_KEY")ifnotapi_key:msg="BRAVE_SEARCH_API_KEY not found in environment"raiseValueError(msg)asyncdefsearch()->None:"""Run various searches using the Brave Search Python Client (see https://brave-search-python-client.readthedocs.io/en/latest/lib_reference.html)."""# Initialize the Brave Search Python client, using the API key from the environmentbs=BraveSearch()# Perform a web searchresponse=awaitbs.web(WebSearchRequest(q="jupyter"))# Print results as JSON# Iterate over web hits and render links in markdownfor_resultinresponse.web.resultsifresponse.webelse []:pass# Advanced search with parametersresponse=awaitbs.web(WebSearchRequest(q="python programming",country=CountryCode.DE,search_lang=LanguageCode.DE,        ),    )for_resultinresponse.web.resultsifresponse.webelse []:pass# Search and render imagesresponse=awaitbs.images(ImagesSearchRequest(q="cute cats"))for_imageinresponse.resultsor []:pass# Search and render videosresponse=awaitbs.videos(VideosSearchRequest(q="singularity is close"))for_videoinresponse.resultsor []:pass# Search and render newsresponse=awaitbs.news(NewsSearchRequest(q="AI"))for_iteminresponse.resultsor []:pass# Run the async search function# Alternatively use await search() from an async functionasyncio.run(search())

Show script code -

Read the library reference documentationfor an explanation of available classes and methods.

Jupyter Notebook

Jupyter Notebook

Show notebook code

Command Line Interface (CLI)

Run withuvx

Add Brave Search API key to the environment

export BRAVE_SEARCH_API_KEY=YOUR_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

Read the CLI reference documentationfor an explanation of all commands and options.

Run with Docker

Note: Replace YOUR_BRAVE_SEARCH_API_KEY with your API key in the followingexamples.

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

Or use docker compose

File .env is passed through

docker compose updocker compose run brave-search-python-client --help

Further Reading

  • Inspect oursecurity policy with detailed documentation of checks, tools and principles.
  • Check out theCLI reference with detailed documentation of all CLI commands and options.
  • Check out thelibrary reference with detailed documentation of public classes and functions.
  • Check out theAPI reference with detailed documentation of all API operations and parameters.
  • Ourrelease notes provide a complete log of recent improvements and changes.
  • In case you want to help us improve 🦁 Brave Search Python Client: Thecontribution guidelines explain how to setup your development environment and create pull requests.
  • We gratefully acknowledge theopen source projects that this project builds upon. Thank you to all these wonderful contributors!

Star History

Star History Chart

Packages

 
 
 

Languages


[8]ページ先頭

©2009-2025 Movatter.jp