Skip to main content

pelper - python helper functions

read the docs Coverage status Build status PyPI page Github page

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', ',', ' ']

Pelper offers p-functions, i.e., functions where the first argument is data. There is pmap (like map, but works with pipel):

>>> from pelper import pipe, pmap
>>> pipe(
...     range(5),
...     (pmap, lambda x: x*x),
...     list)
[0, 1, 4, 9, 16]

…and also pfilter:

>>> from pelper import pipe, pfilter
>>> pipe(
...     range(5),
...     (pfilter, lambda x: x > 2),
...     list)
[3, 4]

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)
['h', 'e', 'l', 'l', 'o']

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

Easier printing and formating:

>>> from pelper import printf
>>> printf("Hello {name}, I'm {something}", name="Alan", something="world")
Hello Alan, I'm world

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 .

Development

Use virtualenv for working on pelper. Install the dev requrirements via:

pip install -e requirements-dev.txt

Tests

pelper uses doctest, py.test, and tox for testing. It also has Coverage status coverage.

You can run the tests for all supported versions of python and build and test the docs:

tox

Run only the tests for the specified version of python:

tox -e py27,py34,py35

Alternatively just run tests for the current version of python:

py.test

Docs

Build the docs via:

cd docs
sphinx html

Metadata

Release files for pelper 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pelper 0.1.0
File Size Uploaded Provenance Actions
pelper-0.1.0.tar.gz 6.5 kB Without provenance Details for pelper-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pelper 0.1.0
File Interpreter ABI Platform Actions
pelper-0.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for pelper-0.1.0-py2.py3-none-any.whl

Total release size: 15.6 kB

Release files / pelper-0.1.0.tar.gz

Download URL pelper-0.1.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2b753d3c440704161431a7bab5a9e79ab318bab55a77b9732c7352b5ec7eac98
BLAKE2b-256 checksum
How to use checksums
5cdf7a0573d56786b840405bff6a9fd56675e5277b79119d00c27f3d1f7545c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pelper-0.1.0-py2.py3-none-any.whl

Download URL pelper-0.1.0-py2.py3-none-any.whl
Size 9.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d2f91123a3ff841f2cf10f5e39242235cca643711f142e0c2b50567b5ec075e9
BLAKE2b-256 checksum
How to use checksums
259b6f032b61b422e84ac0b567c14ad9e06f4ca945af276354d986e65447d5df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pelper 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page