Skip to main content

pymastring

pymastring is a high-performance utility package that globally overrides the runtime behavior of Python's built-in primitive str class via deep C-level monkey-patching. It breaks standard type limitations to allow direct mathematical calculations, matrix equations, bitwise interactions, universal cross-type comparisons, and custom serialization paradigms natively on raw string literals.


Technical Concept

Python's built-in str instances are hardcoded at the C-API level to prevent arbitrary mutation. pymastring bypasses this defense mechanism by temporarily modifying PyTypeObject.tp_flags and overwriting underlying C-slots (tp_as_number, tp_as_sequence, tp_as_mapping, tp_richcompare, tp_iter) via ctypes and garbage collector referent dictionaries.

Every mathematical operation maps characters to their respective Unicode Code Points (via 32-bit UCS-4 memory buffers), runs numerical adjustments, applies an auto-overflow modulo bounds-check (% 1114112), and decodes resulting buffers back into strings.

Performance & Memory Acceleration

pymastring includes a zero-dependency C-level buffer engine utilizing Python's native array('I') with utf-32-le encoding/decoding. If numpy is installed in the system environment, pymastring automatically harnesses processor SIMD vector operations for instant array computation.

pymastring provides total interoperability across all native Python types: numbers (int, float, bool), collections (list, tuple, set, dict, bytes), and custom third-party objects.


Installation

Install pymastring directly from PyPI:

pip install pymastring

Or install the package locally from source in editable development mode:

pip install .

Core Features & Extended API Specification

1. Universal Vectorized Arithmetic Engine (+, -, *, /, //, %, **)

Standard string literals can be manipulated mathematically with numbers, strings, booleans, collections, and sequences across left-hand and right-hand operations.

  • Addition (+ / radd): Integer/float/bool addition shifts character unicode codes forward ("abc" + 1 -> "bcd", "abc" + True -> "bcd"). Standard string concatenation ("a" + "b") is retained.
  • Subtraction (- / rsub): Subtraction by a number reduces unicode codes ("python" - 5). Subtraction by another string removes target substring bytes ("abcdef" - "bd" -> "acef"). Subtraction from numbers (1000 - "a") computes reverse shifts.
  • Multiplication (* / rmul): String-by-integer multiplication performs classic repetition ("a" * 3). String-by-float scales codes. String-by-string evaluates element-wise Hadamard multiplication.
  • Division (/, //, %, divmod): Performs exact truediv, floordiv, and modulo on character weights. Supports right-hand division (200 / "a", 200 // "a") and native divmod("abc", 2).
  • Exponentiation (** / rpow): Exponentiates internal character weights ("abc" ** 2 or 2 ** "a").
import pymastring

print("abc" + 1)            # Outputs: "bcd"
print(1 + "abc")            # Right-hand addition -> Outputs: "bcd"
print("abc" + True)         # Bool scalar shift -> Outputs: "bcd"
print("python" - 5)         # Left-shifts unicode positions
print("abcdef" - "bd")      # Drops target slices -> Outputs: "acef"
print("abc" ** 2)           # Exponentiates character codes
print(2 ** "a")             # Right-hand exponentiation
print("xyz" / 2)            # Uniform code points scaling
print(200 / "a")            # Right-hand division
print(divmod("a", 10))      # Returns tuple of (floordiv, modulo)

2. Stream Encryption & XOR Cipher Capability (^)

Combining element-wise bitwise operations enables single-line Vernam / Stream encryption directly on raw strings without manual loops or zip() iterations.

import pymastring

message = "secret_payload"
key = "super_key_12345"

# Encrypt in a single line
encrypted = message ^ key
print(encrypted)            # Outputs encrypted unicode characters

# Decrypt back
decrypted = encrypted ^ key
print(decrypted)            # Outputs: "secret_payload"

3. Matrix Cross-Multiplication Vector Behavior (@)

Using the @ operator evaluates the structural linear algebra dot product between two string arrays or between strings and numeric vectors (list, tuple).

import pymastring

# String-by-string dot product: (ord('a') * ord('b')) -> 97 * 98
print("a" @ "b")            # Outputs integer: 9506

# String-by-vector dot product: (97*1 + 98*2 + 99*3)
print("abc" @ [1, 2, 3])    # Outputs integer: 590

4. Cross-Type Rich Comparisons (>, <, >=, <=, ==, !=)

Rich comparison algorithms evaluate recursive integrated inner array vector weight sums (_get_weight), allowing seamless comparisons between strings, numbers, nested lists, dicts, and custom objects.

import pymastring

print("aaa" > 1)            # Compares 291 > 1 -> Outputs: True
print(100 < "aaa")          # Compares 100 < 291 -> Outputs: True
print("aaa" == 291)         # Weight equality -> Outputs: True
print("abc" > [1, 2, 3])    # Compares string weight vs list weight -> Outputs: True
print("abc" > None)         # Compares string weight vs None weight -> Outputs: True

5. Dynamic Structural Weight Evaluation & Element Extraction (len(), str[i])

The global len() invocation evaluates context dynamically. Standard raw string literals retain traditional element counts. However, iterated elements, indexed characters (pymastring.MathChar("a")), or MathChar objects compute and report the integrated unicode code point weight (ord()).

import pymastring

# A primitive baseline string keeps its classic character length
print(len("abc"))           # Outputs integer: 3

# MathChar objects report true inner weight sum
char = pymastring.MathChar("a")
print(len(char))            # Outputs Unicode weight: 97

# Intercept loops pull typified MathChar wrappers
for char in "a":
    print(len(char))        # Outputs Unicode weight: 97

6. Unary Operators & Transparent Casting (-str, ~str, abs(), int(), float(), round())

  • Unary Negation (-): Reverses the string (-"abc" -> "cba").
  • Bitwise NOT (~): Inverts character bit positions (~"abc").
  • Vector Norm (abs()): Calculates Euclidean vector magnitude ($\sqrt{\sum \text{ord}(c)^2}$).
  • Transparent Casting (int(), float(), round()): Safely parses valid numeric text or falls back to total character weight sums for non-numeric strings via metaclass-enabled numeric types.
import pymastring

print(-"abc")               # Reverses string -> Outputs: "cba"
print(abs("abc"))           # Calculates Euclidean vector length -> ~169.75
print(int("123"))           # Parses valid integer -> 123
print(int("abc"))           # Fallback sum of weights -> 97 + 98 + 99 = 294
print(float("123.45"))      # Parses float -> 123.45
print(float("abc"))         # Fallback sum of weights -> 294.0

7. Bitwise Vector Conversions (<<, >>, &, |, ^)

Direct byte-level array transformations across registers supporting left-hand and right-hand operations.

import pymastring

print("abc" << 2)           # Left shift bit positions
print("secret" ^ 42)        # XOR encryption mask mapping
print("hello" & "world")     # Matrix intersection overlay
print(15 & "a")             # Right-hand bitwise AND

8. Typified Generator Array Extraction & Reversal

Loops and reversed iterators parsing raw string sequences yield operational wrappers (MathChar) inheriting full mathematical capabilities.

import pymastring

for char in reversed("xyz"):
    print(char ** 1.5)

9. Custom JSON Serialization Engine (MathJSONEncoder)

To prevent internal character objects from breaking standard data transfers, use our targeted serialization mapping profile.

import json
import pymastring

data = {"payload": "abc" ** 2}
json_string = json.dumps(data, cls=pymastring.MathJSONEncoder)

License

MIT License - Copyright (c) 2026 ProgVM

Download files

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

Source Distribution

pymastring-1.1.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

pymastring-1.1.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file pymastring-1.1.0.tar.gz.

File metadata

  • Download URL: pymastring-1.1.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pymastring-1.1.0.tar.gz
Algorithm Hash digest
SHA256 de5ca96e71c68ae047b667eae5346b40f2f917a88580c1fbd1380d22e696deb4
MD5 d5d30c691d86447a4c68906bdc1bf62d
BLAKE2b-256 57ee2987de50756ab29f7c2c2a21e31b42838bb8753e02902fab74b03ec2d061

See more details on using hashes here.

File details

Details for the file pymastring-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pymastring-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pymastring-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a26a4a7d1566034badb6229624f12132de9c2aff7ee513cca467c66dbb270d6b
MD5 49736315beabfe97691dabbaa4e7328d
BLAKE2b-256 bba47b16e7df67543bb085c6fb1373035380a4108af0bb2dd9cc8d49cd9d72a7

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 Sentry Error logging StatusPage Status page