Skip to main content

chars-counter

A Python utility that counts, per ASCII category, how many characters appear exactly once in a given string. Works as both a CLI tool and an importable library.

Requires Python ≥ 3.14


Installation

pip install chars-counter
uv add chars-counter

CLI usage

Run the module directly with python -m chars_counter.

Count characters in a string

python -m chars_counter --string "Hello"
# Counter({<ASCIICharCategories.Lowercase_Letters: 'lowercase_letters'>: 2, <ASCIICharCategories.Uppercase_Letters: 'uppercase_letters'>: 1})

H appears once → 1 uppercase. e and o each appear once → 2 lowercase. l appears twice → ignored.

Count characters from a file

python -m chars_counter --file path/to/file.txt

Help

python -m chars_counter --help

Typo suggestions

Mistyped flags are caught and the closest valid flag is suggested:

python -m chars_counter --flie notes.txt
# --flie cannot be used, maybe you meant: --file

Library usage

Basic example

from chars_counter import get_once_seen_chars_categories_count, ASCIICharCategories

result = get_once_seen_chars_categories_count("Hello")
# Counter({<ASCIICharCategories.Lowercase_Letters: 'lowercase_letters'>: 2,
#          <ASCIICharCategories.Uppercase_Letters: 'uppercase_letters'>: 1})

result[ASCIICharCategories.Lowercase_Letters]  # 2
result[ASCIICharCategories.Uppercase_Letters]  # 1

Iterating over results

from chars_counter import get_once_seen_chars_categories_count

result = get_once_seen_chars_categories_count("aA1")

for category, count in result.items():
    print(f"{category}: {count}")
# lowercase_letters: 1
# uppercase_letters: 1
# digits: 1

Empty / all-duplicate strings

Strings where every character appears more than once return an empty dict:

get_once_seen_chars_categories_count("aabb")  # Counter()
get_once_seen_chars_categories_count("")      # Counter()

Handling non-ASCII input

Passing a string that contains non-ASCII characters raises NotAsciiCharacterProvidedError:

from chars_counter import get_once_seen_chars_categories_count
from chars_counter.not_ascii_character_provided_error import NotAsciiCharacterProvidedError

try:
    get_once_seen_chars_categories_count("café")
except NotAsciiCharacterProvidedError as e:
    print(e.char)      # 'é'
    print(e.position)  # 3
    print(e)           # Non-ASCII character 'é' found at position 3.

ASCII character categories

Category Code points Examples
Control_Characters 0–31, 127 \t, \n
Space 32
Punctuation 33–47, 58–64, 91–96, 123–126 !, ., @
Digits 48–57 0–9
Uppercase_Letters 65–90 A–Z
Lowercase_Letters 97–122 a–z

Public API reference

get_once_seen_chars_categories_count(string: str) -> dict[ASCIICharCategories, int]

Returns a Counter mapping each ASCIICharCategories member to the number of characters in that category that appear exactly once in string. Categories with no once-seen characters are omitted.

Results are cached (lru_cache, capacity 1000).

Raises NotAsciiCharacterProvidedError if string contains any non-ASCII character.

ASCIICharCategories

A StrEnum with members: Control_Characters, Space, Punctuation, Digits, Uppercase_Letters, Lowercase_Letters.

Each member's string value is its snake_case name (e.g. ASCIICharCategories.Lowercase_Letters == "lowercase_letters").

NotAsciiCharacterProvidedError

Inherits from Exception. Attributes:

  • char: str — the offending character
  • position: int — its index in the input string

Development

uv sync
uv run pytest
uv run coverage run -m pytest && uv run coverage report
uv run ruff format 
uv run ruff check --fix
uv run pyright

Metadata

Release files for chars-counter 0.4.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 chars-counter 0.4.0
File Size Uploaded Provenance Actions
chars_counter-0.4.0.tar.gz 4.0 kB Without provenance Details for chars_counter-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chars-counter 0.4.0
File Interpreter ABI Platform Actions
chars_counter-0.4.0-py3-none-any.whl Python 3 none any Details for chars_counter-0.4.0-py3-none-any.whl

Total release size: 9.9 kB

Release files / chars_counter-0.4.0.tar.gz

Download URL chars_counter-0.4.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d2dfa6bc2e4d3977704150fa2ed122bd81f0077b406009c95845ac7b6e2e776e
BLAKE2b-256 checksum
How to use checksums
2ef7ca0e4489e4ace7be928a136c1fbdfb89007979ca551833fd262e3df84630
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"20.1","id":"ulyssa","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / chars_counter-0.4.0-py3-none-any.whl

Download URL chars_counter-0.4.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f68cda037bb48aee30fbcc16bcf8cf75b038ab5133e962ee4ecee629c5b75841
BLAKE2b-256 checksum
How to use checksums
9fbae2911320633a4c1ba3f42e1dd62e21c2dee0615408f81c310fd2895c7478
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"20.1","id":"ulyssa","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for chars-counter 0.4.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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