Get total physical memory in Python

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.

Leave a Comment