pythonlinuxmemory

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.


Solution

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

    import psutil
    
    psutil.virtual_memory().total  # total physical memory in Bytes
    

    Documentation for virtual_memory is here.