Configuration API

The config module handles all configuration management for LayoutLens.

Config Class

class layoutlens.config.Config(config_path: str | None = None)[source]

Bases: object

Main configuration class for LayoutLens framework.

This class manages all configuration aspects including: - LLM provider settings - Viewport configurations - Screenshot options - Test execution parameters - Output and reporting settings

DEFAULT_VIEWPORTS = [ViewportConfig(name='mobile_portrait', width=375, height=667, device_scale_factor=2.0, is_mobile=True, has_touch=True, user_agent=None), ViewportConfig(name='tablet_portrait', width=768, height=1024, device_scale_factor=2.0, is_mobile=True, has_touch=True, user_agent=None), ViewportConfig(name='desktop', width=1440, height=900, device_scale_factor=1.0, is_mobile=False, has_touch=False, user_agent=None), ViewportConfig(name='desktop_large', width=1920, height=1080, device_scale_factor=1.0, is_mobile=False, has_touch=False, user_agent=None)]
__init__(config_path: str | None = None)[source]

Initialize configuration.

Parameters:

config_path (str, optional) – Path to YAML configuration file

load_from_file(config_path: str) None[source]

Load configuration from YAML file.

Parameters:

config_path (str) – Path to YAML configuration file

save_to_file(config_path: str) None[source]

Save current configuration to YAML file.

Parameters:

config_path (str) – Path where to save the configuration file

get_output_path(subdir: str) Path[source]

Get path for output subdirectory.

Parameters:

subdir (str) – Subdirectory name (screenshots, results, reports)

Returns:

Full path to the subdirectory

Return type:

Path

get_viewport_by_name(name: str) ViewportConfig | None[source]

Get viewport configuration by name.

Parameters:

name (str) – Viewport name

Returns:

Viewport configuration if found

Return type:

ViewportConfig, optional

add_viewport(viewport: ViewportConfig) None[source]

Add a new viewport configuration.

Parameters:

viewport (ViewportConfig) – Viewport configuration to add

add_custom_queries(category: str, queries: list[str]) None[source]

Add custom queries for a category.

Parameters:
  • category (str) – Category name for the queries

  • queries (list[str]) – List of query strings

validate() list[str][source]

Validate configuration and return any issues.

Returns:

List of validation errors (empty if valid)

Return type:

list[str]

Configuration Data Classes

class layoutlens.config.ViewportConfig(name: str, width: int, height: int, device_scale_factor: float = 1.0, is_mobile: bool = False, has_touch: bool = False, user_agent: str | None = None)[source]

Bases: object

Viewport configuration for testing.

name: str
width: int
height: int
device_scale_factor: float = 1.0
is_mobile: bool = False
has_touch: bool = False
user_agent: str | None = None
__init__(name: str, width: int, height: int, device_scale_factor: float = 1.0, is_mobile: bool = False, has_touch: bool = False, user_agent: str | None = None) None
class layoutlens.config.LLMConfig(provider: str = 'openai', model: str = 'gpt-4o-mini', api_key: str | None = None, api_key_env: str = 'OPENAI_API_KEY', max_retries: int = 3, timeout: int = 60, temperature: float = 0.1, custom_params: dict[str, ~typing.Any] = <factory>)[source]

Bases: object

Configuration for Language Model providers.

provider: str = 'openai'
model: str = 'gpt-4o-mini'
api_key: str | None = None
api_key_env: str = 'OPENAI_API_KEY'
max_retries: int = 3
timeout: int = 60
temperature: float = 0.1
custom_params: dict[str, Any]
__init__(provider: str = 'openai', model: str = 'gpt-4o-mini', api_key: str | None = None, api_key_env: str = 'OPENAI_API_KEY', max_retries: int = 3, timeout: int = 60, temperature: float = 0.1, custom_params: dict[str, ~typing.Any] = <factory>) None
class layoutlens.config.TestConfig(auto_generate_queries: bool = True, focus_areas: list[str] = <factory>, parallel_execution: bool = False, max_workers: int = 4, continue_on_error: bool = True, save_screenshots: bool = True, save_detailed_results: bool = True)[source]

Bases: object

Configuration for test execution.

auto_generate_queries: bool = True
focus_areas: list[str]
parallel_execution: bool = False
max_workers: int = 4
continue_on_error: bool = True
save_screenshots: bool = True
save_detailed_results: bool = True
__init__(auto_generate_queries: bool = True, focus_areas: list[str] = <factory>, parallel_execution: bool = False, max_workers: int = 4, continue_on_error: bool = True, save_screenshots: bool = True, save_detailed_results: bool = True) None
class layoutlens.config.OutputConfig(base_dir: str = 'layoutlens_output', screenshots_dir: str = 'screenshots', results_dir: str = 'results', reports_dir: str = 'reports', format: str = 'json', include_metadata: bool = True, compress_results: bool = False)[source]

Bases: object

Configuration for output and reporting.

base_dir: str = 'layoutlens_output'
screenshots_dir: str = 'screenshots'
results_dir: str = 'results'
reports_dir: str = 'reports'
format: str = 'json'
include_metadata: bool = True
compress_results: bool = False
__init__(base_dir: str = 'layoutlens_output', screenshots_dir: str = 'screenshots', results_dir: str = 'results', reports_dir: str = 'reports', format: str = 'json', include_metadata: bool = True, compress_results: bool = False) None

Utility Functions

layoutlens.config.create_default_config(config_path: str) Config[source]

Create a default configuration file.

Parameters:

config_path (str) – Path where to save the default configuration

Returns:

The created configuration instance

Return type:

Config