Skip to main content

A Universal String Encoder

Project description

Universal String Encoder

Tests Documentation Coverage PyPI version Python Versions License: MIT Code style: ruff

A universal string encoder CLI tool and Python library for encoding/decoding strings in various formats.

Check out the official documentation

Features

  • 🚀 Simple CLI - Encode/decode from stdin or files
  • 🔌 Extensible - Easy to add new encoders
  • 🎯 Flexible - Support for custom character sets
  • 📦 Lightweight - No heavy dependencies
  • 🧪 Well-tested - Comprehensive test suite with snapshot testing

Install

usenc is available on PyPi.

Install the CLI automatically

pipx install usenc

Or with traditional pip (in a virtual env)

pip install usenc

Quick Example

CLI

# Get help and parameters
usenc --help
usenc <encoder> --help
# Encode a string
echo "hello world" | usenc url
# Output: hello%20world

# Decode
echo "hello%20world" | usenc url -d
# Output: hello world

# File input/output
usenc url -i input.txt -o output.txt

# More complex encoding
echo "hello world" | usenc hex --prefix '${' --suffix '}' --lowercase
# Output: ${68}${65}${6c}${6c}${6f}${20}${77}${6f}${72}${6c}${64}

# Optional character selection
echo "hello world" | usenc cstring --include e
# Output: h\x65llo\x20world

Python

from usenc import encode, decode

# Encode
encoded = encode(b'hello world', encoder='url')
print(encoded)  # hello%20world

# Decode
decoded = decode(encoded, encoder='url')
print(decoded)  # hello world

Available Encoders

  • base16 - Standard Base16 encoding (RFC 4648)
  • base32 - Standard Base32 encoding (RFC 4648)
  • base64 - Standard Base64 encoding (RFC 4648)
  • cstring - C string escaping
  • doubleurl - Double URL encoding (RFC 3986 percent encoding)
  • hash - Base hash encoder using python hashlib
  • hex - Hexadecimal string encoding
  • html - HTML Entities encoding
  • md5 - MD5 hash encoding
  • sha1 - SHA-1 hash encoding
  • sha256 - SHA-256 hash encoding
  • unicode - Unicode escapes encoding
  • url - Standard URL encoding (RFC 3986 percent encoding)

Optional Encoding

Some encoders provide the option to select which characters should be encoded (e.g. url or cstring). Those have a default setting that can be augmented with --include some_chars and --exclude some_chars.

Advanced users can specify directly --regex match_chars that will override these parameters.

Global Parameters

The bulk (-bor --bulk) parameter makes the encoder process the whole file instead of line by line. This mode can be useful for encoders like base64 or md5.

For some encoders, the way the input bytes and output bytes are interpreted into strings matter. You can use parameters --input-charset and --output-charset to set the charsets used by the encoder. They both default to utf8 which should be fine in most situations.

echo héllo | usenc url --output-charset utf8
> h%C3%A9llo
echo héllo | usenc url --output-charset latin1
> h%E9llo
echo h%E9llo | usenc url -d --input-charset latin1
> héllo

Development

See the Contributing Guide and How to add an encoder

License

MIT License - see LICENSE file for details.

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

usenc-1.0.0.tar.gz (113.5 kB view details)

Uploaded Source

Built Distribution

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

usenc-1.0.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file usenc-1.0.0.tar.gz.

File metadata

  • Download URL: usenc-1.0.0.tar.gz
  • Upload date:
  • Size: 113.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for usenc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fc7cfb899a79e968fa6d99b8be271e8db7fd74c8bab0717d9bb79c4d9a35b801
MD5 7d2f1decfed01c970e694596e4934207
BLAKE2b-256 3451641e1ce3d722abf9621b8ef7b245e5b70823582742a54f1da8d2b046ad55

See more details on using hashes here.

Provenance

The following attestation bundles were made for usenc-1.0.0.tar.gz:

Publisher: publish.yml on crashoz/usenc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usenc-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: usenc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for usenc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7361723bf58175e2f6cdefbcf4340f7fe730f003c769ebfa416971a11ede6373
MD5 1bb1fac895e6042a6bdfaa0f56478d35
BLAKE2b-256 635bf890a0f983bd5b562ad8b7ff3684d61542a4c7c2cb6bdf82079d6573ca0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for usenc-1.0.0-py3-none-any.whl:

Publisher: publish.yml on crashoz/usenc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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