settings
onion_peeler.settings
¶
ConfigLoader(config_dir=None, strict=True)
¶
Loads configuration from TOML files and validates with Pydantic.
Features: - Merges base.toml with site-specific configs - Environment variable overrides - Automatic validation - Helpful error messages
Initialize loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Optional[str]
|
Path to config directory (default: project_root/config) |
None
|
strict
|
bool
|
If True, fail on validation errors |
True
|
Source code in src/onion_peeler/settings/loader.py
find_site_for_url(url)
¶
Find site ID by matching URL against domains.
Source code in src/onion_peeler/settings/loader.py
list_sites()
¶
List all available site IDs.
Source code in src/onion_peeler/settings/loader.py
load_all_sites()
¶
Load all site configurations.
Source code in src/onion_peeler/settings/loader.py
load_global_config()
¶
Load global configuration.
Loads from: 1. base.toml [scrapy] section 2. Environment variables (ONION_PEELER__*)
Returns:
| Type | Description |
|---|---|
GlobalConfig
|
Validated GlobalConfig instance |
Source code in src/onion_peeler/settings/loader.py
load_site_config(site_id=None)
¶
Load site-specific configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
site_id
|
Optional[str]
|
Site identifier (filename without .toml) If None, uses ONION_PEELER_SITE env var |
None
|
Returns:
| Type | Description |
|---|---|
SiteConfig
|
Validated SiteConfig instance |
Source code in src/onion_peeler/settings/loader.py
GlobalConfig
¶
Bases: BaseModel
Global configuration for the scraper, including proxy settings and other global options.
Can be loaded from
- A toml file (e.g. config.toml)
- Site-specific config files (e.g. site_config.yaml) that override global defaults for specific sites
- Environment variables for sensitive data (e.g. TOR_CONTROL_PASSWORD)
to_scrapy_dict()
¶
Convert to Scrapy settings dictionary.
Only includes UPPERCASE fields (Scrapy convention).
Source code in src/onion_peeler/settings/models.py
SiteConfig
¶
Bases: BaseModel
get_item_selectors(item_type)
¶
Return selectors for an item type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_type
|
str
|
Item type key from config, e.g. "thread" |
required |
Source code in src/onion_peeler/settings/models.py
get_selector(item_type, field_name)
¶
Get the selector for a specific field.
Source code in src/onion_peeler/settings/models.py
get_loader()
¶
load_global_config()
¶
load_item_selectors(item_type, site_id=None)
¶
Load selectors for an item type from site config.
Source code in src/onion_peeler/settings/loader.py
load_selector(item_type, field_name, site_id=None)
¶
Load a single selector field for a site and item type.