Skip to main content

Simple text-stream processing functionality

Project description

logo

CI (License MIT 1.0)

rill

Python library providing simple text-stream processing functionality

Table of contents

Introduction

With grep, sed, wc, cat, sort, uniq, head, tail, tr, etc., we have a set of extremely powerful and time-proven tools for pipeline-processing text on the command line ubiquitously available.

But some tasks that start out as a simple one-liner, over time, can mutate into a mess ("write-only code"), especially if the requirements grow or some edge cases need special handling, such that having things in a "normal" programming language would be more convenient.

This is where rill comes into play. It provides simple text-stream processing functionality in Python. And while it is much less powerful (features and throughput, hence the name "rill") compared to the good old Unix tools, there is the advantage that one-liners written using rill can easily be expanded to longer Python scripts.

Also, in case one is already familiar with Python, but not (yet) with the Unix tools, it can be a somewhat more convenient entry point to text-stream processing.

Examples

Assuming you have an example_input.txt like so:

Hello, fellow dev,
this test file helps to show
the thrilling things
you can do with rill. ;)

You can do stuff like the following:

# Drop all lines not containing "rill", and replace "rill" with "RILL".
python3 -c 'import rill; rill.inp().grep("rill").replace("rill", "RILL").show()' example_input.txt
# Same as: grep rill example_input.txt | sed 's/rill/RILL/g'

Output:

the thRILLing things
you can do with RILL. ;)
# Count the number of lines containing an "e".
python3 -c 'import rill; rill.inp().grep("e").line_count().show()' example_input.txt
# Same as: cat example_input.txt | grep e | wc -l

Output:

3

You can also use it as part of normal Unix pipelines, e.g.:

cat example_input.txt | grep 'rill' | python3 -c 'import rill; rill.inp().replace("rill", "RILL").show()'

Output:

the thRILLing things
you can do with RILL. ;)

And extend your script infinitely, e.g.:

cat example_input.txt | python3 -c 'import rill
import codecs
def caesar(text):
    return str(codecs.encode(text, "rot_13"))
rill.inp().grep("rill").map_lines(caesar).show()'

Output:

gur guevyyvat guvatf
lbh pna qb jvgu evyy. ;)

At this point, it probably makes sense to move your code into a file and use it like a normal Python script.

python3 my_script.py example_input.txt

Requirements and Installation

pip install rill

Or, if you like to use the latest version from this repository:

git clone https://github.com/Dobiasd/rill
cd rill
pip install .

License

Distributed under the MIT License. (See accompanying file LICENSE or at https://opensource.org/licenses/MIT)

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

rill-0.1.2.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

rill-0.1.2-py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 3

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