Skip to content

signalwire.web

signalwire.web

Copyright (c) 2025 SignalWire

This file is part of the SignalWire SDK.

Licensed under the MIT License. See LICENSE file in the project root for full license information.

SignalWire Agents Web Service Module

This module provides static file serving capabilities for the SignalWire Agents SDK.

__all__ = ['WebService'] module-attribute

WebService

Static file serving service with HTTP API

port = port instance-attribute

enable_directory_browsing = enable_directory_browsing instance-attribute

max_file_size = max_file_size instance-attribute

enable_cors = enable_cors instance-attribute

directories = directories instance-attribute

allowed_extensions = allowed_extensions instance-attribute

blocked_extensions = blocked_extensions or ['.env', '.git', '.gitignore', '.key', '.pem', '.crt', '.pyc', '__pycache__', '.DS_Store', '.swp'] instance-attribute

security = SecurityConfig(config_file=config_file, service_name='web') instance-attribute

app = None instance-attribute

__init__(port=8002, directories=None, basic_auth=None, config_file=None, enable_directory_browsing=False, allowed_extensions=None, blocked_extensions=None, max_file_size=100 * 1024 * 1024, enable_cors=True)

Initialize WebService

Parameters:

Name Type Description Default
port int

Port to bind to (default: 8002)

8002
directories dict[str, str] | None

Dict mapping URL paths to local directories

None
basic_auth tuple[str, str] | None

Optional tuple of (username, password)

None
config_file str | None

Optional configuration file path

None
enable_directory_browsing bool

Allow directory listing

False
allowed_extensions list[str] | None

List of allowed file extensions (e.g., ['.html', '.css'])

None
blocked_extensions list[str] | None

List of blocked extensions (e.g., ['.env', '.git'])

None
max_file_size int

Maximum file size in bytes to serve

100 * 1024 * 1024
enable_cors bool

Enable CORS support

True

add_directory(route, directory)

Add a new directory to serve

Parameters:

Name Type Description Default
route str

URL path to mount at (e.g., "/docs")

required
directory str

Local directory path to serve

required

remove_directory(route)

Remove a directory from being served

Parameters:

Name Type Description Default
route str

URL path to remove

required

start(host='0.0.0.0', port=None, ssl_cert=None, ssl_key=None)

Start the service with optional HTTPS support

Parameters:

Name Type Description Default
host str

Host to bind to (default: "0.0.0.0")

'0.0.0.0'
port int | None

Port to bind to (default: self.port)

None
ssl_cert str | None

Path to SSL certificate file (overrides environment)

None
ssl_key str | None

Path to SSL key file (overrides environment)

None

stop()

Stop the service (placeholder for cleanup)

web_service

Copyright (c) 2025 SignalWire

This file is part of the SignalWire SDK.

Licensed under the MIT License. See LICENSE file in the project root for full license information.

logger = get_logger('web_service') module-attribute

WebService

Static file serving service with HTTP API

port = port instance-attribute
enable_directory_browsing = enable_directory_browsing instance-attribute
max_file_size = max_file_size instance-attribute
enable_cors = enable_cors instance-attribute
directories = directories instance-attribute
allowed_extensions = allowed_extensions instance-attribute
blocked_extensions = blocked_extensions or ['.env', '.git', '.gitignore', '.key', '.pem', '.crt', '.pyc', '__pycache__', '.DS_Store', '.swp'] instance-attribute
security = SecurityConfig(config_file=config_file, service_name='web') instance-attribute
app = None instance-attribute
__init__(port=8002, directories=None, basic_auth=None, config_file=None, enable_directory_browsing=False, allowed_extensions=None, blocked_extensions=None, max_file_size=100 * 1024 * 1024, enable_cors=True)

Initialize WebService

Parameters:

Name Type Description Default
port int

Port to bind to (default: 8002)

8002
directories dict[str, str] | None

Dict mapping URL paths to local directories

None
basic_auth tuple[str, str] | None

Optional tuple of (username, password)

None
config_file str | None

Optional configuration file path

None
enable_directory_browsing bool

Allow directory listing

False
allowed_extensions list[str] | None

List of allowed file extensions (e.g., ['.html', '.css'])

None
blocked_extensions list[str] | None

List of blocked extensions (e.g., ['.env', '.git'])

None
max_file_size int

Maximum file size in bytes to serve

100 * 1024 * 1024
enable_cors bool

Enable CORS support

True
add_directory(route, directory)

Add a new directory to serve

Parameters:

Name Type Description Default
route str

URL path to mount at (e.g., "/docs")

required
directory str

Local directory path to serve

required
remove_directory(route)

Remove a directory from being served

Parameters:

Name Type Description Default
route str

URL path to remove

required
start(host='0.0.0.0', port=None, ssl_cert=None, ssl_key=None)

Start the service with optional HTTPS support

Parameters:

Name Type Description Default
host str

Host to bind to (default: "0.0.0.0")

'0.0.0.0'
port int | None

Port to bind to (default: self.port)

None
ssl_cert str | None

Path to SSL certificate file (overrides environment)

None
ssl_key str | None

Path to SSL key file (overrides environment)

None
stop()

Stop the service (placeholder for cleanup)