Memray is an open-source memory profiler for Python, developed by Bloomberg. Bloomberg has over 3,000 software developers who code in Python, as well as a Python Infrastructure team to support those developers. 

The team created Memray to enable developers to analyze their memory allocations, thus enabling them to reduce memory usage, find leaks, and identify memory hotspots in code. 

The tool was recently open-sourced so that Python developers all over the world could take advantage of it. 

Some key features of Memray include tracing of every function call, handling of native calls in C/C++ library, report generation, and the ability to work with both Python and native threads.

According to Bloomberg, some of the benefits of Memray include speed, gathering of large amounts of data, that it can be activated and deactivated at runtime, and that it shows the merged Python and C/C++ stack for each allocation so that it can be understood how memory is being allocated in native extensions.  

“There are some great open source profilers available to figure out where a Python program is spending its time. However, there haven’t been many great solutions for figuring out where a Python program is spending its memory, especially when that memory is allocated by a native extension module. My hope is that the next time someone wonders why a script is using so much memory, they’re able to figure it out without needing to change anything about their program besides how they run it,” said Pablo Galindo Salgado, member of the Python Infrastructure team at Bloomberg, in an interview posted on Bloomberg’s blog