Skip to main content

smith-utils

PyPI version Python versions Status License Tests Documentation Status

Smith Utils is a central hub for data cleaning and parsing scripts. This package consolidates distributed utility functions to improve code reuse and maintenance efficiency across all yeiichi projects.

Key Features

Datetime Utilities (smith_utils.datetime)

Robust date parsing and formatting.

  • ensure_date: Flexible conversion of strings, datetime.date objects, or None (returns today) into a date object.
  • parse_strict_date: Strict parsing for YYYYMMDD or YYYY-MM-DD formats, rejecting ambiguous inputs.
  • format_ordinal: Converts integers to ordinal strings (e.g., 1"1st", 22"22nd").

Numeric Refinement (smith_utils.numeric)

Clean and parse messy numeric data.

  • parse_numeric_value: Handles custom separators, decimals, and negative formats like (1,234.56).
  • parse_currency_value: Alias for numeric parsing, specifically for currency strings.

Text Normalization & Metrics (smith_utils.text)

Standardize text and compare string similarity.

  • normalize_text: Unicode NFKC normalization, case folding, and whitespace handling.
  • random_string: Generate random ASCII, kanji, or mixed strings using secure randomness.
  • StringDistance: Implementation of Damerau-Levenshtein and Jaro-Winkler algorithms for fuzzy matching.
  • analyze_pair: Convenience function for string comparison returning a Result.
  • Relation / Result: Relation enum and typed result for text comparisons.
  • make_unicode_char_name_records: Extract Unicode codepoint/name metadata from text.
  • normalize_newlines_stream: Stream-based newline normalization to LF with newline type detection.
  • normalize_file_to_lf: File-based newline normalization helper.

Crypto Hash Utilities (smith_utils.crypto)

Calculate SHA-256 digests for text and files.

  • get_text_digest: Returns the SHA-256 hexadecimal digest for a text string.
  • get_file_digest: Returns the SHA-256 hexadecimal digest for a file using streaming reads.

File Classification Utilities (smith_utils.file)

Classify files from multiple evidence sources.

  • classify_file: Returns extension, MIME, magic-number, and file(1) classification evidence.
  • FileClassification: Dataclass result containing raw signals, file_class, and derived categories.

Installation

Install via pip:

pip install smith-utils

This also installs the smith command.

Quick Start

from smith_utils import ensure_date, get_text_digest, parse_numeric_value, normalize_text, random_string
from smith_utils import make_unicode_char_name_records
from smith_utils import classify_file, get_file_digest, normalize_file_to_lf

# Datetime
date = ensure_date("20231225") # datetime.date(2023, 12, 25)

# Numeric
value = parse_numeric_value("(1,250.50)") # -1250.5

# Text
clean_text = normalize_text("  Smith  Utils  ") # "smith utils"

# Random strings
token = random_string(16)

# Unicode metadata
records = make_unicode_char_name_records("Aあ")
# [UnicodeCharNameRecord(index=0, codepoint='U+0041', ...), ...]

# Normalize a file's newlines to LF
summary = normalize_file_to_lf("input.txt", "output.txt")
# {'newline_type': 'CRLF', 'bytes_in': ..., 'bytes_out': ...}

# SHA-256 digests
text_digest = get_text_digest("smith-utils")
file_digest = get_file_digest("input.txt")

# File classification
classification = classify_file("input.pdf")
# FileClassification(extension='.pdf', file_class='document', categories=('document', 'pdf'), ...)

CLI

smith random-string 16
smith digest --text "smith-utils"
smith digest input.txt
smith normalize-text "  Smith  Utils  "
smith unicode-names "Aあ"
smith classify-file input.pdf

Directory Structure

  • src/smith_utils/: Main package source.
  • legacy/: Legacy scripts and templates (not included in distribution).
  • tests/: Comprehensive test suite.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Download files

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

Source Distribution

smith_utils-0.4.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

smith_utils-0.4.1-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file smith_utils-0.4.1.tar.gz.

File metadata

  • Download URL: smith_utils-0.4.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for smith_utils-0.4.1.tar.gz
Algorithm Hash digest
SHA256 59a96a3abce2ca1caae0e874dbcfc8be69aa9d9136d229918b7229135058fcc7
MD5 9591a570c3257648e7a179f2ae733d52
BLAKE2b-256 2ebbbfcb85cc4c5ce0702712adf87c6e0f8cdcefd5dba0b60f1331a2865c1e1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for smith_utils-0.4.1.tar.gz:

Publisher: pypi.yml on yeiichi/smith-utils

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

File details

Details for the file smith_utils-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: smith_utils-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for smith_utils-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2bbd688d16b86a77b31f482b775d76ad83c39a3ca53b01bead054265ed41f030
MD5 c7cd62118e55d22134834b9d4bf6ac38
BLAKE2b-256 467fdf04168544b4cc067d3435f72782d6a096e3be5ebdce5e4d100b3fed4935

See more details on using hashes here.

Provenance

The following attestation bundles were made for smith_utils-0.4.1-py3-none-any.whl:

Publisher: pypi.yml on yeiichi/smith-utils

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

Release history Release notifications | RSS feed

0.5.0

2 files

This release

0.4.1 This release

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page