top of page


How can I get the source code of the Python Packages?

You can find source code on Github. Under cpython you will be able to find all the modules and python objects (written in C).

You can also find which file (using __file__ attribute) on your system is used for respective module. For example math and random module,

>>> import math
>>> import random 
>>> math.__doc__
'This module is always available.  It provides access to the\nmathematical functions defined by the C standard.' 
>>> math.__file__
>>> random.__file__

Now, you can get source code for objects written in python (not C) with inspect get source code. You can also refer Python docs for “inspect” library.

>>> import inspect
>>> inspect.getsourcelines(random) 
(['"""Random variable generators.\n',
'    integers\n',  
'    --------\n',  
'           uniform within range\n',  
'    sequences\n',  
'    ---------\n',  
'           pick random element\n',  
'           pick random sample\n',  
so on..


Want to share your thoughts about this blog?

Disclaimer: Please note that the information provided on this website is for general informational purposes only and should not be taken as legal advice. Dataneb is a platform for individuals to share their personal experiences with visa and immigration processes, and their views and opinions may not necessarily reflect those of the website owners or administrators. While we strive to keep the information up-to-date and accurate, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability, or availability with respect to the website or the information, products, services, or related graphics contained on the website for any purpose. Any reliance you place on such information is therefore strictly at your own risk. We strongly advise that you consult with a qualified immigration attorney or official government agencies for any specific questions or concerns related to your individual situation. We are not responsible for any losses, damages, or legal disputes arising from the use of information provided on this website. By using this website, you acknowledge and agree to the above disclaimer and Google's Terms of Use ( and Privacy Policy (

bottom of page