{"id":18,"date":"2012-11-11T05:50:18","date_gmt":"2012-11-11T05:50:18","guid":{"rendered":"https:\/\/code4reference.com\/?p=18"},"modified":"2012-11-11T05:50:18","modified_gmt":"2012-11-11T05:50:18","slug":"code4referencepython-package-library-source-code-browsing","status":"publish","type":"post","link":"https:\/\/code4reference.com\/?p=18","title":{"rendered":"Code4ReferencePython package\/library source code browsing"},"content":{"rendered":"<p>Recently\u00a0I moved to new project where the programming language was Python. I often get confused about what module do I need to import ? what is the signature of the method\/function? etc. I also tried to consult the documentation provided by the third party library but many a times I didn\u2019t get the clear idea.\u00a0<br \/>\nHowever, Java provides javadoc which helps to figure out the type of package that needs to be included in a particular class. It also describes the function signature. This is possible because of good editors(IDE: Eclipse) with integrated javadoc. On the other hand Python editors lack these features.\u00a0Most of the Python IDEs neither help to auto-complete nor provide any help for the method\/function signature. This makes life more difficult and\u00a0frustrating.\u00a0Python third party library\/module provides their documentation but sometimes much more is needed which can sufficed through access to\u00a0source code. This helps to understand how third party library functions and gives a very first hand experience on how the code is organized, what modules are needed to be included in the project in order to access certain objects, methods, or classes, what is the method signature etc. If you have access to such information your life becomes easier while coding in Python.\u00a0<br \/>\nBitten by <b><i>source code browsing<\/i><\/b> bug I started looking for tool which can help me to browse python library source code and I stumbled upon <a href=\"http:\/\/pydoc.net\/\">pydoc.net<\/a>\u00a0and <a href=\"http:\/\/nullege.com\/\">Nullege.com<\/a>. \u00a0First we will talk about \u00a0pydoc.net and then will talk about Nullege(Don\u2019t get confused with <i><a href=\"http:\/\/docs.python.org\/library\/pydoc.html\">pydoc<\/a><\/i> module present in python).\u00a0Let\u2019s see what pydoc.net says about itself in its own words:<\/p>\n<p><i>\u201cPyDoc.net is an online open source package library for Python language. It aims to provide ease of navigation through their source code in a better and organized way. It is still on its experimental stages.\u201d<\/i><\/p>\n<p><i><br \/><\/i><\/p>\n<p><i>\u00a0<\/i>I have been using this tool for quite sometime and liked it. It provides very limited functionality e.g indexing, searching and source code. \u00a0If you are too geeky and know the technology well then in that case it might be useful. But if you are a newbie then this is not what you are looking for. If pydoc.net had provided similar functionality \u00a0as grepcode has provided for java source code, then pydoc.net would be definitely the first choice for Python developers . If you are wondering about grepcode and it\u00a0functionality, then you may be interested to check <a href=\"http:\/\/code4reference.com\/2012\/06\/android-source-code-browsing\/\">this post<\/a>. \u00a0Since grepcode doesn\u2019t provide python module source code, I have to settle with pydoc. Given that pydoc.net is experimental project and handled by single person, I would give this site 3.5 out of 5.<\/p>\n<p>Enough of talking, lets check its functionality. This site provides search service, where you can search by keyword, package\/module name and will list the related packages and modules. Checkout the \u00a0picture\u00a0below. It also lists the packages download count wise. There is one more list which shows the packages\/modules with their respective tags as marked 2 in the picture below.\u00a0<\/p>\n<table>\n<tr>\n<td><a href=\"http:\/\/1.bp.blogspot.com\/-ewUloZr3ahE\/T_Pgzzg4JgI\/AAAAAAAAAhs\/mus6tiBrKa4\/s1600\/Search+results+for+%22selenium%22+%3A+PyDoc.net+-+Google+Chrome_002.png\"><img alt='searchresultsfor22selenium223apydoc-net-googlechrome_002-9976801' src='https:\/\/code4reference.com\/wp-content\/uploads\/2012\/11\/Searchresultsfor22selenium223APyDoc.net-GoogleChrome_002-9976801.png' \/><\/a><\/td>\n<\/tr>\n<tr>\n<td>module search result<\/td>\n<\/tr>\n<\/table>\n<p>If you click the link \u201c<b><i>index package<\/i><\/b>\u201d which is marked <i>4<\/i> \u00a0in the above picture, it lists all the packages in alphanumeric wise which you can see in the shown below. This gives you idea about the similar packages and the gamut of package who share common prefix\/name.<\/p>\n<table>\n<tr>\n<td><a href=\"http:\/\/4.bp.blogspot.com\/-HeThNVQK5XY\/T_PWoKra2PI\/AAAAAAAAAhg\/QI0b8uQ_ZcY\/s1600\/Indexed+Python+packages+starts+with+'A'+%3A+PyDoc.net+-+Google+Chrome_003.png\"><\/a><\/td>\n<\/tr>\n<tr>\n<td>Module\/package index<\/td>\n<\/tr>\n<\/table>\n<p>Ok found the package name so what? Well this was the first step on the source code browsing. On selecting the package it shows the meta-data of the package\/module as shown in the picture below. This also shows how to install the package, example-code and the documentation link. In some cases it also shows the link from where the source code can be downloaded.<\/p>\n<table>\n<tr>\n<td><a href=\"http:\/\/4.bp.blogspot.com\/-s59N7VWG5uk\/T_PWgG29sRI\/AAAAAAAAAhI\/wl4XxiqsVvE\/s1600\/selenium+2.9.0+%3A+PyDoc.net+-+Google+Chrome_004.png\"><img alt='selenium2-9-03apydoc-net-googlechrome_004-2887431' src='https:\/\/code4reference.com\/wp-content\/uploads\/2012\/11\/selenium2.9.03APyDoc.net-GoogleChrome_004-2887431.png' \/><\/a><\/td>\n<\/tr>\n<tr>\n<td>Package\/module details<\/td>\n<\/tr>\n<\/table>\n<p>As you may have noticed there is a directory hierarchy which shows how modules are organized and what are the source files present under any particular directory. If you click the file name you will see the source code which will look similar to picture as shown below.<\/p>\n<p><a href=\"http:\/\/4.bp.blogspot.com\/-xYi3RO-JWbQ\/T_Pihh5p4SI\/AAAAAAAAAh0\/NAF3ipA6lP4\/s1600\/selenium.webdriver.support.ui+%3A%3A+selenium+2.9.0+%3A+PyDoc.net+-+Google+Chrome_005.png\"><img alt='selenium-webdriver-support-ui3a3aselenium2-9-03apydoc-net-googlechrome_005-9663612' src='https:\/\/code4reference.com\/wp-content\/uploads\/2012\/11\/selenium.webdriver.support.ui3A3Aselenium2.9.03APyDoc.net-GoogleChrome_005-9663612.png' \/><\/a><\/p>\n<p>Nullege also has the similar interface as that of pydoc. You can see the user interface in picture below. I noticed few differences between these two websites. Nullege doesn\u2019t give any meta information about the package and doesn\u2019t show the documentation provided by the python third party library\/package. But Nullege has the feature to search the keywords in the source code while pydoc doesn\u2019t have.<\/p>\n<p><a href=\"http:\/\/3.bp.blogspot.com\/-dUzpg69twnM\/T_TEL8Bsm9I\/AAAAAAAAAiA\/OZClSFAbApM\/s1600\/selenium.SeleniumException+-+Nullege+Python+Samples+-+Google+Chrome_006.png\"><img alt='selenium-seleniumexception-nullegepythonsamples-googlechrome_006-4989089' src='https:\/\/code4reference.com\/wp-content\/uploads\/2012\/11\/selenium.SeleniumException-NullegePythonSamples-GoogleChrome_006-4989089.png' \/><\/a><\/p>\n<p>User may not like one thing about Nullege i.e the advertisements are shown below the source code\u00a0hierarchy which restrict the complete view of directory\u00a0hierarchy. If the advertisements were shown somewhere else, it would have given more view area to the directory\/file hierarchy and hence would have provided good user experience. If asked, I would give 3 out of 5 to this website.<\/p>\n<h4>How to download source code:<\/h4>\n<p>If you are interested in downloading the source code, even that is possible with the help of \u201c<b><i>pip\u201d<\/i><\/b>. <a href=\"http:\/\/www.pip-installer.org\/en\/latest\/index.html\">Pip<\/a> is a python tool which installs the python packages and it\u2019s replacement of easy_install. If you system doesn\u2019t have the pip installed then run the following command.<\/p>\n<pre> \n$python easy_install pip\n<\/pre>\n<p>For downloading source code of particular package run the following command.<\/p>\n<pre> $pip install -src= .    #This will download the src in the current directory.\n<\/pre>\n<p>Happy source code browsing!!!<\/p>\n<p><b>Related topics:<\/b><br \/>\n<a href=\"http:\/\/code4reference.com\/2012\/06\/android-source-code-browsing\/\">Android\/java source code browsing<\/a><\/p>\n<p>Your valuable comments are always welcomed. It will help to improve my post and understanding.<\/p>\n<p><i>\u201cBy three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest.\u201d<\/i><br \/>\nBy : Confucius<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently\u00a0I moved to new project where the programming language was Python. I often get confused about what module do I need to import ? what is the signature of the method\/function? etc. I also tried to consult the documentation provided by the third party library but many a times I didn\u2019t get the clear idea.\u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18"}],"version-history":[{"count":0,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}