📦WebSocket Imports

This section documents all the imports used in backend/main.py and their purposes.


Standard Library Imports

  • datetime
    For handling dates and times, such as timestamps and formatting.

  • platform
    To retrieve information about the underlying platform (OS, node, release, etc.).

  • time
    For time-related functions, such as calculating uptime.

  • typing (Dict, Set)
    For type hinting dictionaries and sets.

  • contextlib (asynccontextmanager)
    To manage the application lifespan with asynchronous context managers.

  • asyncio
    For asynchronous programming, including tasks, locks, and sleep.

  • json
    For encoding and decoding JSON data.


Third-Party Imports

  • fastapi

    • FastAPI: The main FastAPI application class.
    • WebSocket: For handling WebSocket connections.
  • fastapi.middleware.cors (CORSMiddleware)
    To enable Cross-Origin Resource Sharing (CORS) for the API.

  • psutil
    For retrieving system information such as CPU, memory, disk, sensors, and network stats.

  • docker
    For interacting with Docker, including listing images and containers.


Summary Table

ModulePurpose
datetimeDate and time handling
platformSystem/platform information
timeTime calculations
typingType hints for Dict and Set
contextlibAsync context management
fastapiAPI and WebSocket framework
fastapi.middleware.corsCORS middleware for FastAPI
psutilSystem resource monitoring
asyncioAsync programming primitives
jsonJSON serialization/deserialization
dockerDocker API interaction