Skip to main content

pelper - python helper functions

Project description

build status coverage read the docs

pelper – python helper functions to ease measuring, ignoring, caching, …

pelper contains useful helper functions, decorators, context managers - all the stuff that make the python life a tiny bit easier. It has no dependencies, has a coverage of 100%, and is well documented.

Examples

Measure the duration of a function:

from pelper import print_duration
@print_duration()
def f(n):
    pass

Measure duration of a context:

from pelper import print_duration
with print_duration():
    range(4)

Ignore exceptions:

from pelper import ignored
with ignored(OSError):
    raise OSError()  # this is ignored

Cache already computed results of functions:

from pelper import cache
@cache
def fib(n):
    return 1 if n < 2 else fib(n-1) + fib(n-2)

f(500)  # this would run for quite a wile without the cache decorator

Pipe data through unix-like pipes

from pelper import pipe
pipe("some datat, some data",
     set,
     (sorted, {"reverse": True}))

Take n elements from iterables (useful if you can’t use the square bracket notation, e.g., if you’re using pipe)

from pelper import take
take(2, range(5))

Take the n-th elements from iterables (useful if you can’t use the square bracket notation, e.g., if you’re using pipe)

from pelper import nth
nth(2, range(5))

Installation

pelper is only one file and has no dependencies. You can simply drop pelper.py into your project and use it.

Run the tests:

python pelper.py

TODO

  • install via pip and conda

Project details


Download files

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

Source Distributions

pelper-0.0.2.tar.gz (4.4 kB view hashes)

Uploaded Source

pelper-0.0.2.linux-x86_64.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

pelper-0.0.2-py2.7.egg (7.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page