Skip to main content

Getting started

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.

Install

To install:

pip install python-textops

Overview

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()

or

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

or

myops = my().chained().operations()
# and later in the code, use them :
result = myops("an input text")
or
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()
['line1line2line3']
>>> 'line1\nline2\nline3' | grep('2').tolist()
['line2']
>>> ['line1','line2','line3'] | grep('2').tolist()
['line2']
>>> [['line','1'],['line','2'],['line','3']] | grep('2').tolist()
[['line', '2']]
>>> [{'line':1},{'line':'2'},{'line':3}] | grep('2').tolist()
[{'line': '2'}]

Examples

Piped then dotted notation (recommended):

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

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()
THIS IS AN ERROR

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()
THIS IS AN ERROR

Documentation

Please, read documentation here :

News

0.3.6 (2019-010-01)

  • add separators argument to parse_smart()

0.3.5 (2019-09-25)

  • add key_filter argument to parse_smart()

0.3.4 (2018-05-25)

  • add since() and until()

0.3.3 (2018-02-23)

  • Fix get_attribute_or_textop()

0.3.2 (2017-06-18)

  • DebugText class fixed

0.3.1 (2017-04-05)

  • Fixed bug when have empty string as piped input string

0.3.0 (2017-03-23)

  • add fileops and runops

0.2.14 (2017-02-28)

  • sed() and sedi() now accept list of patterns to search and list of replacement strings

0.2.12 (2017-02-27)

  • add tofile() and teefile()

0.2.11 (2017-01-31)

  • Remove version limitation over sphinx package in setup.py

0.2.10 (2017-01-26)

  • added textops.extend_type

0.2.9 (2016-12-06)

  • Fix autostrip in state_pattern() when no groupdict

  • add __continue__ for goto _state in state_pattern()

  • parsek* and keyval now can parse list of strings

0.2.8 (2016-11-02)

  • fix MySQLdb does not support UnicodeExt

  • callable attribute starting with ‘_’ will not be extended anymore

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

Metadata

Release files for python-textops 0.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-textops 0.3.6
File Size Uploaded Provenance Actions
python-textops-0.3.6.tar.gz 76.8 kB Without provenance Details for python-textops-0.3.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-textops 0.3.6
File Interpreter ABI Platform Actions
python_textops-0.3.6-py2-none-any.whl Python 2 none any Details for python_textops-0.3.6-py2-none-any.whl

Total release size: 131.8 kB

Release files / python-textops-0.3.6.tar.gz

Download URL python-textops-0.3.6.tar.gz
Size 76.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c35d2e518bf12b556490bf7ba8a2eca80bd843c954feb1bf25f0357822b02197
BLAKE2b-256 checksum
How to use checksums
de7eb0b84a7a93fb842252da7c68bcc79903a913f7b91071829a60d271a0d456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.15+

Release files / python_textops-0.3.6-py2-none-any.whl

Download URL python_textops-0.3.6-py2-none-any.whl
Size 55.0 kB
Tags Python 2
SHA-256 checksum
How to use checksums
065337f0b04c3df3598114bdf609cdf24eb5b9697a0da75f94e212fd4c92a267
BLAKE2b-256 checksum
How to use checksums
c8e04220b868ae39d95728d2f366f5e7a3e88319a01e1ce18c519c4f62a0cb0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.15+

Security for python-textops 0.3.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page