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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pypable-0.0.7.tar.gz
  • Upload date:
  • Size: 22.0 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.7.tar.gz
Algorithm Hash digest
SHA256 3182d139449c11f8138a249faa80baf43f7d76002174a9887487fd04c3f72824
MD5 fa4ce15a15af58a3c3ec9048308d5459
BLAKE2b-256 85907fd2b806f7c3dfdd9097ed09ccdb8dd83796ced22a70a6c4ae6dff298650

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pypable-0.0.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 53d57e0c07176ef68f54b7a748cebe0102f71319d21c03d031509f98ed6739b5
MD5 cd3709a9596c793125221bc2b69169fc
BLAKE2b-256 885a22921a01061e1921987cc167d6e998fc13d4f79df313f5fc049b7eeb0516

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