Skip to main content

A syntactic patching library with char-level granularity

Project description

¶ ⠶ textum

PyPI crates.io documentation MIT/Apache-2.0 licensed pre-commit.ci status

A syntactic patching library with char-level granularity.

Installation

pip install textum

Quick Start

import textum

# Create a simple patch
patch = textum.Patch.from_literal_target(
    file="example.txt",
    needle="old text",
    mode="include",
    replacement="new text"
)

# Apply to string content
content = "This is old text in a file"
result = patch.apply_to_string(content)
print(result)  # "This is new text in a file"

# Work with multiple patches
patchset = textum.PatchSet()
patchset.add(patch)

# Apply to actual files
results = patchset.apply_to_files()

Advanced Usage

Using Snippets and Boundaries

# Create a target
target = textum.Target.literal("hello")

# Create a boundary with mode
boundary = textum.Boundary(target, "include")

# Create a snippet
snippet = textum.Snippet.at(boundary)

# Create a patch with the snippet
patch = textum.Patch(
    file="test.txt",
    snippet=snippet,
    replacement="goodbye"
)

Line-based Patching

# Delete lines 5-10
patch = textum.Patch.from_line_range(
    file="large_file.txt",
    start_line=5,
    end_line=10,
    replacement=""
)

Between Markers

# Replace content between HTML comments
start = textum.Boundary(
    textum.Target.literal("<!-- start -->"),
    "exclude"
)
end = textum.Boundary(
    textum.Target.literal("<!-- end -->"),
    "exclude"
)

snippet = textum.Snippet.between(start, end)

patch = textum.Patch(
    file="template.html",
    snippet=snippet,
    replacement="new content"
)

JSON Import/Export

# Load patches from JSON
json_data = '[{"file": "test.txt", ...}]'
patches = textum.load_patches_from_json(json_data)

# Save patches to JSON
json_str = textum.save_patches_to_json(patches)

Licensing

Textum is MIT licensed, a permissive open source license.

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

