pywry.config¶
Configuration and settings classes for PyWry. Settings can be loaded from environment variables, TOML files, or passed directly.
Main Settings¶
pywry.config.PyWrySettings
¶
Bases: BaseSettings
Main settings aggregating all configuration sections.
Environment prefix: PYWRY__
Configuration sources (in order of precedence): 1. Built-in defaults 2. pyproject.toml [tool.pywry] section 3. ./pywry.toml (project-level) 4. ~/.config/pywry/config.toml (user-level, overrides project) 5. Environment variables (highest priority)
Attributes¶
model_config
class-attribute
instance-attribute
¶
csp
class-attribute
instance-attribute
¶
csp: SecuritySettings = Field(default_factory=SecuritySettings)
theme
class-attribute
instance-attribute
¶
theme: ThemeSettings = Field(default_factory=ThemeSettings)
timeout
class-attribute
instance-attribute
¶
timeout: TimeoutSettings = Field(default_factory=TimeoutSettings)
asset
class-attribute
instance-attribute
¶
asset: AssetSettings = Field(default_factory=AssetSettings)
window
class-attribute
instance-attribute
¶
window: WindowSettings = Field(default_factory=WindowSettings)
hot_reload
class-attribute
instance-attribute
¶
hot_reload: HotReloadSettings = Field(default_factory=HotReloadSettings)
server
class-attribute
instance-attribute
¶
server: ServerSettings = Field(default_factory=ServerSettings)
deploy
class-attribute
instance-attribute
¶
deploy: DeploySettings = Field(default_factory=DeploySettings)
oauth2
class-attribute
instance-attribute
¶
oauth2: OAuth2Settings | None = Field(default=None, description='OAuth2 authentication settings (None to disable)')
tauri_plugins
class-attribute
instance-attribute
¶
tauri_plugins: Annotated[list[str], NoDecode] = Field(default_factory=lambda: list(DEFAULT_TAURI_PLUGINS), description="Tauri plugins to initialise in the native subprocess. Each name must be one of the 19 plugins bundled in pytauri_wheel (e.g. 'dialog', 'fs', 'notification', 'http'). Set via PYWRY_TAURI_PLUGINS env var (comma-separated) or in pyproject.toml / pywry.toml under [tool.pywry].")
extra_capabilities
class-attribute
instance-attribute
¶
extra_capabilities: Annotated[list[str], NoDecode] = Field(default_factory=list, description="Additional Tauri capability permission strings to grant beyond the auto-generated '<plugin>:default' entries (e.g. 'shell:allow-execute', 'fs:allow-read-file'). Set via PYWRY_EXTRA_CAPABILITIES env var (comma-separated).")
Functions¶
_parse_tauri_plugins
classmethod
¶
Accept a comma-separated string (from env var) or a list.
_parse_extra_capabilities
classmethod
¶
Accept a comma-separated string (from env var) or a list.
Security Settings¶
Content Security Policy configuration.
pywry.config.SecuritySettings
¶
Bases: BaseSettings
Content Security Policy settings.
Environment prefix: PYWRY_CSP__ Example: PYWRY_CSP__CONNECT_SRC="'self' https://api.example.com"
Attributes¶
model_config
class-attribute
instance-attribute
¶
default_src
class-attribute
instance-attribute
¶
connect_src
class-attribute
instance-attribute
¶
script_src
class-attribute
instance-attribute
¶
img_src
class-attribute
instance-attribute
¶
Functions¶
permissive
classmethod
¶
permissive() -> SecuritySettings
Create permissive CSP settings for development mode.
strict
classmethod
¶
strict() -> SecuritySettings
Create strict CSP settings for production mode.
Removes unsafe-eval, restricts to self and specific CDNs.
localhost
classmethod
¶
localhost(ports: list[int] | None = None) -> SecuritySettings
Create localhost-only CSP settings.
| PARAMETER | DESCRIPTION |
|---|---|
ports
|
Specific ports to allow. If None, allows all localhost ports.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SecuritySettings
|
Configured security settings for localhost. |
Theme Settings¶
pywry.config.ThemeSettings
¶
Bases: BaseSettings
Theme and styling settings.
Controls the visual appearance of PyWry windows and widgets. The mode setting determines light/dark theme behavior.
Environment prefix: PYWRY_THEME__ Example: PYWRY_THEME__MODE=dark Example: PYWRY_THEME__CSS_FILE=/path/to/custom.css
Attributes¶
model_config
class-attribute
instance-attribute
¶
mode
class-attribute
instance-attribute
¶
mode: Literal['system', 'dark', 'light'] = Field(default='system', description="Theme mode: 'system' follows browser/OS preference, 'dark' or 'light' forces theme")
css_file
class-attribute
instance-attribute
¶
css_file: str | None = Field(default=None, description='Path to external CSS file for custom styling')
Window Settings¶
pywry.config.WindowSettings
¶
Bases: BaseSettings
Default window settings.
These settings correspond to WindowConfig fields and are used when creating native windows via the window manager.
Environment prefix: PYWRY_WINDOW__ Example: PYWRY_WINDOW__TITLE="My App"
Attributes¶
model_config
class-attribute
instance-attribute
¶
width
class-attribute
instance-attribute
¶
height
class-attribute
instance-attribute
¶
min_width
class-attribute
instance-attribute
¶
min_height
class-attribute
instance-attribute
¶
center
class-attribute
instance-attribute
¶
resizable
class-attribute
instance-attribute
¶
decorations
class-attribute
instance-attribute
¶
always_on_top
class-attribute
instance-attribute
¶
devtools
class-attribute
instance-attribute
¶
allow_network
class-attribute
instance-attribute
¶
on_window_close
class-attribute
instance-attribute
¶
on_window_close: Literal['hide', 'close'] = Field(default='hide', description="What happens when user clicks X: 'hide' keeps window alive, 'close' destroys it")
enable_plotly
class-attribute
instance-attribute
¶
enable_aggrid
class-attribute
instance-attribute
¶
plotly_theme
class-attribute
instance-attribute
¶
plotly_theme: Literal['plotly', 'plotly_white', 'plotly_dark', 'ggplot2', 'seaborn', 'simple_white'] = Field(default='plotly_dark', description='Default Plotly theme')
aggrid_theme
class-attribute
instance-attribute
¶
aggrid_theme: Literal['quartz', 'alpine', 'balham', 'material'] = Field(default='alpine', description='Default AG Grid theme')
Timeout Settings¶
pywry.config.TimeoutSettings
¶
Bases: BaseSettings
Timeout settings for IPC and subprocess.
Environment prefix: PYWRY_TIMEOUT__ Example: PYWRY_TIMEOUT__STARTUP=15.0
Log Settings¶
pywry.config.LogSettings
¶
Hot Reload Settings¶
pywry.config.HotReloadSettings
¶
Bases: BaseSettings
Hot reload settings.
Environment prefix: PYWRY_HOT_RELOAD__ Example: PYWRY_HOT_RELOAD__ENABLED=true
Attributes¶
model_config
class-attribute
instance-attribute
¶
debounce_ms
class-attribute
instance-attribute
¶
debounce_ms: int = Field(default=100, ge=10, description='Debounce time for file changes in milliseconds')
watch_directories
class-attribute
instance-attribute
¶
Functions¶
parse_comma_separated
classmethod
¶
Parse comma-separated strings from env vars.
Asset Settings¶
pywry.config.AssetSettings
¶
Bases: BaseSettings
Asset and library settings.
Environment prefix: PYWRY_ASSET__ Example: PYWRY_ASSET__PLOTLY_VERSION="3.4.0"
Deploy Settings¶
pywry.config.DeploySettings
¶
Bases: BaseSettings
Deploy mode settings for scalable production deployments.
Deploy mode is activated when both PYWRY_HEADLESS=1 and a state backend is configured. This enables horizontal scaling with Redis for state storage.
Environment prefix: PYWRY_DEPLOY__ Example: PYWRY_DEPLOY__STATE_BACKEND=redis Example: PYWRY_DEPLOY__REDIS_URL=redis://redis:6379/0
Attributes¶
model_config
class-attribute
instance-attribute
¶
state_backend
class-attribute
instance-attribute
¶
state_backend: Literal['memory', 'redis'] = Field(default='memory', description="State storage backend: 'memory' (single process) or 'redis' (distributed). Redis enables multi-worker horizontal scaling.")
redis_url
class-attribute
instance-attribute
¶
redis_url: str = Field(default='redis://localhost:6379/0', description="Redis connection URL. Supports standard redis:// and redis+sentinel:// schemes. Examples: 'redis://host:port/db', 'redis://:password@host:port/db'")
redis_prefix
class-attribute
instance-attribute
¶
redis_prefix: str = Field(default='pywry', description='Key prefix for all Redis keys (namespace isolation)')
redis_pool_size
class-attribute
instance-attribute
¶
redis_pool_size: int = Field(default=10, ge=1, le=100, description='Redis connection pool size per store')
widget_ttl
class-attribute
instance-attribute
¶
widget_ttl: int = Field(default=86400, ge=60, description='Widget data TTL in seconds (auto-deleted after expiry)')
connection_ttl
class-attribute
instance-attribute
¶
connection_ttl: int = Field(default=300, ge=30, description='Connection routing TTL in seconds (refresh on heartbeat)')
session_ttl
class-attribute
instance-attribute
¶
worker_id
class-attribute
instance-attribute
¶
worker_id: str | None = Field(default=None, description='Unique worker identifier for connection routing. Auto-generated if None (recommended for most deployments).')
auth_enabled
class-attribute
instance-attribute
¶
auth_enabled: bool = Field(default=False, description='Enable user authentication and session management')
auth_session_cookie
class-attribute
instance-attribute
¶
auth_session_cookie: str = Field(default='pywry_session', description='Name of the session cookie for authentication')
auth_header
class-attribute
instance-attribute
¶
auth_header: str = Field(default='Authorization', description='HTTP header for bearer token authentication')
default_roles
class-attribute
instance-attribute
¶
default_roles: Annotated[list[str], NoDecode] = Field(default_factory=lambda: ['viewer'], description='Default roles assigned to new users')
admin_users
class-attribute
instance-attribute
¶
admin_users: Annotated[list[str], NoDecode] = Field(default_factory=list, description='List of user IDs with admin privileges')
oauth2_login_path
class-attribute
instance-attribute
¶
oauth2_login_path: str = Field(default='/auth/login', description='Path for the OAuth2 login endpoint in deploy mode')
oauth2_callback_path
class-attribute
instance-attribute
¶
oauth2_callback_path: str = Field(default='/auth/callback', description='Path for the OAuth2 callback endpoint in deploy mode')
auth_public_paths
class-attribute
instance-attribute
¶
auth_public_paths: Annotated[list[str], NoDecode] = Field(default_factory=lambda: ['/auth/login', '/auth/callback', '/auth/status'], description='Paths that do not require authentication (pre-auth routes)')
auth_redirect_uri
class-attribute
instance-attribute
¶
auth_redirect_uri: str = Field(default='', description='Explicit OAuth2 redirect URI for deploy mode. When set, overrides request-derived Host header to prevent poisoning. Example: https://myapp.example.com/auth/callback')
force_https
class-attribute
instance-attribute
¶
force_https: bool = Field(default=False, description='Enforce HTTPS for redirect URIs and cookies in deploy mode. Should be True in production. When False, allows localhost HTTP for development.')
Functions¶
parse_comma_separated
classmethod
¶
Parse comma-separated strings from env vars.
parse_public_paths
classmethod
¶
Parse comma-separated strings from env vars.
Server Settings¶
pywry.config.ServerSettings
¶
Bases: BaseSettings
Inline server settings for notebook/web mode.
Exposes full uvicorn configuration for deployment.
Environment prefix: PYWRY_SERVER__ Example: PYWRY_SERVER__PORT=8080
Attributes¶
model_config
class-attribute
instance-attribute
¶
host
class-attribute
instance-attribute
¶
port
class-attribute
instance-attribute
¶
widget_prefix
class-attribute
instance-attribute
¶
widget_prefix: str = Field(default='/widget', description="URL prefix for widget routes (e.g., '/widget' -> /widget/{id})")
auto_start
class-attribute
instance-attribute
¶
force_notebook
class-attribute
instance-attribute
¶
force_notebook: bool = Field(default=False, description='Force notebook mode even in headless environments (for web deployments)')
workers
class-attribute
instance-attribute
¶
log_level
class-attribute
instance-attribute
¶
log_level: Literal['critical', 'error', 'warning', 'info', 'debug', 'trace'] = Field(default='info', description='Uvicorn log level')
access_log
class-attribute
instance-attribute
¶
reload
class-attribute
instance-attribute
¶
timeout_keep_alive
class-attribute
instance-attribute
¶
timeout_graceful_shutdown
class-attribute
instance-attribute
¶
timeout_graceful_shutdown: int | None = Field(default=None, description='Graceful shutdown timeout (None = wait forever)')
ssl_keyfile
class-attribute
instance-attribute
¶
ssl_certfile
class-attribute
instance-attribute
¶
ssl_keyfile_password
class-attribute
instance-attribute
¶
ssl_ca_certs
class-attribute
instance-attribute
¶
cors_origins
class-attribute
instance-attribute
¶
cors_origins: Annotated[list[str], NoDecode] = Field(default_factory=lambda: ['*'], description='Allowed CORS origins')
cors_allow_credentials
class-attribute
instance-attribute
¶
cors_allow_methods
class-attribute
instance-attribute
¶
cors_allow_methods: Annotated[list[str], NoDecode] = Field(default_factory=lambda: ['*'], description='Allowed CORS methods')
cors_allow_headers
class-attribute
instance-attribute
¶
cors_allow_headers: Annotated[list[str], NoDecode] = Field(default_factory=lambda: ['*'], description='Allowed CORS headers')
limit_concurrency
class-attribute
instance-attribute
¶
limit_max_requests
class-attribute
instance-attribute
¶
limit_max_requests: int | None = Field(default=None, description='Max requests before worker restart')
backlog
class-attribute
instance-attribute
¶
websocket_allowed_origins
class-attribute
instance-attribute
¶
websocket_allowed_origins: Annotated[list[str], NoDecode] = Field(default_factory=list, description="List of allowed origins for WebSocket connections. Empty list allows any origin (rely on token auth only). Examples: ['http://localhost:8080', 'https://app.example.com']")
websocket_require_token
class-attribute
instance-attribute
¶
websocket_require_token: bool = Field(default=True, description='Require per-widget authentication token for WebSocket connections. Each widget gets a unique short-lived token embedded in its HTML.')
internal_api_header
class-attribute
instance-attribute
¶
internal_api_header: str = Field(default='X-PyWry-Token', description='Header name for internal API authentication.')
internal_api_token
class-attribute
instance-attribute
¶
internal_api_token: str | None = Field(default=None, description='Token for internal API access. If None, auto-generated on server start. Required for /register_widget, /disconnect, /health endpoints.')
strict_widget_auth
class-attribute
instance-attribute
¶
strict_widget_auth: bool = Field(default=False, description='If True, /widget/{id} endpoint also requires internal API header (browser mode). If False, only checks widget exists (notebook mode, allows iframes).')
Functions¶
parse_comma_separated
classmethod
¶
Parse comma-separated strings from env vars.
MCP Settings¶
pywry.config.MCPSettings
¶
Bases: BaseSettings
MCP (Model Context Protocol) server settings.
Controls the MCP server for AI agent integration using FastMCP. The MCP server manages its own runtime (native windows or headless mode) and state.
Environment prefix: PYWRY_MCP__ Example: PYWRY_MCP__TRANSPORT=sse Example: PYWRY_MCP__PORT=8001 Example: PYWRY_MCP__HEADLESS=false
Attributes¶
model_config
class-attribute
instance-attribute
¶
name
class-attribute
instance-attribute
¶
version
class-attribute
instance-attribute
¶
version: str | None = Field(default=None, description='Server version string (auto-detected from package if None)')
instructions
class-attribute
instance-attribute
¶
instructions: str | None = Field(default=None, description='Server instructions shown to AI agents describing capabilities')
transport
class-attribute
instance-attribute
¶
transport: Literal['stdio', 'sse', 'streamable-http'] = Field(default='stdio', description="Transport type: 'stdio' for CLI/Claude Desktop, 'sse' or 'streamable-http' for HTTP")
host
class-attribute
instance-attribute
¶
host: str = Field(default='127.0.0.1', description='Host for HTTP transports (SSE/streamable-http)')
port
class-attribute
instance-attribute
¶
sse_path
class-attribute
instance-attribute
¶
message_path
class-attribute
instance-attribute
¶
message_path: str = Field(default='/messages/', description='Message endpoint path (for SSE transport)')
streamable_http_path
class-attribute
instance-attribute
¶
streamable_http_path: str = Field(default='/mcp', description='Streamable HTTP endpoint path (for streamable-http transport)')
json_response
class-attribute
instance-attribute
¶
json_response: bool = Field(default=False, description='Return JSON instead of SSE for HTTP transports')
stateless_http
class-attribute
instance-attribute
¶
stateless_http: bool = Field(default=False, description='Enable stateless HTTP mode (no session management)')
strict_input_validation
class-attribute
instance-attribute
¶
strict_input_validation: bool = Field(default=False, description='Enable stricter JSON schema validation for tool inputs')
mask_error_details
class-attribute
instance-attribute
¶
mask_error_details: bool = Field(default=False, description='Hide detailed error messages in production (show generic errors)')
debug
class-attribute
instance-attribute
¶
debug: bool = Field(default=False, description='Enable FastMCP debug mode (verbose logging, detailed errors)')
include_tags
class-attribute
instance-attribute
¶
include_tags: Annotated[list[str], NoDecode] = Field(default_factory=list, description='Only expose tools with these tags (empty = all tools)')
exclude_tags
class-attribute
instance-attribute
¶
exclude_tags: Annotated[list[str], NoDecode] = Field(default_factory=list, description='Exclude tools with these tags')
headless
class-attribute
instance-attribute
¶
headless: bool = Field(default=False, description='Run in headless mode (inline widgets via browser) or desktop mode (native windows). Can also be set via PYWRY_HEADLESS environment variable.')
widget_ttl
class-attribute
instance-attribute
¶
widget_ttl: int = Field(default=0, ge=0, description='Widget auto-cleanup TTL in seconds (0 = disabled, widgets persist until destroyed)')
max_widgets
class-attribute
instance-attribute
¶
event_buffer_size
class-attribute
instance-attribute
¶
event_buffer_size: int = Field(default=1000, ge=10, description='Maximum events buffered per widget before oldest are dropped')
default_width
class-attribute
instance-attribute
¶
default_height
class-attribute
instance-attribute
¶
default_height: int = Field(default=600, ge=150, description='Default window height for new widgets')
log_level
class-attribute
instance-attribute
¶
log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR'] = Field(default='INFO', description='MCP server log level')
log_tools
class-attribute
instance-attribute
¶
skills_auto_load
class-attribute
instance-attribute
¶
skills_auto_load: bool = Field(default=True, description='Auto-load skill documents when agents connect')
Functions¶
parse_comma_separated
classmethod
¶
Parse comma-separated strings from env vars.
Tauri Plugin Constants¶
pywry.config.TAURI_PLUGIN_REGISTRY
module-attribute
¶
TAURI_PLUGIN_REGISTRY: dict[str, tuple[str, str, str]] = {'autostart': ('PLUGIN_AUTOSTART', 'pytauri_plugins.autostart', 'init'), 'clipboard_manager': ('PLUGIN_CLIPBOARD_MANAGER', 'pytauri_plugins.clipboard_manager', 'init'), 'deep_link': ('PLUGIN_DEEP_LINK', 'pytauri_plugins.deep_link', 'init'), 'dialog': ('PLUGIN_DIALOG', 'pytauri_plugins.dialog', 'init'), 'fs': ('PLUGIN_FS', 'pytauri_plugins.fs', 'init'), 'global_shortcut': ('PLUGIN_GLOBAL_SHORTCUT', 'pytauri_plugins.global_shortcut', 'builder'), 'http': ('PLUGIN_HTTP', 'pytauri_plugins.http', 'init'), 'notification': ('PLUGIN_NOTIFICATION', 'pytauri_plugins.notification', 'init'), 'opener': ('PLUGIN_OPENER', 'pytauri_plugins.opener', 'init'), 'os': ('PLUGIN_OS', 'pytauri_plugins.os', 'init'), 'persisted_scope': ('PLUGIN_PERSISTED_SCOPE', 'pytauri_plugins.persisted_scope', 'init'), 'positioner': ('PLUGIN_POSITIONER', 'pytauri_plugins.positioner', 'init'), 'process': ('PLUGIN_PROCESS', 'pytauri_plugins.process', 'init'), 'shell': ('PLUGIN_SHELL', 'pytauri_plugins.shell', 'init'), 'single_instance': ('PLUGIN_SINGLE_INSTANCE', 'pytauri_plugins.single_instance', 'callback'), 'updater': ('PLUGIN_UPDATER', 'pytauri_plugins.updater', 'builder'), 'upload': ('PLUGIN_UPLOAD', 'pytauri_plugins.upload', 'init'), 'websocket': ('PLUGIN_WEBSOCKET', 'pytauri_plugins.websocket', 'init'), 'window_state': ('PLUGIN_WINDOW_STATE', 'pytauri_plugins.window_state', 'builder')}
pywry.config.AVAILABLE_TAURI_PLUGINS
module-attribute
¶
AVAILABLE_TAURI_PLUGINS: frozenset[str] = frozenset(TAURI_PLUGIN_REGISTRY)
pywry.config.DEFAULT_TAURI_PLUGINS
module-attribute
¶
Settings Functions¶
pywry.config.get_settings
cached
¶
get_settings() -> PyWrySettings
Get the global settings instance (cached).
Call clear_settings() to reload configuration.