How megadose/onionsearch works
Project type and purpose
• This is a Python-based CLI utility (“OnionSearch”) that crawls multiple “.onion” search engines over Tor, aggregates results and writes them to a CSV (or other) file.
• It is an open-source tool (packaged via setup.py / PyPI), not a web app or microservice.
File structure
• Top level:
• setup.py — installer and entry point definition
• LICENSE, .gitignore, README.md
• onionsearch/ (the Python package)
• Inside onionsearch/:
• __init__.py — package marker and possibly version
• core.py — the only module; contains CLI parsing, engine definitions, scraping logic, multiprocessing orchestration and output routines
Extract architecture hints from the README
• Uses argparse (CLI), runs multiple scrapers in parallel (multiprocessing), talks to Tor proxy by default at 127.0.0.1:9050.
• Supports a list of search-engine backends (ahmia, darksearchio, …), each one implemented as a function or class in core.py.
• Aggregates link fields and writes CSV (with custom fields, delimiter, progressive write).
Main components
a. CLI Layer
• Argument Parser (argparse in core.py)
• Validation of options (engines list, output path, limits, proxies, mp_units)
b. Orchestration Layer
• Multiprocessing Manager – spawns worker processes (pool of size mp_units)
• Task Queue – engine scrape requests with search term + per-engine limit
c. Scraper Engines
• Individual engine modules/functions (ahmia, darksearchio, etc.)
• Factory/Dispatcher that chooses which engine function to invoke
d. Network/Proxy Layer
• Tor Proxy (127.0.0.1:9050)
• HTTP client (e.g., requests with SOCKS5 support)
e. Output Layer
• Result Aggregator – collects tuples of (engine, name, url, domain, …)
• File Writer – writes to CSV (batch or continuous), format/filename generator
f. Utilities
• Sanitization / CSV field escaping
• Progress bar display (optional, per-process)
Relationships and data flows
• User invokes “onionsearch” CLI → Argument Parser
• Parser produces a job spec → Multiprocessing Manager
• Manager enqueues scraping tasks → Worker Processes
• Each worker:
• Picks one engine
• Calls the corresponding scraper function
• Sends HTTP requests via Tor Proxy
• Parses HTML results into structured records
• Returns record list to Manager
• Manager aggregates all results → passes to File Writer
• File Writer writes final CSV (or progressively writes as tasks complete)
Architectural patterns & design principles
• Separation of concerns: clean split between CLI, orchestration, network, engine logic, and I/O
• Concurrency via multiprocessing pool
• Plug-in / factory pattern for adding new engines
• Single-responsibility for each component (parsing, scraping, writing)
Technologies, frameworks, libraries
• Python 3.x
• argparse (CLI)
• multiprocessing (parallelism)
• requests or httpx + PySocks (network over Tor)
• csv module (output)
• setuptools / entry_points (CLI installation via setup.py)