textum-0.1.1.tar.gz (87.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

textum-0.1.1-cp39-abi3-win_amd64.whl (964.0 kB view details)

Uploaded CPython 3.9+Windows x86-64

textum-0.1.1-cp39-abi3-win32.whl (905.5 kB view details)

Uploaded CPython 3.9+Windows x86

textum-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

textum-0.1.1-cp39-abi3-musllinux_1_2_i686.whl (1.3 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ i686

textum-0.1.1-cp39-abi3-musllinux_1_2_armv7l.whl (1.3 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARMv7l

textum-0.1.1-cp39-abi3-musllinux_1_2_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

textum-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

textum-0.1.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ s390x

textum-0.1.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ppc64le

textum-0.1.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (990.3 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARMv7l

textum-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (996.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

textum-0.1.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.5+ i686

textum-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (944.2 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

textum-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file textum-0.1.1.tar.gz.

File metadata

  • Download URL: textum-0.1.1.tar.gz
  • Upload date:
  • Size: 87.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.6

File hashes

Hashes for textum-0.1.1.tar.gz
Algorithm Hash digest
SHA256 42bafd9cdb9e1d48a4c30937c559f366643b50999c3989150ed6952726cb349d
MD5 244e43b3ef093bdc90450c2ed909f8ca
BLAKE2b-256 3cb3bf0ee35bb970e6f7771188ea939ad55468ecb6eca016b3bf30206804295e

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: textum-0.1.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 964.0 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.6

File hashes

Hashes for textum-0.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a6b14d33b145503ec825db6a3d4413c04d33903b548d573ab753958807cd4f7d
MD5 8340a0608e669853d2295c04df8ac4a6
BLAKE2b-256 2c2c31b948444d2e4b250ffc81adc382dd15aceaa20f0a43cdc400eebc43961e

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-win32.whl.

File metadata

  • Download URL: textum-0.1.1-cp39-abi3-win32.whl
  • Upload date:
  • Size: 905.5 kB
  • Tags: CPython 3.9+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.6

File hashes

Hashes for textum-0.1.1-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 fb2d102fc453eca43b0281893b69ba6f234e1362f9fe104161c2f6b4a2219f96
MD5 5810bc44a36aea3b1743f89c1746e556
BLAKE2b-256 c1a6102c95da0f7be6d2fc09cdd1d91d284ad4680f95590838dd7b827cea9590

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1dd391c88fd9ca6bd0f0b362df5781e9ce1c7ec845aa0d28478490ad16221a1f
MD5 b34d148113df6c80e20943d510095dbb
BLAKE2b-256 3c95fe41a33997f8e11f11533638ee9db9c722e6598b7d24a790429a5a956be2

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 28a1707b3fdbe1ab6ad6d98e449df13ad0b7fbd9b74061de9576355b75d4558d
MD5 2a73733132df69351c085b3dfe863270
BLAKE2b-256 d62f7934d13356d43bca60a7087c3659f47dc327a1570a5cd872d191116cbbfa

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 448d3f4d876a794af2922e01963932ea036ba0bd3bb20c17b206be87b8f4caf1
MD5 264fe0fdbe76cc11d33a0585bb67e03b
BLAKE2b-256 9dd51b2ce7c4827d4b6cb80deddab816d6678ef2beb64f65c29c2781c122e423

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d551ca5515fa1af0bc49bc333c6c7f25c425996eff218b22f33703b08042190e
MD5 11cc41f0355953717588671f370ca634
BLAKE2b-256 672276d5523fed2ce82a07f51d8e8c39cbd756d6bee72dccf4113dc41721a392

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bef5bdf97406372224df9e45270f536ead9d5043d8b6993c0b0d28df3654aa3c
MD5 8d23a69629662f7a2c9ec056df06d662
BLAKE2b-256 d00f777037c9043dd706c043c116417b87481a34ebadf13def921db25b1e512c

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 6a8d927e4126bff72e38a259d150c384d9a83aa238a195602ddc88298a09607c
MD5 ee30d687538d401fb7b7b86c40ce7384
BLAKE2b-256 522a1b8e3cdccdf261b6c1163408fa31990f571031e9f20515ddf1fe18732b50

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 27a9de2fbf314677431363195ac60a8f31188225f275eb0ed3e8884fac72bbcc
MD5 25ad8fd22191d108183f83d18ea7f57a
BLAKE2b-256 207341a8c7feaafc0ac3bd32dd23c807cd87e81f5b5073ce6326c2f3d16b58f1

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 6de70c3b5200b0e24430610e0de5b48e95045c3acc1fa585f20492eb848a06c1
MD5 6839890d3dacefe5bdc1c94b453da81f
BLAKE2b-256 1396ff1a75e2b0572af239330541973f0df64ff894dc193b3b06908a18419d89

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 aa9e5b955b98b207eb66cd235a394234bc97bcb48a2d10b8efd507dc88d7efd2
MD5 417b04c836a3aa8450419ae7077f1f58
BLAKE2b-256 cc2ae7f425dc0212c5c8dd73121d8f99e8fdb9c739b616142413898e66444e80

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 4fff27aa48c0fb3c41d6cc25d4fbbf7f734fcdd94982dc70e2eb867f917d3fa3
MD5 b0a980ccfd43c2943a316675f301318b
BLAKE2b-256 8be2478968e1284e92c5eb6c86ed68c582cbcc82673e95c0ec788ceead31f970

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 94965d659d9c054a0bfa5f1fcee175933afcfdec1511dba5584b06ed6b707cd2
MD5 5b7579edbdf82953ca62106c702033ba
BLAKE2b-256 429196d118fe634aa7de5d537c6ee3d831744fc1922bf4069dcae33650fff326

See more details on using hashes here.

File details

Details for the file textum-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for textum-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b7478b3fde0982315b16c293ab3ab87dbcd104a745383690d13d12005f6be09f
MD5 54a64c29e5e9652c0a1bbbb72ba04f27
BLAKE2b-256 65d12963e56e50197c7ee41426cdb5424d4541b2007065e5fd0714f1df764fa2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page