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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pypable-0.1.0.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.1.0.tar.gz
Algorithm Hash digest
SHA256 b843f591f48dd5a41820cf1ebfe745c002b4dba70ae2e780a7d75e5fb3e60e29
MD5 f7210289977decbd97802464e34b730a
BLAKE2b-256 27b5c20cda82dbeb5995bbeb1feb7ba700940a8274d3ebf99359e602a6662587

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pypable-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.8 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48b10b94701c8689e1239f0a6ee86f371cf556f5419bba8b14a5f5a4178c487e
MD5 0f31c228b6953f16538a1609b95c8038
BLAKE2b-256 e9d1d64b563d763c94f58ef1876d9c828b748f70d14b8a7995c110696ad79d4e

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