import heapq imports a Python implementation. You can confirm this by checking the heapq value in the interpreter:
In [20]: import heapq In [21]: heapq Out[21]: <module 'heapq' from '/usr/lib/python2.7/heapq.pyc'>
heapq.pyc is a byte-compiled version of the heapq.py module.
However, inside the heapq.py file:
# If available, use C implementation try: from _heapq import * except ImportError: pass
_heapqmodule.c provides the _heapqmodule.c module. Therefore, if a C implementation is available, import heapq uses a C implementation.
source share