Skip to main content

Bidirectionally transformed strings

Project description

PyPI version

The bistring library provides non-destructive versions of common string processing operations like normalization, case folding, and find/replace. Each bistring remembers the original string, and how its substrings map to substrings of the modified version.

For example:

>>> from bistring import bistr
>>> s = bistr('๐•ฟ๐–๐–Š ๐––๐–š๐–Ž๐–ˆ๐–, ๐–‡๐–—๐–”๐–œ๐–“ ๐ŸฆŠ ๐–๐–š๐–’๐–•๐–˜ ๐–”๐–›๐–Š๐–— ๐–™๐–๐–Š ๐–‘๐–†๐–Ÿ๐–ž ๐Ÿถ')
>>> s = s.normalize('NFKD')     # Unicode normalization
>>> s = s.casefold()            # Case-insensitivity
>>> s = s.replace('๐ŸฆŠ', 'fox')  # Replace emoji with text
>>> s = s.replace('๐Ÿถ', 'dog')
>>> s = s.sub(r'[^\w\s]+', '')  # Strip everything but letters and spaces
>>> s = s[:19]                  # Extract a substring
>>> s.modified                  # The modified substring, after changes
'the quick brown fox'
>>> s.original                  # The original substring, before changes
'๐•ฟ๐–๐–Š ๐––๐–š๐–Ž๐–ˆ๐–, ๐–‡๐–—๐–”๐–œ๐–“ ๐ŸฆŠ'

This allows you to perform very aggressive text processing completely invisibly.

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

bistring-0.4.0.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

bistring-0.4.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file bistring-0.4.0.tar.gz.

File metadata

  • Download URL: bistring-0.4.0.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for bistring-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a7bc8d123958b343677942e7fbc41b67e5cdb432c91852cbcff851a3430e43d8
MD5 d72f9cee1333953e3a06ab3192f7474d
BLAKE2b-256 b19a87d8ccce6cbfb3434e9c4a58a14060716dc040177e4162d2c7cc2ada5ce2

See more details on using hashes here.

File details

Details for the file bistring-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: bistring-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for bistring-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d8a723d905b9f921992203872b07b2ac96845791f979ca145cee2a67b4f497
MD5 7db0488ae6e620309bc094ff033a3bb1
BLAKE2b-256 817f2a8f3a5d82a6c096440ef3d35835576ac73c77e519e86252ee01f5c344dd

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