🦁 Brave Search Python Client supporting Web, Image, News and Video search.
Project description
🦁 Brave Search Python Client
[!TIP] 📚 Online documentation - 📖 PDF Manual
[!NOTE] 🧠 This project was scaffolded using the template oe-python-template with copier.
Brave Search Python Client supporting Web, Image, News and Video search.
Use Cases:
- Fast and easy to use project setup
- Consistent update of already scaffolded projects to benefit from new and improved features.
- Dummy CLI application and service demonstrating example usage of the generated directory structure and build pipeline
Scaffolding
Step 1: Install uv package manager and copier
if [[ "$OSTYPE" == "darwin"* ]]; then # Install dependencies for macOS X
if ! command -v brew &> /dev/null; then ## Install Homebrew if not present
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then # Install dependencies for Linux
sudo apt-get update -y && sudo apt-get install curl -y # Install curl
fi
if ! command -v uvx &> /dev/null; then # Install uv package manager if not present
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
fi
uv tool install copier # Install copier as global tool
Step 2: Now create an empty repository on GitHubm, clone to your local machine, and change into it's directory.
Step 3: Scaffold the project
copier copy gh:helmut-hoffer-von-ankershoffen/oe-python-template .
Step 4: Setup the local environment
uv run nox -s setup_dev
Step 5: Perform initial commit and push
git add .
git commit -m "feat: Initial commit"
git push
Visit your GitHub repository and check the Actions tab. The CI workflow should fail at the SonarQube step, as this external service is not yet configured for our new repository.
Step 6: Follow the instructions to wire up external services such as Cloudcov, SonarQube Cloud, Read The Docs, Docker.io, GHCR.io and Streamlit Community Cloud.
Step 7: Release the first versions
./bump
Notes:
- You can remove this section post having successfully scafolded your project.
- The following sections refer to the dummy application and service provided by this template. Use them as inspiration and adapt them to your own project.
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 follow these instructions. If you still prefer pip over the modern and fast package manager uv, you can install the library like this:
pip install brave-search-python-client # add dependency to your project
Executing the command line interface (CLI) in an isolated Python environment is just as easy:
uvx brave-search-python-client hello-world # prints "Hello, world! [..]"
uvx brave-search-python-client serve # serves webservice API
uvx brave-search-python-client serve --port=4711 # serves webservice API on port 4711
Notes:
- The API is versioned, mounted at
/api/v1
resp./api/v2
- While serving the webservice API go to
http://127.0.0.1:8000/api/v1/hello-world
to see the respons of the
hello-world
operation. - Interactive documentation is provided at http://127.0.0.1:8000/api/docs
The CLI provides extensive help:
uvx brave-search-python-client --help # all CLI commands
uvx brave-search-python-client hello-world --help # help for specific command
uvx brave-search-python-client echo --help
uvx brave-search-python-client openapi --help
uvx brave-search-python-client serve --help
Operational Excellence
This project is designed with operational excellence in mind, using modern Python tooling and practices. It includes:
- Various examples demonstrating usage:
- Simple Python script
- Streamlit web application deployed on Streamlit Community Cloud
- Jupyter and Marimo notebook
- Complete reference documentation on Read the Docs
- Transparent test coverage including unit and E2E tests (reported on Codecov)
- Matrix tested with multiple python versions to ensure compatibility (powered by Nox)
- Compliant with modern linting and formatting standards (powered by Ruff)
- Up-to-date dependencies (monitored by Renovate and GitHub Dependabot)
- A-grade code quality in security, maintainability, and reliability with low technical debt and codesmell (verified by SonarQube)
- Additional code security checks using GitHub CodeQL
- Security Policy
- License compliant with the Open Source Initiative (OSI)
- 1-liner for installation and execution of command line interface (CLI) via uv(x) or Docker
- Setup for developing inside a devcontainer included (supports VSCode and GitHub Codespaces)
Usage Examples
The following examples run from source. Clone this repository first using
git clone git@github.com:helmut-hoffer-von-ankershoffen/brave-search-python-client.git
.
Minimal Python Script:
"""Example script demonstrating the usage of the service provided by Brave Search Python Client."""
from dotenv import load_dotenv
from rich.console import Console
from brave_search_python_client import Service
console = Console()
load_dotenv()
message = Service.get_hello_world()
console.print(f"[blue]{message}[/blue]")
Show script code - Read the reference documentation
Streamlit App
Serve the functionality provided by Brave Search Python Client in the web by easily integrating the service into a Streamlit application.
... or serve the app locally
uv sync --all-extras # Install streamlit dependency part of the examples extra, see pyproject.toml
uv run streamlit run examples/streamlit.py # Serve on localhost:8501, opens browser
Notebooks
Jupyter
... or run within VSCode
uv sync --all-extras # Install dependencies required for examples such as Juypyter kernel, see pyproject.toml
Install the Jupyter extension for VSCode
Click on examples/notebook.ipynb
in VSCode and run it.
Marimo
Execute the notebook as a WASM based web app
uv sync --all-extras # Install ipykernel dependency part of the examples extra, see pyproject.toml
uv run marimo run examples/notebook.py --watch # Serve on localhost:2718, opens browser
or edit interactively in your browser
uv sync --all-extras # Install ipykernel dependency part of the examples extra, see pyproject.toml
uv run marimo edit examples/notebook.py --watch # Edit on localhost:2718, opens browser
... or edit interactively within VSCode
Install the Marimo extension for VSCode
Click on examples/notebook.py
in VSCode and click on the caret next to the Run
icon above the code (looks like a pencil) > "Start in marimo editor" (edit).
Command Line Interface (CLI)
Run with uvx
Show available commands:
uvx brave-search-python-client --help
Execute commands:
uvx brave-search-python-client hello-world
uvx brave-search-python-client echo --help
uvx brave-search-python-client echo "Lorem"
uvx brave-search-python-client echo "Lorem" --json
uvx brave-search-python-client openapi
uvx brave-search-python-client openapi --output-format=json
uvx brave-search-python-client serve
Environment
The service loads environment variables including support for .env files.
cp .env.example .env # copy example file
echo "THE_VAR=MY_VALUE" > .env # overwrite with your values
Now run the usage examples again.
Run with Docker
You can as well run the CLI within Docker.
docker run helmuthva/brave-search-python-client --help
docker run helmuthva/brave-search-python-client hello-world
docker run helmuthva/brave-search-python-client echo --help
docker run helmuthva/brave-search-python-client echo "Lorem"
docker run helmuthva/brave-search-python-client echo "Lorem" --json
docker run helmuthva/brave-search-python-client openapi
docker run helmuthva/brave-search-python-client openapi --output-format=json
docker run helmuthva/brave-search-python-client serve
Execute command:
docker run --env THE_VAR=MY_VALUE helmuthva/brave-search-python-client echo "Lorem Ipsum"
Or use docker compose
The .env is passed through from the host to the Docker container.
docker compose run brave-search-python-client --help
docker compose run brave-search-python-client hello-world
docker compose run brave-search-python-client echo --help
docker compose run brave-search-python-client echo "Lorem"
docker compose run brave-search-python-client echo "Lorem" --json
docker compose run brave-search-python-client openapi
docker compose run brave-search-python-client openapi --output-format=json
docker compose up
curl http://127.0.0.1:8000/api/v1/hello-world
curl http://127.0.0.1:8000/api/v1/docs
curl http://127.0.0.1:8000/api/v2/hello-world
curl http://127.0.0.1:8000/api/v2/docs
Extra: Lorem Ipsum
Dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam.
Further Reading
- Check out the reference with detailed documentation of public classes and functions.
- Our release notes provide a complete log of recent improvements and changes.
- In case you want to help us improve 🦁 Brave Search Python Client: The contribution guidelines explain how to setup your development environment and create pull requests.
Star History
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file brave_search_python_client-0.4.2.tar.gz
.
File metadata
- Download URL: brave_search_python_client-0.4.2.tar.gz
- Upload date:
- Size: 37.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
c9864a9f34b4d9c15dbf1de10aa9cc0818271d83e1ce37d41e191256199cabd3
|
|
MD5 |
e2424d53c8a0e520e6dbd4e3a199f150
|
|
BLAKE2b-256 |
ff0d4a16cd910e68af3084a987d77606677f4f9f4b97d181a3c7eca330497aea
|
File details
Details for the file brave_search_python_client-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: brave_search_python_client-0.4.2-py3-none-any.whl
- Upload date:
- Size: 68.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
05de39ef03234b663fb8b08af5d230b649e93261c79a3e27b6539b0d78901e5d
|
|
MD5 |
9a4a7d7a99622b3536a3ab778990001c
|
|
BLAKE2b-256 |
6f327247fc61ae7c5e379f00a6fa265d9c120514bdeb3ea219f3b2cc68f7fa5a
|