Skip to main content

Enumerate, Search, Parse, and Iterate - A tool for structured data extraction from search results

Project description

espai

Enumerate, Search, Parse, and Iterate - A tool for structured data extraction from search results

Overview

Espai is a command-line tool that combines search engines, web scraping, and LLMs to extract structured data from the web. It can find entities (like companies, schools, or government agencies) and extract specific attributes about them (like websites, phone numbers, or addresses).

Architecture

Espai is built with a modular architecture that combines several components:

1. Query Understanding

  • Uses Google's Gemini LLM to parse natural language queries into:
    • Entity type (what we're looking for)
    • Attributes (what information to extract)
    • Search space (geographic or domain constraints)
  • Example: "find tech companies in california with their websites and phone numbers"
    • Entity: company
    • Attributes: website, phone
    • Search space: california

2. Search Providers

  • Pluggable search provider interface supporting multiple backends:
    • Google Custom Search API
    • Exa.ai API (with neural search)
  • Each provider returns normalized SearchResult objects containing:
    • Title
    • Snippet
    • URL
    • Domain
    • Published date

3. Entity Extraction

  • Two-pass approach:
    1. First pass: Find entities matching the query
      • Uses search results to identify entity names
      • Deduplicates entities based on normalized names
    2. Second pass: Extract requested attributes
      • Uses targeted searches for each attribute
      • Scrapes web pages when needed
      • Updates existing entities with new information

4. Web Scraping

  • Asynchronous web scraping with httpx
  • Robust text extraction:
    • Handles multiple character encodings
    • Removes irrelevant HTML elements
    • Cleans and normalizes text
    • Truncates long content for LLM processing

5. LLM Processing

  • Uses Gemini for multiple tasks:
    • Query parsing
    • Entity name extraction
    • Attribute extraction
    • Search space enumeration
  • Custom prompts ensure consistent and clean output

6. Data Management

  • Stores results in EntityResult objects with fields for:
    • Name
    • Search space
    • Website
    • Phone
    • Email
    • Address components
  • Supports multiple output formats:
    • CSV
    • JSON
    • Parquet

How It Works

  1. Query Processing:

    • User inputs a natural language query
    • Gemini parses it into structured components
    • Search space is enumerated if needed (e.g., "all New England states")
  2. Entity Discovery:

    • Primary search provider finds potential entities
    • Results are processed to extract entity names
    • Entities are deduplicated and normalized
  3. Attribute Enrichment:

    • For each entity, missing attributes are identified
    • Targeted searches find attribute information
    • Web pages are scraped when needed
    • LLM extracts structured data from text
  4. Result Management:

    • Results are continuously updated and deduplicated
    • Progress is shown in real-time
    • Results can be saved even if interrupted
    • Output is formatted according to user preference

Features

  • Natural language query interface
  • Multiple search provider support (Google and Exa.ai)
  • Asynchronous operation for better performance
  • Robust error handling and recovery
  • Clean shutdown with result saving
  • Multiple output formats (CSV, JSON, Parquet)
  • Progress tracking with rich console output
  • Verbose mode for debugging

Installation

pip install espai

Or with Poetry:

poetry add espai

Configuration

You'll need to set up the following environment variables:

# Required for Google Custom Search
GOOGLE_API_KEY=your_google_api_key
GOOGLE_CSE_ID=your_custom_search_engine_id

# Required for Exa.ai search
EXA_API_KEY=your_exa_api_key

# Required for Gemini AI
GEMINI_API_KEY=your_gemini_api_key

Usage

Basic usage:

espai "tech companies in San Francisco with their websites"

With options:

espai "department of education websites for all US states" \
  --max-results 20 \
  --output-format json \
  --output-file results.json \
  --verbose

Available options:

  • --max-results, -n: Maximum results per search (default: 10)
  • --output-format, -f: Output format: csv, json, or parquet (default: csv)
  • --output-file, -o: Output file (default: results.[format])
  • --verbose, -v: Show verbose output
  • --provider, -p: Search provider: google or exa (default: google)
  • --temperature, -t: Temperature for LLM generation (default: 0.7)

Example Queries

Find companies:

espai "tech startups in Boston with websites and phone numbers"

Find organizations:

espai "environmental nonprofits in California with email addresses"

Find people:

espai "state governors with their official websites"

Find locations:

espai "national parks in Utah with visitor center addresses"

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

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

espai-0.2.4.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

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

espai-0.2.4-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file espai-0.2.4.tar.gz.

File metadata

  • Download URL: espai-0.2.4.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.1 Darwin/23.4.0

File hashes

Hashes for espai-0.2.4.tar.gz
Algorithm Hash digest
SHA256 07f8909072d4c365042cbe7ecdc0e9f45fad003d51984c327e7153be53f4e774
MD5 970592cfc5d1130e32b8c8e122e4d9f1
BLAKE2b-256 9a2b1f35cac453a7bf702219912b25071ac577dbd814edfd63dd927c9c11c0e4

See more details on using hashes here.

File details

Details for the file espai-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: espai-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.1 Darwin/23.4.0

File hashes

Hashes for espai-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9744cdc95e1cd6260e71f9f15de35043548361f3b7b419063fa7466eb8d7e3da
MD5 61c9910e9ae0f1a84485b33ff0532b8e
BLAKE2b-256 ad0e5917d524a9eaf485c3ad76d5f73db67f7d15371d2492de23a63b199e832c

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