Multiple builds of the same Python version can coexist on one machine. A 32-bit and a 64-bit build, a free-threaded build alongside a GIL-enabled one, a debug build next to a release build. Compiled extension modules are not compatible between them, so code that loads native libraries, selects wheels, or reports diagnostics often needs to know which variant is running.
Determining the pointer width in bits, free-threading status, debug flag and byte order previously meant querying several unrelated places. Since Python 3.15, the sys module provides abi_info, which gathers these four values into a single object.
import sys
print(sys.abi_info)
Output example:
namespace(pointer_bits=64, free_threaded=False, debug=False, byteorder='little')
Each value is also available as an individual attribute.
import sys
print(sys.abi_info.pointer_bits) # 64
print(sys.abi_info.free_threaded) # False
print(sys.abi_info.debug) # False
print(sys.abi_info.byteorder) # little
The pointer_bits attribute reports the pointer width in bits, and is typically 32 or 64. The free_threaded attribute is True when the interpreter was built with free threading support, reflecting the --disable-gil configure option. The debug attribute is True for a debug build, reflecting --with-pydebug. The byteorder attribute holds 'big' or 'little'.
Leave a Comment
Cancel reply