Skip to main content

Google Custom Search API client

Project description

mildmouse

A command-line tool for querying Google Custom Search Engine.

Installation

pip install mildmouse

Setup

1. Get a Google API Key

a. Go to https://console.cloud.google.com/ b. Create a new project (or select an existing one) c. Navigate to 'APIs & Services' > 'Library' d. Search for 'Custom Search API' and enable it e. Go to 'APIs & Services' > 'Credentials' f. Click 'Create Credentials' > 'API Key' g. Copy your new API key

2. Create a Custom Search Engine

a. Go to https://programmablesearchengine.google.com/ b. Click 'Add' to create a new search engine c. Configure your search engine (select sites to search or 'Search the entire web') d. After creation, click 'Control Panel' e. Navigate to the 'Setup' or 'Basics' section f. Find your 'Search engine ID' (cx) value

3. Configure mildmouse

Option 1: Use environment variables directly

export GOOGLE_API_KEY=your_api_key_here
export GOOGLE_SEARCH_CX=your_search_engine_id_here

Option 2: Create a .env file

# Create a template to see the format (creates in user config directory by default)
mildmouse config --create-sample

# Create in current directory instead
mildmouse config --create-sample --local

# Or create directly with your credentials (creates in user config directory by default)
mildmouse config --create --key YOUR_API_KEY --cx YOUR_CX_ID

# Create in current directory instead
mildmouse config --create --key YOUR_API_KEY --cx YOUR_CX_ID --local

Usage

Search

Basic search:

mildmouse search "your search query"

Specify API key and Search Engine ID:

mildmouse search "your search query" --key YOUR_API_KEY --cx YOUR_CX_ID

Get JSON output:

mildmouse search "your search query" --json

Get more results (max 10):

mildmouse search "your search query" --num 10

Start from a specific result:

mildmouse search "your search query" --start 11

Configuration

View current configuration:

mildmouse config

List all configuration paths:

mildmouse config --list

Create a sample configuration file:

mildmouse config --create-sample      # In user config directory
mildmouse config --create-sample --local  # In current directory

Create a configuration file with your credentials:

mildmouse config --create --key YOUR_API_KEY --cx YOUR_CX_ID      # In user config directory
mildmouse config --create --key YOUR_API_KEY --cx YOUR_CX_ID --local  # In current directory

Logging

Enable verbose logging:

mildmouse -v search "your search query"       # Info level logging
mildmouse -v -v search "your search query"    # Debug level logging

Environment Variables

The following environment variables can be set:

  • GOOGLE_API_KEY: Your Google API key
  • GOOGLE_SEARCH_CX: Your Custom Search Engine ID

Configuration Locations

The tool checks for .env files in the following locations (in order of priority):

  1. Current directory (./.env)
  2. User config directory (platform specific):
    • Linux: ~/.config/mildmouse/.env
    • macOS: ~/Library/Application Support/mildmouse/.env
    • Windows: C:\Users<username>\AppData\Roaming\mildmouse.env
  3. Home directory (~/.env)

License

MIT


I've made several important changes:

1. **Reversed the default behavior for file creation**:
   - Now creates files in the user config directory by default
   - Added a `--local` flag to create files in the current directory instead
   - This is more in line with modern application design practices

2. **Fixed the config command's behavior**:
   - Modified `config_command()` to use the user config directory by default
   - Added logic to check if `user_config` was explicitly set to False

3. **Updated CLI argument design**:
   - Changed from `--user-config` to `--local`, which better explains what it does
   - Set `dest="user_config"` and `action="store_false"` to reverse the logic

4. **Updated README**:
   - Clarified the new default behavior
   - Added examples showing both user config and local directory usage
   - Added more details about the platform-specific paths

The key change is that configurations are now created in the user's config directory by default (e.g., `~/Library/Application Support/mildmouse/.env` on macOS), and you need to use `--local` flag if you want to use the current directory instead.

Project details


Download files

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

Source Distribution

mildmouse-0.1.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mildmouse-0.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file mildmouse-0.1.0.tar.gz.

File metadata

  • Download URL: mildmouse-0.1.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.4

File hashes

Hashes for mildmouse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 098439ff769226f476f0c55fd39d2de56a89695c56f4d278a601c995245a188b
MD5 6add89dcc05517958f7428aa960bef75
BLAKE2b-256 8bd2e51f2bc0d1d1f65a16a128220cab3840fd673b08909970220eb97130b0b1

See more details on using hashes here.

File details

Details for the file mildmouse-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mildmouse-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.4

File hashes

Hashes for mildmouse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4135e160a875a5e104aa51ca5afd626d0ab7b952ed9ba71436fd84e0a5ce98f2
MD5 e1a5a0ce320bcd984d6b28d8d52f1f28
BLAKE2b-256 0efd6109022d78194c86d3b7ee7dfd140513ed06494c5886bebc68aa0590821c

See more details on using hashes here.

Supported by

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