Skip to main content

A toolset for piping values between functions, with optional shell-like text-processing tools.

Project description

Pypable: A Toolset for Piping Values and Text Processing

Introduction

Pypable is a Python package designed to simplify the process of piping values between functions and provide optional shell-like text-processing tools.

The PipableMixin class provides features to make any class pipable, in the style of traditional shells such as Bourne and Zsh.

The package's second most important feature is the Receiver, which allows you to easily chain functions and pass values between them.

Additionally, the Pypable.text module offers utilities for shell-like text processing and manipulation.

Installation

To install Pypable, use pip:

pip install pypable

Usage

PipableMixin

The PipableMixin is the most important tool in Pypable. It allows add pipe-based chaining to all methods of the inheriting class. Here's an example of how to use it:

<-- TODO ADD EXAMPLE -->

</code></pre>
<h3>Receiver Class</h3>
<p><-- TODO word this better -->
The <code>Receiver</code> class is used to create a "receiving" function call. By placing a receiver object on the right side of a pipe,
the callable defined in the receiver can be deferred rather than called at time of evaluation.
This enables any function or method to receive the value from the left side of a pipe, without needing to create a pipable object.</p>
<p><-- TODO: example --></p>
<h3>Text Module</h3>
<p>The <code>Pypable.text</code> module provides utility functions for text processing and manipulation. Here's an example of how to use it:</p>
<pre lang="python"><code>from Pypable.text import Text, grep

example = Text("""
“Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!” 
""")

example | grep('beware', insensitive=True) | print
# Beware the Jabberwock, my son!
# Beware the Jubjub bird, and sun

In this example...

Printer Utilities

The Pypable.printers module provides some simple methods for printing and decorating multi-line strings. Here's an example of how to use it:

from Pypable.printers import mprint

text = """This is a
multi-line
string."""

mprint("""
    This is a
        multi-line
    string.
    """)
# This is a
#   multi-line
# string.

In this example... Notice that the second line is indented, while the other two lines have had their indents removed. When printing with mprint, if the final line consists of only horizontal whitespace, that whitespace will be used for dedenting. Otherwise, the text will be dedented in the style of the textwrap module.

Pypable Typing

Finally, the Pypable.typing module provides a few additional tools that may be useful outside of piping context. Some of these functions include:

  • isinstance: A replacement for the built-in isinstance, this function accepts subscripted types and type-tuples.
  • class_path: Checks if an object is callable.
  • extend_class: Checks if an object is iterable.

Here's an example of how to use these functions:

<-- TODO -->

In this example...

License

Pypable is licensed under the MIT License. See the LICENSE file for more information.

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

pypable-0.0.5.tar.gz (278.4 kB view details)

Uploaded Source

Built Distribution

pypable-0.0.5-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file pypable-0.0.5.tar.gz.

File metadata

  • Download URL: pypable-0.0.5.tar.gz
  • Upload date:
  • Size: 278.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pypable-0.0.5.tar.gz
Algorithm Hash digest
SHA256 dc03a5fb896ebb54ec436f82290c758ea248b4e07b7b56cc8aebd9f81e709ce2
MD5 4574d2e89562ad346ee4949377bf0890
BLAKE2b-256 1ae4b1a3c26d6c628b40bed96d506f2a26ef32c51fdad83bce2e0c4b0191a6de

See more details on using hashes here.

File details

Details for the file pypable-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pypable-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pypable-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 91915f05b3e4f1966509e19af0d1da0cb1d6a99fb08909969c623fdd3042867d
MD5 8aba185d3d35174373b537b95c3bc84c
BLAKE2b-256 85cd024b9371aaf46c43843f3c4ee7f622a9e37019fef63be60e30b07586083f

See more details on using hashes here.

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