Justin Justin - 2 months ago 20
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.


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.