Justin Justin - 1 year ago 113
Linux Question

Get total physical memory in Python

How can I get the total physical memory within Python in a distribution agnostic fashion? I don't need used memory, just the total physical memory.

Answer Source

your best bet for a cross-platform solution is to use the psutil package (available on PyPI).

from psutil import virtual_memory

mem = virtual_memory()
mem.total  # total physical memory available

Documentation for virtual_memory is here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download