Skip to content

GCLNS/datautil-extras

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

datautil-extras

Tests Python License Type Checked Code Style Version

String encoding, slugification, and sanitization helpers. Zero dependencies — just small, composable functions for everyday text processing.

Installation

pip install datautil-extras

With dev tools:

pip install datautil-extras[dev]

Quick Start

from datautil_extras import (
    to_base32, from_base32,
    to_base62, from_base62,
    slugify,
    strip_ansi, strip_html, strip_control,
)

# Base32 encoding (no padding)
to_base32(b"hello world")
# 'NBSWY3DPEB3W64TMMQ'

from_base32("NBSWY3DPEB3W64TMMQ")
# b'hello world'

# Base62 encoding for compact integer IDs
to_base62(123456789)
# '8M0kX'

# URL-safe slugs
slugify("Hello, World! 123")
# 'hello-world-123'

# Strip ANSI escape codes from terminal output
strip_ansi("\x1b[31mError\x1b[0m: something broke")
# 'Error: something broke'

# Remove HTML tags
strip_html("<p>Hello <b>world</b></p>")
# 'Hello world'

API Reference

Encoding

to_base32(data: bytes) -> str

Encode bytes as base32 without padding.

from_base32(text: str) -> bytes

Decode a base32 string back to bytes. Padding is optional.

to_base62(num: int) -> str

Encode a non-negative integer as a base62 string (digits + letters).

from_base62(text: str) -> int

Decode a base62 string to an integer.

Slugify

slugify(text, separator="-", lowercase=True)

Convert a string into a URL-safe slug. Unicode is transliterated to ASCII.

Sanitize

strip_ansi(text: str) -> str

Remove ANSI escape sequences.

strip_html(text: str) -> str

Remove HTML tags.

strip_control(text: str) -> str

Remove ASCII control characters (except tab, newline, CR).

Development

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

pytest
mypy src/
ruff check src/ tests/

Project Structure

src/datautil_extras/
├── __init__.py     # Public API re-exports
├── encoding.py     # Base32 and base62 encoding
├── slugify.py      # URL-safe slug generation
└── sanitize.py     # String cleanup utilities

Requirements

  • Python 3.10+
  • No runtime dependencies

About

Encoding, slugification, and string sanitization utilities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages