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.
  • 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.
  • normalize_kanji_variants: Replace Japanese glyph variants using the bundled MJSU 1.2.0 table.
  • parse_japanese_name: Split Japanese personal names into family, middle, and given names with structured warnings.
  • 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 and com-name-cleaner commands.

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, parse_japanese_name, 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"
name = parse_japanese_name("遠洋 インド マグロ子")
# JapaneseName(family_name='遠洋', middle_names=('インド',), given_name='マグロ子', ...)

# 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 parse-japanese-name "遠洋 インド マグロ子"
smith parse-japanese-name --tsv --header < names.txt
smith parse-japanese-name "山田/海/太郎" --delimiter / --tsv
smith unicode-names "Aあ"
smith classify-file input.pdf
smith positive-gaussian-samples 3 --mean 5 --approx-upper-bound 10
smith com-name-cleaner '㈱ 例示用工房'
com-name-cleaner --csv organizations.csv --column 会社名

Directory Structure

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

License

The Python code is licensed under the MIT License. The bundled MJSU replacement data is distributed under CC BY-SA 2.1 Japan. See the data attribution and provenance.

Metadata

Release files for smith-utils 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smith-utils 2.1.0
File Size Uploaded Provenance Actions
smith_utils-2.1.0.tar.gz 126.8 kB With provenance Details for smith_utils-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for smith-utils 2.1.0
File Interpreter ABI Platform Actions
smith_utils-2.1.0-py3-none-any.whl Python 3 none any Details for smith_utils-2.1.0-py3-none-any.whl

Total release size: 251.8 kB

Release files / smith_utils-2.1.0.tar.gz

Download URL smith_utils-2.1.0.tar.gz
Size 126.8 kB
Tags Source
SHA-256 checksum
How to use checksums
54f1b2405424de56a4c4f1414120e5b3fad5f8b8f4826250f2fa540da0674ce5
BLAKE2b-256 checksum
How to use checksums
33f0dd4e337815e7f03a3b332b8bdba6ec8a003df049d939d25d546a492dff4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / smith_utils-2.1.0-py3-none-any.whl

Download URL smith_utils-2.1.0-py3-none-any.whl
Size 125.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b288fdd1412d542c5711d0da1f383a88e6613d6c53f32abc21a3808331fa0a19
BLAKE2b-256 checksum
How to use checksums
3846a57a878691eee17a74718fb2de0c41bd55ceaada4a3e4f4614b28e5a15d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for smith-utils 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for smith_utils-2.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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