Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Locate python object definition in your file-system

Project description

Build Status Coverage Status Last released version Supported python versions Download rate Package stability License

pyloc prints the location of the definition of any python object in your file-system.


pyloc is very similar to what python3 -m inspect -d <object> offers. However, it is only focused to retrieve the file name (and eventually the line number) where a given Python object is defined. The object can be a package, module, class, method or function.

pyloc makes some further efforts to figure out the line and column number and its output is formatted so that it can easily be passed to emacsclient or vi.


You can see the location of Popen.wait method in the sub-process package:

$ python -m pyloc -f human subprocess:Popen.wait
Filename: /Users/polrop/.pyenv/versions/2.7.9/lib/python2.7/
Line: 1379

$ python -m pyloc -f human email.utils:formataddr
Filename: /Users/polrop/.pyenv/versions/2.7.9/lib/python2.7/email/
Line: 85

(Output may be different on your system if you have different installation path and version)

Note that the object naming syntax is as follow: module[:qualname] Since version 0.2.0, syntax module[.qualname] a la pydoc is also supported.

To open it in Emacs you can do:

$ emacsclient `python -m pyloc -f emacs subprocess:Popen.wait`

or in vim:

$ vim `python -m pyloc -f vi subprocess:Popen.wait`

If you are lazy typing -f <format> all the time and you often use the same format, you can set the default output format this way (you can add this line in your .zshenv or .bashrc):


pyloc will always locate object based on the python interpreter your are using:

$ python3 -m pyloc -f human subprocess:Popen.wait
Filename: /Users/polrop/.pyenv/versions/3.4.3/lib/python3.4/
Line: 1526

$ /usr/local/bin/python -m pyloc -f human email.utils:formataddr
Filename: /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/
Line: 85

$ /usr/bin/python -m pyloc -f human email.utils:formataddr
Filename: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/
Line: 85


Using pip

You can install pyloc using pip like this:

$ pip install pyloc


$ pip3 install pyloc

Directly from the source

$ git clone
$ cd pyloc
$ python develop
# If you also want it for Python 3
$ python3 develop

Note that if you also install the Python 3 version, the pyloc2 command line driver will not work but the pyloc driver will point to the Python 2 installation.

To uninstall it, you ca do:

$ python develop --uninstall
# And if you installed the Python 3 version
$ python3 develop --uninstall

However, this won’t remove the entry scripts generated by easy install.

Known bugs

  • Classes or built-in types like int or str do not contain location information. In this case pyloc tries to look for the name in the AST. This procedure may not be accurate since Python is a dynamic language.


See HACKING for details.

Release notes

See the corresponding tag annotation. After cloning you can do for instance:

$ git show v0.1.10


pyloc is released under the term of the Simplified BSD License. Copyright (c) 2015-2106, Nicolas Desprès All rights reserved.

As noted in the source code, some part has been inspired by code from the inspect module written by Ka-Ping Yee <> and Yury Selivanov <> form the Python 3.4.3 distribution (see the LICENSE file in the python distribution)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyloc, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size pyloc-0.2.0-py2-none-any.whl (16.3 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size pyloc-0.2.0-py3-none-any.whl (16.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pyloc-0.2.0.tar.gz (16.3 kB) File type Source Python version None Upload date Hashes View
Filename, size (23.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page