Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Extract Python Tracebacks from text

Project Description

A module & command-line tool for extracting Python tracebacks from text.

Extracting tracebacks from bunch of files

$ tbgrep file1 file2 file3

Grepping for tracebacks in a pipeline

$ tail -f logfile | tbgrep

Displaying all unique tracebacks ordered by the number of occurrences

$ tbgrep --stats logfile

== 99 occurences ==================================================

Traceback (most recent call last):
 File "/usr/lib/python2.4/site-packages/bodhi/", line 209, in _masher_request
 File "/usr/lib/python2.4/site-packages/fedora/client/", line 285, in send_request
   raise AuthError(_('Unable to log into server.  Invalid'
AuthError: Unable to log into server.  Invalid authentication tokens.  Send new username and password

733 unique tracebacks extracted

Using the Python API

Once instantiated, you pass each line to the process method, which will return either None, or a string of a traceback.

from tbgrep import TracebackGrep

extractor = TracebackGrep()
for line in file('logfile'):
    tb = extractor.process(line)
    if tb:

Instead of displaying each traceback found in the file, tbgrep also supports generating statistics about all tracebacks in the file.

extractor = TracebackGrep(stats=True)
for line in file('logfile'):

There are also some functions that allow you to search for tracebacks in a more convenient way.

from tbgrep import (
    tracebacks_from_lines, tracebacks_from_file,
for tb in tracebacks_from_file(file('logfile')):
for tb in tracebacks_from_file(file('logfile'), reverse=True):

Supported Input Formats

tbgrep can extract tracebacks from logs of various formats. For example, CherryPy starts the traceback on a line with other details (like module, timestamp, etc), but the rest of the trace starts at the beginning of the line. Apache logs, on the other hand, will prefix each line of the traceback with this information. tbgrep is designed to handle these kinds of situations

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(18.1 kB) Copy SHA256 Hash SHA256
Source None Jan 30, 2015

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers