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, piping, functional helpers, and more for python 2.7, 3.4, and 3.5.

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

Examples

Pipe data through unix-like/elixir-like pipes:

>>> from pelper import pipe
>>> pipe("some datat, some data",
>>>      set,
>>>      (sorted, {"reverse": True}))
['t', 's', 'o', 'm', 'e', 'd', 'a', ',', ' ']

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("hello world", 5)
'hello'

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(range(5), 2)
2

Flatten arbitrarily nested lists:

>>> from pelper import flatten
>>> flatten([1, [2, 2, [3, 3]]])
[1, 2, 2, 3, 3]

Measure the duration of a function:

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

Measure the 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

Installation

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

Or install it from pypi by running:

pip install pelper

Or install it from source by running:

pip install .

Tests

pelper uses doctest extensively and has coverage. You can run the tests with:

python pelper/pelper.py

or:

python -m doctest pelper/pelper.py

or:

python3 pelper/pelper.py

or:

python3 -m doctest pelper/pelper.py

Project details


Download files

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

Source Distribution

pelper-0.0.3.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

pelper-0.0.3-py2.py3-none-any.whl (7.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pelper-0.0.3.tar.gz.

File metadata

  • Download URL: pelper-0.0.3.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pelper-0.0.3.tar.gz
Algorithm Hash digest
SHA256 92e7ca096cc0fccbbbbd97571f3cbdaa5cd53a1c8179f72f2e16d0a51b5441ef
MD5 ab4fb9ba27ddcd6de47b4d606d6b5e15
BLAKE2b-256 447e75ffc27540192913948bcabdeb0451c7e456b7f9bb7cdc0457b0220ef401

See more details on using hashes here.

Provenance

File details

Details for the file pelper-0.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pelper-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 91df5d0de37ae0dbdacf3cf2c58ce9472a14413677bc2ee2655faa5e77ff4f32
MD5 96a7f60d13a5190b0517dd8da084fabd
BLAKE2b-256 bb1fce7b1d74d919a335c6608b11d2d5b8bbc83bb4722f3ed001cf836cde25f8

See more details on using hashes here.

Provenance

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