Skip to main content

Python text operations module

Project description

python-textops provides many text operations at string level, list level or whole text level.
These operations can be chained with a ‘dotted’ or ‘piped’ notation.
Chained operations are stored into a single lazy object, they will be executed only when an input text will be provided.


To install:

pip install python-textops


The usual way to use textops is something like below. IMPORTANT : Note that textops library redefines the python bitwise OR operator ‘|’ in order to use it as a ‘pipe’ like in a Unix shell:

from textops import *

result = "an input text" | my().chained().operations()


for result_item in "an input text" | my().chained().operations():


myops = my().chained().operations()
# and later in the code, use them :
result = myops("an input text")
result = "an input text" | myops

An “input text” can be :

  • a simple string,
  • a multi-line string (one string having newlines),
  • a list of strings,
  • a strings generator,
  • a list of lists (useful when you cut lines into columns),
  • a list of dicts (useful when you parse a line).

So one can do:

>>> 'line1line2line3' | grep('2').tolist()
>>> 'line1\nline2\nline3' | grep('2').tolist()
>>> ['line1','line2','line3'] | grep('2').tolist()
>>> [['line','1'],['line','2'],['line','3']] | grep('2').tolist()
[['line', '2']]
>>> [{'line':1},{'line':'2'},{'line':3}] | grep('2').tolist()
[{'line': '2'}]


Piped then dotted notation (recommended):

>>> print 'this is an error\nthis is a warning' | grepi('error').first().upper()

You could use the pipe everywhere (internally a little less optimized, but looks like shell):

>>> print 'this is an error\nthis is a warning' | grepi('error') | first() | strop.upper()

To execute an operation directly from strings, lists or dicts with the dotted notation, you must use textops Extended types : StrExt, ListExt or DictExt:

>>> s = StrExt('this is an error\nthis is a warning')
>>> print s.grepi('error').first().upper()


Please, read documentation here :


0.2.6 (2016-04-12)

  • Improve out data path in state_pattern() op

0.2.5 (2016-04-12)

  • Add sgrep*() ops

0.2.4 (2016-03-23)

  • Add dostrip() op
  • Improve sed() op

0.2.3 (2016-03-17)

  • Add wcount*() ops

0.2.2 (2016-02-16)

  • cut and cutre now accept maxsplit parameter

0.2.1 (2016-02-16)

  • add aggregate() list operation

0.2.0 (2015-12-16)

  • Better repr display in ipython

0.1.9 (2015-12-15)

  • Add eformat
  • Add context dict parameter for format and render operations

0.1.8 (2015-12-10)

  • Add less(), skess() list operations
  • Add parse_smart() parser

0.1.7 (2015-11-26)

  • Add some operations
  • perf tunning

0.1.3 (2015-11-20)

  • Tune many things
  • All is now documented

0.1.2 (2015-11-04)

  • More docs and doctests

0.1.1 (2015-11-04)

First working package

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for python-textops, version 0.2.6
Filename, size File type Python version Upload date Hashes
Filename, size python-textops-0.2.6.tar.gz (71.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page