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.6.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

pypable-0.0.6-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pypable-0.0.6.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pypable-0.0.6.tar.gz
Algorithm Hash digest
SHA256 8b6f73c74656fcc08f53842eac89041725a26b5d2e34aacdde847fd66c8ebd12
MD5 cd36d1cccfd9004c8ce9b7ae3e16777b
BLAKE2b-256 ed8d6127ee52e33940c5b096be6be676d2a734df38432377e70170f3f93dd4cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pypable-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pypable-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 21af27398065269f5504a7f309647605daa22686b82aedd9df33a90833461ba8
MD5 2efaead64f2457be4bfe753e7a28ebee
BLAKE2b-256 938ec15746dee0df7725beb2ac01e3b993aef433a5dc763cf56afd44b7a1e851

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