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!

No project description provided.

Project Description


exgurd provides a decorator to guard a function or method against exceptions. This is useful in situations where untrusted code is executed, e.g. when executing a third-party module in a framework.

In comparison to the suppress context manager from Python 3, exguard provides more means to control exception handling:

  • filter on modules and namespaces to define which exceptions to catch and leave exceptions in other code untouched
  • execute a callback function once an exception was caught
  • execute a callback function in the finally block

For example, an API method in a web application that calls through to code in third-party modules can be guarded against exceptions in this modules only, while having exceptions in the framework itself be raised verbatim:

from exguard import guard, traceback_str

def throw_to_client(exception, module):
    tb = traceback_str(exception)

    # Do something to pass a traceback to the browser, disable the plugin,…

# All third-party modules are under one namespace
@guard(modules=["myframework.plugins"], submodules=True, fullstack=True, cb_except=throw_to_client)
def call_plugin_api():
    # An exception inside this will be caught

    # This will still raise an exception like normal
    x = 17 / 0


exguard has been started as a part of Veripeditus, mainly by Eike Tim Jesinghaus <>.



  • Guard against <string> or other non-module frames.


  • Add utility function to get full traceback as string.
  • Re-licence under MIT.
  • Minor documentation updates.


  • First release.

Release History

This version
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
(7.0 kB) Copy SHA256 Hash SHA256
Wheel 3.5 Aug 31, 2017
(4.1 kB) Copy SHA256 Hash SHA256
Source None Aug 31, 2017

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 DreamHost DreamHost Log Hosting