<commit_before>pyratchet
=========

pyratchet is a generic library for reporting exceptions and other messages to Ratchet.io_::

    import ratchet, sys
    ratchet.init('YOUR_ACCESS_TOKEN', 'production')  # access_token, environment

    try:
        main_app_loop()
    except IOError:
        ratchet.report_message('Got an IOError in the main loop', 'warning')
    except:
        # catch-all
        ratchet.report_exc_info(sys.exc_info())


Requirements
------------
pyratchet requires:

- Python 2.6 or 2.7
- requests 0.12+
- a Ratchet.io account


Installation
------------
Install using pip::
    
    pip install ratchet


Configuration
-------------
**For generic Python or a non-Django/non-Pyramid framework, follow these instructions:**

Somewhere in your initialization code, call ratchet.init() with your access_token::

    ratchet.init('YOUR_ACCESS_TOKEN_HERE', environment='production')

Other options can be passed as keyword arguments. See the reference below for all options.

**If you are integrating with Django, follow these instructions:**

1. In your ``settings.py``, add ``'ratchet.contrib.django.middleware.RatchetNotifierMiddleware'`` as the last item in ``MIDDLEWARE_CLASSES``::

    MIDDLEWARE_CLASSES = (
        # ... other middleware classes ...
        'ratchet.contrib.django.middleware.RatchetNotifierMiddleware',
    )

2. Add these configuration variables in ``settings.py``::

    RATCHET = {
        'access_token': 'YOUR_ACCESS_TOKEN_HERE',
        'environment': 'development' if DEBUG else 'production',
        'branch': 'master',
        'root': '/absolute/path/to/code/root',
    }

**If you are integrating with Pyramid, follow these instructions:**

1. In your ``ini`` file (e.g. ``production.ini``), add ``ratchet.contrib.pyramid`` to the end of your ``pyramid.includes``::
    
    [app:main]
    pyramid.includes =
        pyramid_debugtoolbar
        ratchet.contrib.pyramid
  
2. Add these ratchet configuration variables::
    
    [app:main]
    ratchet.access_token = YOUR_ACCESS_TOKEN_HERE
    ratchet.environment = production
    ratchet.branch = master
    ratchet.root = %(here)s

Usage
-----
The Django and Pyramid integration will automatically report uncaught exceptions to Ratchet.

Call ``ratchet.report_exc_info()`` to report an exception, or ``ratchet.report_message()`` to report an arbitrary string message. See the docstrings for more info.


Configuration reference
-----------------------

access_token
    Access token from your Ratchet.io project<commit_msg>docs for using the new filter<commit_after>pyratchet
=========

pyratchet is a generic library for reporting exceptions and other messages to Ratchet.io_::

    import ratchet, sys
    ratchet.init('YOUR_ACCESS_TOKEN', 'production')  # access_token, environment

    try:
        main_app_loop()
    except IOError:
        ratchet.report_message('Got an IOError in the main loop', 'warning')
    except:
        # catch-all
        ratchet.report_exc_info(sys.exc_info())


Requirements
------------
pyratchet requires:

- Python 2.6 or 2.7
- requests 0.12+
- a Ratchet.io account


Installation
------------
Install using pip::
    
    pip install ratchet


Configuration
-------------
**For generic Python or a non-Django/non-Pyramid framework, follow these instructions:**

Somewhere in your initialization code, call ratchet.init() with your access_token::

    ratchet.init('YOUR_ACCESS_TOKEN_HERE', environment='production')

Other options can be passed as keyword arguments. See the reference below for all options.

**If you are integrating with Django, follow these instructions:**

1. In your ``settings.py``, add ``'ratchet.contrib.django.middleware.RatchetNotifierMiddleware'`` as the last item in ``MIDDLEWARE_CLASSES``::

    MIDDLEWARE_CLASSES = (
        # ... other middleware classes ...
        'ratchet.contrib.django.middleware.RatchetNotifierMiddleware',
    )

2. Add these configuration variables in ``settings.py``::

    RATCHET = {
        'access_token': 'YOUR_ACCESS_TOKEN_HERE',
        'environment': 'development' if DEBUG else 'production',
        'branch': 'master',
        'root': '/absolute/path/to/code/root',
    }

**If you are integrating with Pyramid, follow these instructions:**

1. In your ``ini`` file (e.g. ``production.ini``), add ``ratchet.contrib.pyramid`` to the end of your ``pyramid.includes``::
    
    [app:main]
    pyramid.includes =
        pyramid_debugtoolbar
        ratchet.contrib.pyramid
  
2. Add these ratchet configuration variables::
    
    [app:main]
    ratchet.access_token = YOUR_ACCESS_TOKEN_HERE
    ratchet.environment = production
    ratchet.branch = master
    ratchet.root = %(here)s

The above will configure ratchet to catch and report all exceptions that occur in your Pyramid app. However, if there are any middleware
applications that wrap your app, Ratchet will not be able to catch exceptions. 

In order to catch exceptions from Pyramid and middleware code, you will need to create a ``pipeline`` where the ratchet middleware wraps your Pyramid app.

- Change your ``ini`` file to use a ``pipeline``::

    From

    [app:main]
    ...

    To

    [pipeline:main]
    pipeline =
        ratchet
        YOUR_APP_NAME

    [app:YOUR_APP_NAME]
    pyramid.includes =
        pyramid_debugtoolbar
        ratchet.contrib.pyramid

    [filter:ratchet]
    access_token = YOUR_ACCESS_TOKEN_HERE
    environment = production
    branch = master
    root = %(here)s


Unfortunately, the ratchet tween and the ratchet filter configurations contains duplicated information. We'll look into fixing this in future versions.

Usage
-----
The Django and Pyramid integration will automatically report uncaught exceptions to Ratchet.

Call ``ratchet.report_exc_info()`` to report an exception, or ``ratchet.report_message()`` to report an arbitrary string message. See the docstrings for more info.


Configuration reference
-----------------------

access_token
    Access token from your Ratchet.io project
{'fraction_non_alphanumeric': 0.11295681063122924, 'fraction_numerical': 0.003654485049833887, 'mean_word_length': 3.2491178546224417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '280716', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1704, 'n_words': 561}