Simple text-stream processing functionality
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file rill-0.1.2.tar.gz
.
File metadata
- Download URL: rill-0.1.2.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.27.1 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 167cb816141afedd08e2ec81fa334ce278d824ecd88776c7024a802479cf1fcc |
|
MD5 | b6e05a9831c9af3c96e11fc603617044 |
|
BLAKE2b-256 | 6e5cc66551e64b9173890f697222d02f41a87ca67d2c6967a464a6d5d3b51e19 |
File details
Details for the file rill-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: rill-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.27.1 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ebc90228304ba3ed4a50a57101f7243518e492695b928e619421193cccd6acf |
|
MD5 | 4cd81dbed62deab57fc59e747a74f0d3 |
|
BLAKE2b-256 | 98b53866515945259377c6a70feab8a26de07e5a8d0e4537186ddc6d75d6956a |