Registry / serialization / morphys

morphys

JSON →
library1.0pypypi✓ verified 83d 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.

pip install morphys
INSTALL
IMPORT
SIG · MORPHYS
M
morphys
serializationpythonv1.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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.

StrMorpher
from morphys import StrMorpher
from morphys import to_unicode
ensure_bytes
from morphys import ensure_bytes
ensure_unicode
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 issues
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.
fix
For mission-critical applications or advanced encoding needs, consider Python's built-in `str.encode()` and `bytes.decode()` methods with explicit encoding and error handling, or more actively maintained libraries like `chardet` for robust encoding detection.
affects: 1.0
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.
fix
Ensure that `str` objects are passed to functions expecting `str` and `bytes` objects to functions expecting `bytes`. Explicitly specify `encoding` (e.g., `'utf-8'`) and `errors` (e.g., `'strict'`, `'ignore'`, `'replace'`) arguments during conversion to prevent unexpected behavior.
affects: All
Upgrade
Version history
1.0latest on PyPI · released Jan 10, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
morphys — pip install morphys · libregistry