Skip to content

Component: Networking

Canonical source: SmrtApps/PythonApp/python_core/net/README.md (mirrored below)


python_core.net

Overview & Responsibilities

  • Hosts the Python-side HTTP servers that connect SmrtHub WinUI surfaces, extensions, and automation agents to the Python Core runtime.
  • Provides two primary surfaces: bridge_server for WinUI↔Python interop and web_listener for SmrtChrome metadata ingestion; wsgi.py supplies the production entry point.
  • Centralizes route registration under routes/ so new endpoints ship in a consistent, testable pattern and stay aligned with documented policies.

Dependencies & Integrations

  • Built on Flask plus Flasgger (Swagger docs) and Flask-CORS for extension telemetry; production deployments typically run behind waitress or another WSGI host.
  • Reads canonical settings via python_core.config.load_or_seed_bridge_settings() and load_or_seed_web_listener_settings(), keeping file locations compliant with the Operational Data Policy.
  • Relies on shared state helpers (python_core.runtime, python_core.utils.shared_state_window, etc.) to fulfill requests and on python_core.utils.logger.get_logger_for("python-net") for structured/text logging.

Runtime Flows / Operational Workflows

  • bridge_server.app registers clipboard, hub window, trigger, structured-output, and status routes during module import; supervisors start it either via VS Code debugging or the deployment scripts under Tools/.
  • web_listener.app bootstraps CORS, exposes /tab-info and /ping, and forwards tab metadata to python_core.smrtdetect.websource.handle_tab_info.
  • wsgi.application hands the configured bridge app to WSGI servers; developers can run python python_core/net/wsgi.py for a local Waitress host when debugging outside VS Code.

Configuration & Log Paths

  • Bridge settings: %APPDATA%/SmrtHub/Config/python-net/bridge-settings.json (seeded on demand).
  • Web listener settings: %APPDATA%/SmrtHub/Config/python-net/web-listener-settings.json.
  • Logs land in %LOCALAPPDATA%/SmrtHub/Logs/python-net/python-net-log.{txt,json} via the standard Smrt.Logging pipeline and are collected in Support Bundles.

Testing & Validation Expectations

  • Execute pytest -k net (or the full suite) after changing request handlers or dispatch logic.
  • Smoke-test HTTP surfaces by launching the PythonApp under the debugger and invoking representative routes (clipboard post, status get, SmrtSearch trigger) to confirm end-to-end wiring.
  • For documentation or Swagger definition updates, rebuild the MkDocs set via the provided tasks when publishing user-facing manuals.

Support Bundle / Diagnostics Touchpoints

  • Support Bundles capture the python-net logs and current bridge/web-listener settings; keep paths unchanged so exports remain accurate.
  • /status exposes a lightweight health payload surfaced in diagnostics dashboards—preserve contract changes by documenting them here and in the associated docstrings.