Skip to main content

Library for building UNIX-style pipelines in Python

Project description

Wrensh

Wrensh is a library that allows you to process data in Python using UNIX / POSIX shell idioms.

Currently it only supports interactive or batch processing of text in-memory. The goal is to provide a range of modes that allow you to do almost anything that is quick and intuitive to shell users, but in Python environments.

Using Wrensh

Install it:

pip install wrensh

Import it:

from wrensh import text

And go:

text.cat("input.csv").grep(",active,").sort().uniq().append("output.csv")

Starting Pipelines

Each of the following options returns a new pipeline.

From in-memory data:

data = """key,value
key1,value1
key2,value2
"""

sh = text.echo(data.split("\n"))
# OR
sh = text.echo("A string to test a regex command")

From a file:

sh = text.cat("data.csv")

Processing Pipelines

You can use many POSIX commands on your pipelines:

sh.grep("a Python regular expression") # Filters out records that match the reg

sh.head()  # Passes at most the first 10 records
sh.head(2) # Passes at most the first 2 records
sh.tail()  # Passes at most the last 10 records
sh.head(2) # Passes at most the last 2 records

sh.sort() # Sorts the records
sh.uniq() # Deduplicates the records

And you can use higher-order functions:

sh.map(lambda x: x.upper()) # The lambda is called once for each record, and can return None to
                            # ignore it, or it can return a record, or a list of records

Ending Pipelines

Each of the following functions can be used at the end of your pipeline.

Create a file and write the pipeline's contents:

sh.redirect("output.csv") # Create or truncate the file
sh.append("output.csv") # Create or append to the file

You can also get the output as a string:

str(pipe)

Or access the raw list of strings used interally:

sh.pipe

Future Work

Ideas for future work include:

  • negative numbers to tail and head
  • additional POSIX tools (awk, cut, expand, unexpand, tr, sed, curl
  • additional higher order functions (filter, apply)
  • maybe support for binary formats: zipping, conversions
  • streaming
  • multiprocessing

Please submit an issue (or pull request) if you have feedback or input.

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

wrensh-0.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

wrensh-0.0.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file wrensh-0.0.1.tar.gz.

File metadata

  • Download URL: wrensh-0.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.3

File hashes

Hashes for wrensh-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4b3db8f9db8db793ebda2e17fd0c3f14b614b4f1d2c32db39c0bbe05359258fe
MD5 32e4ffd84c8d8dda52492c237f1ecffd
BLAKE2b-256 40989e218622a9051f0eede36b39de42e9fead4f295a9d795716a43924039b08

See more details on using hashes here.

File details

Details for the file wrensh-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: wrensh-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.3

File hashes

Hashes for wrensh-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33ad79557602b89e14c39a5185a775a2bd56a923992329fc9cd54173b6eddeca
MD5 b35a60afd2a5dd20663091e782fd4ca6
BLAKE2b-256 00f64f14f870b167ad6c7328afb60c18dae0e42fe620aa6405bd60c75c68e601

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