Skip to main content

Operating System - API Specification

Version: v1.3.0 | Status: Active | Last Updated: March 2026

1. Overview​

The operating_system module provides cross-platform OS abstraction with auto-detection and platform-specific providers for macOS, Linux, and Windows. Zero external dependencies — uses subprocess and native OS commands.

2. Core Components​

2.1 Generic API Functions​

FunctionSignatureDescription
detect_platform() -> OSPlatformAuto-detect the current OS platform
get_provider() -> OSProviderBaseGet the platform-specific provider (cached)
get_system_info() -> SystemInfoFull system information (hostname, CPU, memory, etc.)
list_processes(limit=None) -> list[ProcessInfo]List running processes
get_disk_usage() -> list[DiskInfo]Disk usage for all mounted volumes
get_services() -> list[ServiceInfo]List system services and their status
get_network_interfaces() -> list[NetworkInfo]List network interfaces with addresses
execute_command(cmd, ...) -> CommandResultRun a shell command and capture output
get_environment_variables() -> dictGet all environment variables

2.2 Data Models​

ClassDescription
SystemInfoSystem metadata (hostname, OS, CPU count, total memory)
ProcessInfoProcess details (PID, name, CPU%, memory)
DiskInfoDisk partition usage (mount, total, used, free)
ServiceInfoService details (name, status, PID)
NetworkInfoNetwork interface details (name, address, MAC)
CommandResultCommand execution result (stdout, stderr, returncode)

2.3 Enums​

EnumValues
OSPlatformMACOS, LINUX, WINDOWS
ProcessStatusRUNNING, SLEEPING, STOPPED, ZOMBIE
ServiceStatusRUNNING, STOPPED, UNKNOWN

2.4 Base Class​

ClassDescription
OSProviderBaseAbstract base for platform-specific providers

3. Usage Example​

from codomyrmex.operating_system import detect_platform, get_system_info, list_processes

platform = detect_platform()
print(f"Running on: {platform.value}")

info = get_system_info()
print(f"CPUs: {info.cpu_count}, Memory: {info.total_memory_gb:.1f} GB")

processes = list_processes(limit=5)
for p in processes:
print(f"[{p.pid}] {p.name}")

4. Navigation​