Skip to main content

Snaptext

Snaptext is a Python package that provides tools for manipulating strings while retaining source positions in the resulting object.

Installation

$ pip install snaptext

Usage

Indexing, concatenation and stripping

from snaptext import Source

source = Source("123 / 456")

source[0:4].area.format()
# =>
# 123 / 456
# ^^^^

source[0:4].strip().area.format()
# =>
# 123 / 456
# ^^^

(source[0:3] + source[-3:]).area.format()
# =>
# 123 / 456
# ^^^   ^^^

Regular expression matching

text = Source("Pi is about 3.1415.")
match = text.transform_match(text.search(r"(\d+)\.(\d+)"))

match.group().area.format()
# =>
# Pi is about 3.1415.
#             ^^^^^^

match.group(2).area.format()
# =>
# Pi is about 3.1415.
#               ^^^^

Regular expression substitution

text = Source("The sum of 3.02 and 12.8 is 15.82")

result = text.sub(r"(\d+)\.(\d+)", r"\1,\2")
# => 'The sum of 3,02 and 12,8 is 15,82'

result.area.format()
# =>
# The sum of 3.02 and 12.8 is 15.82
# ^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^ ^^

Example: JSON parser

from snaptext.json import loads

result = loads("""
{
  "a": "x",
  "b": [13, 14, 15],
  "c": true
}
""")

result.value['b'].value[1].area.format()
# =>
#    "b": [13, 14, 15],
#              ^^

Metadata

Release files for snaptext 0.1.1

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

Source distribution (sdist)

Source distribution for snaptext 0.1.1
File Size Uploaded Provenance Actions
snaptext-0.1.1.tar.gz 7.5 kB Without provenance Details for snaptext-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for snaptext 0.1.1
File Interpreter ABI Platform Actions
snaptext-0.1.1-py3-none-any.whl Python 3 none any Details for snaptext-0.1.1-py3-none-any.whl

Total release size: 15.4 kB

Release files / snaptext-0.1.1.tar.gz

Download URL snaptext-0.1.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4747e114a5e490920043c65a0ecb2f2ddbb60efbb7fcea5a98b4ad712203c3c0
BLAKE2b-256 checksum
How to use checksums
da2a8b13cbddc1017ebae56ffa9a1afef358099d1aeea246ae0792e54184b198
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / snaptext-0.1.1-py3-none-any.whl

Download URL snaptext-0.1.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eeb0a6349fc5d68311d2b3dd294d5681821532c7f3ffd4c376eb514d076bdec9
BLAKE2b-256 checksum
How to use checksums
3e67c8e96f6b7438ab1be048156c6e680e17beb8bc031a8654ce2a2ce7952140
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Security for snaptext 0.1.1

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.1.1 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