Skip to main content

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

Project description

🦁 Brave Search Python Client

License PyPI - Python Version CI Read the Docs Quality Gate Security Maintainability Technical Debt Code Smells CodeQL Dependabot Renovate enabled Coverage Ruff MyPy GitHub - Version GitHub - Commits PyPI - Version PyPI - Status Docker - Version Docker - Size Copier Open in Dev Containers Open in GitHub Codespaces

[!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.

Scaffolding

This Copier template enables you to quickly generate (scaffold) a Python package with fully functioning build and test automation:

  1. Projects generated from this template can be easily updated to benefit from improvements and new features of the template.
  2. During project generation, you can flexibly configure naming of the Python distribution, import package, main author, GitHub repository, organization, and many other aspects to match your specific requirements (see copier.yml for all available options).

Development Infrastructure

Projects generated with this template come with a comprehensive development toolchain and quality assurance framework that supports the entire software development lifecycle - from coding and testing to documentation, release management, and compliance auditing. This infrastructure automates routine tasks, enforces code quality standards, and streamlines the path to production:

  1. Linting with Ruff
  2. Static type checking with mypy
  3. Complete set of pre-commit hooks including detect-secrets and pygrep
  4. Unit and E2E testing with pytest including parallel test execution
  5. Matrix testing in multiple environments with nox
  6. Test coverage reported with Codecov and published as release artifact
  7. CI/CD pipeline automated with GitHub Actions
  8. CI/CD pipeline can be run locally with act
  9. Code quality and security checks with SonarQube and GitHub CodeQL
  10. Dependency monitoring with pip-audit, Renovate, and GitHub Dependabot
  11. Licenses of dependencies extracted with pip-licenses and published as release artifacts in CSV and JSON format for compliance checks
  12. Software Bill of Materials (SBOM) generated with cyclonedx-python and published as release artifact
  13. Version and release management with bump-my-version
  14. Changelog and release notes generated with git-cliff
  15. Documentation generated with Sphinx including reference documentation and PDF export
  16. Documentation published to Read The Docs
  17. Interactive OpenAPI specification with Swagger
  18. Python package published to PyPI
  19. Docker images published to Docker.io and GitHub Container Registry with artifact attestations
  20. One-click development environments with Dev Containers and GitHub Codespaces
  21. Settings for use with VSCode
  22. Settings and custom instructions for use with GitHub Copilot

Application Features

Beyond development tooling, projects generated with this template include the code, documentation, and configuration of a fully functioning demo application and service. This reference implementation serves as a starting point for your own business logic with modern patterns and practices already in place:

  1. Service architecture suitable for use as shared library
  2. Validation with pydantic
  3. Command-line interface (CLI) with Typer
  4. Versioned Web API with FastAPI
  5. Interactive Jupyter notebook and reactive Marimo notebook
  6. Simple Web UI with Streamlit
  7. Configuration to run the CLI and API in a Docker container including setup for Docker Compose
  8. Documentation including badges, setup instructions, contribution guide and security policy

Explore here for what's generated out of the box.

Generate a new project

To generate, build and release a fully functioning project in a few minutes, follow these 5 steps:

Step 1: Execute the following command to install or update tooling.

# Install Homebrew, uv package manager, copier and further dev tools
curl -LsSf https://raw.githubusercontent.com/helmut-hoffer-von-ankershoffen/oe-python-template/HEAD/install.sh | sh

Step 2: Create a repository on GitHub, clone to your local machine, and change into it's directory.

Step 3: Execute the following command to generate a new project based on this template.

# Ensure to stand in your freshly created git repository before executing this command
copier copy --trust gh:helmut-hoffer-von-ankershoffen/oe-python-template .

Step 4: Execute the following commands to push your initial commit to GitHub.

git add .
git commit -m "chore: Initial commit"
git push

Check the Actions tab of your GitHub repository: The CI/CD workflow of your project is already running!

The workflow will fail at the SonarQube step, as this external service is not yet configured for our new repository. We will configure SonarQube and other services in the next step!

Notes:

  1. Check out this manual on how to set up signed commits

Step 5: Follow the instructions to wire up external services such as CloudCov, SonarQube Cloud, Read The Docs, Docker.io, and Streamlit Community Cloud.

Step 6: Release the first version of your project

make bump

Notes:

  1. You can remove the above sections - from "Scaffolding" to this notes - post having successfully generated your project.
  2. The following sections refer to the dummy application and service generated into the tests and src folder by this template. Use the documentation and code as inspiration, adapt to your business logic, or remove and start documenting and coding from scratch.

Overview

Adding Brave Search Python Client to your project as a dependency is easy. See below for usage examples.

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 web API
uvx brave-search-python-client serve --port=4711 # serves web API on port 4711

Notes:

  1. The API is versioned, mounted at /api/v1 resp. /api/v2
  2. While serving the web API go to http://127.0.0.1:8000/api/v1/hello-world to see the respons of the hello-world operation.
  3. 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:

  1. Various examples demonstrating usage: a. Simple Python script b. Streamlit web application deployed on Streamlit Community Cloud c. Jupyter and Marimo notebook
  2. Complete reference documentation on Read the Docs
  3. Transparent test coverage including unit and E2E tests (reported on Codecov)
  4. Matrix tested with multiple python versions to ensure compatibility (powered by Nox)
  5. Compliant with modern linting and formatting standards (powered by Ruff)
  6. Up-to-date dependencies (monitored by Renovate and Dependabot)
  7. A-grade code quality in security, maintainability, and reliability with low technical debt and codesmell (verified by SonarQube)
  8. Additional code security checks using CodeQL
  9. Security Policy
  10. License compliant with the Open Source Initiative (OSI)
  11. 1-liner for installation and execution of command line interface (CLI) via uv(x) or Docker
  12. Setup for developing inside a devcontainer included (supports VSCode and GitHub Codespaces)

Usage Examples

The following examples run from source - clone this repository 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.

Try it out! - Show the code

... 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

Show the Jupyter code

... 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

Show the marimo code

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
echo "Running Brave Search Python Client's API container as a daemon ..."
docker compose up -d
echo "Waiting for the API server to start ..."
sleep 5
echo "Checking health of v1 API ..."
curl http://127.0.0.1:8000/api/v1/healthz
echo ""
echo "Saying hello world with v1 API ..."
curl http://127.0.0.1:8000/api/v1/hello-world
echo ""
echo "Swagger docs of v1 API ..."
curl http://127.0.0.1:8000/api/v1/docs
echo ""
echo "Checking health of v2 API ..."
curl http://127.0.0.1:8000/api/v2/healthz
echo ""
echo "Saying hello world with v1 API ..."
curl http://127.0.0.1:8000/api/v2/hello-world
echo ""
echo "Swagger docs of v2 API ..."
curl http://127.0.0.1:8000/api/v2/docs
echo ""
echo "Shutting down the API container ..."
docker compose down

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

Star History Chart

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

brave_search_python_client-0.4.9.tar.gz (71.9 kB view details)

Uploaded Source

Built Distribution

brave_search_python_client-0.4.9-py3-none-any.whl (70.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for brave_search_python_client-0.4.9.tar.gz
Algorithm Hash digest
SHA256 6e31439eb7fce618eb504c5535cbafd21c057b3c14271ce597653de3e9d4ad61
MD5 d9e69c2fedc7bf4e5c49a2e7736f94da
BLAKE2b-256 4a50b7b34ee95f620584b3d6090c77080e24416493e0ea8fcbbfe0fa7e2d98ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for brave_search_python_client-0.4.9-py3-none-any.whl
Algorithm Hash digest
SHA256 c405473dd0856d1e0de56205138272cbb60a34eed68dbbd51bac3b9f172ffc9f
MD5 db8fb31867dbd8d7c11c2c10402b1676
BLAKE2b-256 3139b648f0a0d0a6c3683429961249ce7ceca19e045aadeb49b34df20e126140

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