Skip to content
Actively maintained fork of python-ctags with Python 3 support
C Python Makefile
Branch: master
Clone or download
Pull request Compare This branch is 25 commits ahead of sbraz:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Rebuild Cython extension to support Python 3.7 Jul 20, 2018
tests Improve tests based on the old upstream ones May 9, 2016
.gitignore Add .gitignore, remove .pyc files May 9, 2016
.project r186627@www: hai | 2009-02-22 01:06:21 -0700 Feb 22, 2009
.travis.yml Add Python 3.6 and 3.7 to Travis (use Xenial and sudo) Jul 21, 2018 Version 1.3.0 Jul 25, 2018 Include examples in releases May 13, 2016
Makefile Remove PYTHONPATH from Makefile for tests May 10, 2016 Update information about the upstream project of readtags.c Jul 12, 2016
license.txt add license file Feb 22, 2009 Version 1.3.0 Jul 25, 2018

Build Status

NOTE: This a fork from the original python-ctags that adds support for Python 3. It is currently maintained by Jonas Haag.

Ctags supports indexing of many modern programming languages. Python is a powerful scriptable dynamic language. Using Python to access Ctags index file is a natural fit in extending an application's capability to examine source code.

This project wrote a wrapper for read tags library. I have been using the package in a couple of projects and it has been shown that it could easily handle hundreds of source files.



From Python Package Index,

pip install python-ctags3


python ./ build
python ./ install

Use Cases

Generating Tags

In command line, run

ctags --fields=afmikKlnsStz readtags.c  readtags.h

Opening Tags File

import ctags
from ctags import CTags, TagEntry
import sys

    tagFile = CTags('tags')

# Available file information keys:
#  opened -  was the tag file successfully opened?
#  error_number - errno value when 'opened' is false
#  format - format of tag file (1 = original, 2 = extended)
#  sort - how is the tag file sorted? 
#  author - name of author of generating program (may be empy string)
#  name - name of program (may be empy string)
#  url - URL of distribution (may be empy string)
#  version - program version (may be empty string)

print tagFile['name']
print tagFile['author']
print tagFile['format']

# Available sort type:

# Note: use this only if you know how the tags file is sorted which is 
# specified when you generate the tag file
status = tagFile.setSortType(ctags.TAG_SORTED)

Obtaining First Tag Entry

entry = TagEntry()
status = tagFile.first(entry)

if status:
    # Available TagEntry keys:
    #  name - name of tag
    #  file - path of source file containing definition of tag
    #  pattern - pattern for locating source line (None if no pattern)
    #  lineNumber - line number in source file of tag definition (may be zero if not known)
    #  kind - kind of tag (none if not known)
    #  fileScope - is tag of file-limited scope?
    # Note: other keys will be assumed as an extension key and will 
    # return None if no such key is found 

    print entry['name']
    print entry['kind']

Finding a Tag Entry

# Available options: 
# TAG_PARTIALMATCH - begin with
# TAG_FULLMATCH - full length matching
# TAG_IGNORECASE - disable binary search
# TAG_OBSERVECASE - case sensitive and allowed binary search to perform

if tagFile.find(entry, 'find', ctags.TAG_PARTIALMATCH | ctags.TAG_IGNORECASE):
    print 'found'
    print entry['lineNumber']
    print entry['pattern']
    print entry['kind']

# Find the next tag matching the name and options supplied to the 
# most recent call to tagFile.find().  (replace the entry if found)
status = tagFile.findNext(entry)

# Step to the next tag in the file (replace entry if found)
status =
You can’t perform that action at this time.