Introduction - Hunter 0.1.dev50 documentation (original) (raw)

Edit this page

Toggle table of contents sidebar

Installation

To install hunter run:

The trace function

The hunter.trace function can take 2 types of arguments:

Note that hunter.trace will use hunter.Q when you pass multiple positional arguments or keyword arguments.

The Q function

The hunter.Q() function provides a convenience API for you:

Note that the default junction hunter.Q() uses is hunter.predicates.And.

Composing

All the builtin predicates (hunter.predicates.Query, hunter.predicates.When,hunter.predicates.And, hunter.predicates.Not and hunter.predicates.Or) support the |, & and ~ operators:

Operators

Added in version 1.0.0: You can add startswith, endswith, in, contains, regex, lt, lte, gt, gte to your keyword arguments, just like in Django. Double underscores are not necessary, but in case you got twitchy fingers it’ll just work - filename__startswith is the same as filename_startswith.

Added in version 2.0.0: You can also use these convenience aliases: sw (startswith), ew (endswith), rx (regex) andhas (contains).

Examples:

Note

If you want to filter out stdlib stuff you’re better off with using Query(stdlib=False).

Activation

You can activate Hunter in three ways.

from code

import hunter hunter.trace( ... )

with an environment variable

Set the PYTHONHUNTER environment variable. Eg:

PYTHONHUNTER="module='os.path'" python yourapp.py

On Windows you’d do something like:

set PYTHONHUNTER=module='os.path' python yourapp.py

The activation works with a clever .pth file that checks for that env var presence and before your app runs does something like this:

from hunter import * trace( )

That also means that it will do activation even if the env var is empty, eg: PYTHONHUNTER="".

with a CLI tool

If you got an already running process you can attach to it with hunter-trace. See Remote tracing for details.