smith-utils
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.dateobjects, orNone(returns today) into adateobject.parse_strict_date: Strict parsing forYYYYMMDDorYYYY-MM-DDformats, 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.sample_positive_gaussian: Generate Gaussian samples truncated to positive values up to an approximate upper bound.
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 aResult.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, andfile(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, sample_positive_gaussian
# Datetime
date = ensure_date("20231225") # datetime.date(2023, 12, 25)
# Numeric
value = parse_numeric_value("(1,250.50)") # -1250.5
samples = sample_positive_gaussian(mean=5.0, approx_upper_bound=10.0, trial_number=3)
# approx_upper_bound is treated as mean + 3 * sigma and as a truncation bound.
# 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
smith positive-gaussian-samples 3 --mean 5 --approx-upper-bound 10
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smith_utils-0.5.0.tar.gz.
File metadata
- Download URL: smith_utils-0.5.0.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99b9cceb1879582b97310aedf8630d7c9ff88385e1709f585b6639327bb5bf19
|
|
| MD5 |
2bb8b4549b7eef9a5d396096aecb89af
|
|
| BLAKE2b-256 |
f663405faf259403176575e7e7e06cadaa37e196621f7b57a515e230c2ea5af3
|
Provenance
The following attestation bundles were made for smith_utils-0.5.0.tar.gz:
Publisher:
pypi.yml on yeiichi/smith-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smith_utils-0.5.0.tar.gz -
Subject digest:
99b9cceb1879582b97310aedf8630d7c9ff88385e1709f585b6639327bb5bf19 - Sigstore transparency entry: 2298511213
- Sigstore integration time:
-
Permalink:
yeiichi/smith-utils@3597debe36e0e6fa3861828a7dd24aebc1de66a5 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/yeiichi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@3597debe36e0e6fa3861828a7dd24aebc1de66a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file smith_utils-0.5.0-py3-none-any.whl.
File metadata
- Download URL: smith_utils-0.5.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a88169d1f7b34ce5d40c50e51dedac69d00bffd1312629bd7fcd45924b0ba908
|
|
| MD5 |
e8bdb8ee395d2280140e457d96310d0b
|
|
| BLAKE2b-256 |
ea51335cfdfec8281da9b7864b3ed48bfadaf54696dbc50e65895cd188ae6a8d
|
Provenance
The following attestation bundles were made for smith_utils-0.5.0-py3-none-any.whl:
Publisher:
pypi.yml on yeiichi/smith-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smith_utils-0.5.0-py3-none-any.whl -
Subject digest:
a88169d1f7b34ce5d40c50e51dedac69d00bffd1312629bd7fcd45924b0ba908 - Sigstore transparency entry: 2298511282
- Sigstore integration time:
-
Permalink:
yeiichi/smith-utils@3597debe36e0e6fa3861828a7dd24aebc1de66a5 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/yeiichi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@3597debe36e0e6fa3861828a7dd24aebc1de66a5 -
Trigger Event:
push
-
Statement type: