Registry / serialization / morphys

morphys

JSON →
library1.0pypypi✓ verified 33d ago

Morphys is a Python library (version 1.0) designed for smart and common conversions between Unicode (Python `str`) and bytes types. It aims to simplify handling character encodings, offering a consistent interface for these essential text processing operations. While available on PyPI, specific details about its ongoing development or release cadence are not publicly detailed beyond its initial release in 2018.

serialization
Install & Compatibility
Where this runs
tested against v1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from morphys import StrMorpher
from morphys import ensure_bytes
from morphys import ensure_unicode

This quickstart demonstrates the core functionality of `morphys`: converting between Python's Unicode `str` type and `bytes`. It shows encoding a string to bytes and then decoding the bytes back to a string, using the common `utf-8` encoding. It also includes an example of handling bytes that might not conform to the expected encoding, illustrating common error handling strategies (assuming `morphys` wraps standard Python encoding/decoding with similar `errors` parameters).

from morphys import to_unicode, to_bytes # Example 1: Convert a Unicode string to bytes unicode_string = "Hello, world! 👋" encoded_bytes = to_bytes(unicode_string, encoding="utf-8") print(f"Unicode string: {unicode_string}") print(f"Encoded bytes: {encoded_bytes}") # Example 2: Convert bytes back to a Unicode string decoded_string = to_unicode(encoded_bytes, encoding="utf-8") print(f"Decoded string: {decoded_string}") # Example 3: Handling potential non-UTF8 characters (assuming default error handling) # If 'morphys' has smart handling, it might try other encodings or use 'replace'/'ignore' # This example still explicitly uses UTF-8 and shows a common issue if characters are not valid try: latin1_bytes = b'caf\xe9' print(f"\nAttempting to decode latin1 bytes: {latin1_bytes}") decoded_from_latin1 = to_unicode(latin1_bytes, encoding="utf-8", errors="strict") print(f"Decoded with strict UTF-8: {decoded_from_latin1}") except UnicodeDecodeError as e: print(f"Error decoding with strict UTF-8 (expected): {e}") # Using 'replace' error handling for robustness decoded_from_latin1_safe = to_unicode(latin1_bytes, encoding="utf-8", errors="replace") print(f"Decoded with UTF-8 (replace errors): {decoded_from_latin1_safe}")
Debug
Known footguns
gotchaThe `morphys` library (version 1.0) appears to be minimally maintained since its 2018 release. While functional, it might not receive updates for newer Python versions or complex encoding scenarios.
gotchaMisunderstanding string vs. bytes in Python is a common source of `TypeError` or `UnicodeDecodeError`/`UnicodeEncodeError`. Always be explicit about the type you're working with and the expected encoding.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
11 hits · last 30 days
gptbot
4
ahrefsbot
3
amazonbot
3
script
1
Resources