Server
Core ASGI server classes.
AsgiServer
ASGI Server - main entry point for genro-asgi applications.
- Classes:
- AsgiServer – central coordinator: loads config (YAML), mounts apps,
builds middleware chain, handles lifespan, routes via genro-routes Router.
Inherits BasicAuthMixin and RoutingClass. Run with AsgiServer(server_dir).run().
WebSocket connections are handled by WsxHandler (WSX protocol over WebSocket).
- class genro_asgi.server.server.AsgiServer(server_dir=None, host=None, port=None, reload=None, argv=None, parent=None)[source]
Bases:
BasicAuthMixin,RoutingClassBase ASGI server with routing via genro_routes.
- config
ServerConfig for configuration.
- router
genro_routes Router for dispatch.
- dispatcher
Dispatcher handling request routing.
- lifespan
ServerLifespan for startup/shutdown.
- server_application
ServerApplication with system endpoints.
- sys_apps
Dict for system apps (mounted at /_sys/).
- apps
Dict for user apps.
- logger
Server logger instance.
- request_registry
RequestRegistry for tracking requests.
- request
Current request (from ContextVar).
- response
Current response builder.
- __init__(server_dir=None, host=None, port=None, reload=None, argv=None, parent=None)[source]
Initialize AsgiServer.
Composes BasicAuthMixin (auth) and RoutingClass (routing). Loads config, builds middleware chain, mounts apps.
- app_loader
- apply_persisted_config()[source]
Apply plugin_config.json to the current router tree.
Called at boot after plugins are attached.
- Return type:
- config
- dispatcher
- get_plugin_config(router_path='', entry='')[source]
Read live plugin configuration for a router/entry.
Uses routing.configure(“?”) for introspection via genro-routes public API.
- lifespan
- logger
- parent
- property request: BaseRequest | None
Current request from registry.
- request_registry
- resource_loader
- router
- save_plugin_config()[source]
Persist current runtime plugin config to plugin_config.json.
Uses routing.configure(“?”) to snapshot the full tree via genro-routes public API.
- server_application
- session_store
- set_plugin_config(router_path='', plugin_name='', target='_all_', **config_values)[source]
Apply a plugin config change at runtime without persisting.
Delegates to routing.configure() via genro-routes public API.
- Parameters:
- Returns:
True on success, or “error” key on failure.
- Return type:
- storage
- wsx_handler
ServerConfig
Server configuration - handles all config loading and app instantiation.
- class genro_asgi.server.server_config.ServerConfig(server_dir=None, host=None, port=None, reload=None, argv=None)[source]
Bases:
objectHandles server configuration loading and app instantiation.
- __init__(server_dir=None, host=None, port=None, reload=None, argv=None)[source]
Build merged configuration from YAML file, env vars, and overrides.
- Parameters:
server_dir (
str|Path|None) – Directory containing config.yaml. Defaults to cwd.host (
str|None) – Override for server host (takes precedence over YAML).port (
int|None) – Override for server port (takes precedence over YAML).argv (
list[str] |None) – Command-line arguments for additional overrides.
- get_app_specs_raw()[source]
Return {name: (module_name, class_name, middleware_config, kwargs)} for all apps.
Returns raw config data without importing. Server uses AppLoader to import.
- get_sys_app_specs_raw()[source]
Return {name: (module_name, class_name, middleware_config, kwargs)} for system apps.
Same format as get_app_specs_raw but for sys_apps config section.
- property server: SmartOptions
Server options (host, port, reload, server_dir).