Question: I'm wondering if there is a module in python standard library I can use to get the total physical memory size. I know I can use psutil, but it would be great if my python script can run without installing external module. Thanks!

Edited:
Sorry guys, I forgot to mention that I'm using a mac OSX. Thanks for all the windows solutions tho!

Answer: 
If you're on Windows, you can use [GlobalMemoryStatusEx](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366589(v=vs.85).aspx), which requires only ctypes and no additional modules.

```
from ctypes import Structure, c_int32, c_uint64, sizeof, byref, windll
class MemoryStatusEx(Structure):
    _fields_ = [
        ('length', c_int32),
        ('memoryLoad', c_int32),
        ('totalPhys', c_uint64),
        ('availPhys', c_uint64),
        ('totalPageFile', c_uint64),
        ('availPageFile', c_uint64),
        ('totalVirtual', c_uint64),
        ('availVirtual', c_uint64),
        ('availExtendedVirtual', c_uint64)]
    def __init__(self):
        self.length = sizeof(self)

```

Used like this:

```
>>> m = MemoryStatusEx()
>>> assert windll.kernel32.GlobalMemoryStatusEx(byref(m))
>>> print('You have %0.2f GiB of RAM installed' % (m.totalPhys / (1024.)**3))

```

See [here](https://stackoverflow.com/a/1911863/1530134), [here](https://stackoverflow.com/a/760276/1530134), and [here](https://apple.stackexchange.com/questions/4286/is-there-a-mac-os-x-terminal-version-of-the-free-command-in-linux-systems) for information for MAC OS X/other UNIX systems.
I've utilized this function in a Windows environment previously. 

```
import os
process = os.popen('wmic memorychip get capacity')
result = process.read()
process.close()
totalMem = 0
for m in result.split("  \r\n")[1:-1]:
    totalMem += int(m)

print totalMem / (1024**3)

```

---

This utilizes [`wmic`](https://msdn.microsoft.com/en-us/library/Bb742610.aspx) and the following command `wmic memorychip get capacity`, which you can run from your command line to see output in bytes. 

This command reads the capacity of each memory module in the machine (in bytes) and then converts the total to gigabytes.

---

Example:

```
> wmic memorychip get capacity
Capacity
4294967296
4294967296

```

This shows I have two 4 GB chips.

```
> python get_totalmemory.py
8

```

Adding those two module capacities and doing a quick conversion shows I have 8 GB of RAM on this machine.