Many built-in libraries use C implementations whenever possible.
For example, heapq uses lib-dynload/_heapq.so if it’s available.
Where can I find source code of modules like _heapq?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To see the code for any version of CPython, go to:
Replace the 3.3 with 3.2, 2.3, whatever for older versions. You can also explicitly put an hg revision number instead of a major.minor version, if you know what you’re looking for.
The C modules are mostly inside the
Modulessubdirectory, and each one is generally namedfoo.corfoomodule.c, while the Python libraries are in theLibsubdirectory, namedfoo.py.In the case of
heapq, the actualheapqmodule is in Python (Lib/heapq.py), but it uses a C module named_heapq(Modules/_heapqmodule.c).Of course you can also download the source. On the front page of http://python.org there are “Quick Links” for “Source Distribution” for the latest 2.x and 3.x versions, or you can click Download for all the other releases. The structure is, as you’d expect, the same thing you see at http://hg.python.org.