Agents

WebService

View as MarkdownOpen in Claude

WebService provides a standalone FastAPI-based HTTP server for serving static files alongside your SignalWire agents. It includes security features such as Basic authentication, CORS, path traversal prevention, file extension filtering, and configurable security headers.

Use WebService when your agent needs to serve audio files, web pages, or other static assets over HTTP/HTTPS.

1from signalwire import WebService
2
3web = WebService(
4 port=8002,
5 directories={"/audio": "./audio_files", "/docs": "./public"},
6 enable_directory_browsing=True
7)
8web.start()

Properties

app
FastAPI

The underlying FastAPI application instance. None if FastAPI is not installed.

port
intDefaults to 8002

The port the server listens on.

directories
dict[str, str]

Dictionary mapping URL route paths to local directory paths.

enable_directory_browsing
boolDefaults to False

Whether directory listing is enabled for mounted directories.

max_file_size
intDefaults to 104857600

Maximum file size in bytes that the server will serve (default: 100 MB).

enable_cors
boolDefaults to True

Whether CORS middleware is enabled.

allowed_extensions
Optional[list[str]]

If set, only files with these extensions are served (e.g., [".html", ".css"]). When None, all extensions except those in blocked_extensions are allowed.

blocked_extensions
Optional[list]

File extensions and names that are never served. Defaults to .env, .git, .gitignore, .key, .pem, .crt, .pyc, __pycache__, .DS_Store, .swp.

security
SecurityConfig

The SecurityConfig instance managing authentication and security headers.

The constructor also accepts basic_auth (Optional[tuple[str, str]]) and config_file (Optional[str]) parameters. These are not exposed as public instance attributes after initialization.

Methods