Search code examples
pythonmemorywinapimemory-managementpywin32

Get memory usage of computer in Windows with Python


How can I tell what the computer's overall memory usage is from Python, running on Windows XP?


Solution

  • You'll want to use the wmi module. Something like this:

    import wmi
    comp = wmi.WMI()
    
    for i in comp.Win32_ComputerSystem():
       print i.TotalPhysicalMemory, "bytes of physical memory"
    
    for os in comp.Win32_OperatingSystem():
       print os.FreePhysicalMemory, "bytes of available memory"