Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I find the python standard library code?

Tags:

python

I wanted to try and look up the source of some of the modules in the Python standard library, but wasn't able to find them. I tried looking in the modules directory after downloading the python tarball, but it has mainly .c files. I also tried looking at the directory where the python that already comes with the OS (mac osx) has it's modules, and there it seems to have mainly .pyc and .pyo files. Would really appreciate it if someone can help me out.

(I tried what was suggested in the question How do I find the location of Python module sources? with no luck)

like image 890
iman453 Avatar asked Jul 08 '12 18:07

iman453


People also ask

How do I find my Python library code?

We use the getsource() method of inspect module to get the source code of the function. Returns the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object.

Where is the Python standard library located?

For Windows, the standard location is based on the directory into which Python is installed. For most Linux environments, Python is installed under /usr/local , and the libraries can be found there. For Mac OS, the home directory is under /Library/Frameworks/Python.

What is Python standard library?

The Python Standard Library is a collection of script modules accessible to a Python program to simplify the programming process and removing the need to rewrite commonly used commands. They can be used by 'calling/importing' them at the beginning of a script.

Does Python have a standard library?

Python standard library. The Python Standard Library contains the exact syntax, semantics, and tokens of Python. It contains built-in modules that provide access to basic system functionality like I/O and some other core modules. Most of the Python Libraries are written in the C programming language.


2 Answers

In cpython, many modules are implemented in C, and not in Python. You can find those in Modules/, whereas the pure Python ones reside in Lib/.

In some cases (for example the json module), the Python source code provides the module on its own and only uses the C module if it's available (to improve performance). For the remaining modules, you can have a look at PyPy's implementations.

like image 88
phihag Avatar answered Oct 18 '22 18:10

phihag


The canonical repository for CPython is this Mercurial repository. There is also a git mirror on GitHub.

like image 2
jameshfisher Avatar answered Oct 18 '22 18:10

jameshfisher