Skip to main content

High-performance digit counting library for integers and floating numbers with precision control.

Project description

digit-counter

digit-counter is a high-performance Python package designed to compute digit statistics from integers, floats, strings, and Decimal values. It provides a unified API, batch-processing utilities, precision control, caching for performance optimization, logging capabilities, and optional CLI support.

This package is suitable for data processing pipelines, numeric analysis utilities, logging systems, and any application requiring accurate and efficient digit computation.


Key Features

  • Unified interface for counting digits across integers, floats, strings, and Decimal types
  • High-performance implementations with LRU caching
  • Precision-controlled handling of floating-point and decimal values
  • Batch processing with detailed reporting
  • Strong error handling and input validation
  • Optional logging support
  • Optional command-line interface
  • Lightweight, production-ready implementation

Installation

Stable release:

pip install digit-counter

Quick Usage Example

from digit_counter import DigitCounter

# Initialize with optional precision
counter = DigitCounter(precision=20)

result = counter.count_digits(123.456, mode="all")

print("Total digits:", result.total_digits)
print("Digits before decimal:", result.before_decimal)
print("Digits after decimal:", result.after_decimal)

Counting Modes

Mode Description
total Returns total digits excluding sign
before Returns digits before the decimal point
after Returns digits after the decimal point (trailing zeros trimmed)
all Returns a full metadata object (DigitCountResult)

Batch Processing

values = [123, 90.45, -77.002, 100.00]

counter = DigitCounter()
batch = counter.batch_process(values, mode="all")

# Access the full list of results
print(batch.results)

# Summary of performance and processing details
print(batch.summary())

Example summary output:

Processed: 4 items  
Successful: 4  
Failed: 0  
Success Rate: 100%  
Average Processing Time: 0.09 ms  

Command-Line Usage (optional if CLI is enabled)

Count digits of a single number:

digit-counter count 123.456

Specify a mode:

digit-counter count 123.456 --mode before

Batch process from a file:

digit-counter batch input.txt --output results.json

Display runtime statistics:

digit-counter stats

Help command:

digit-counter --help

Logging

counter = DigitCounter(log_level="DEBUG")
counter.count_digits(987.654)

Logging supports DEBUG, INFO, WARNING, ERROR, and CRITICAL levels.


Performance Considerations

The package utilizes:

  • Optimized integer digit counting without string conversion
  • Decimal-aware float parsing
  • LRU caching for repeated values
  • Linear-time batch processing
  • Precision control to reduce unnecessary computation

This design allows the library to scale from small datasets up to large numeric collections while maintaining predictable performance characteristics.


Exception Handling

The library provides clear exceptions for:

  • Unsupported data types
  • Precision errors
  • Non-numeric strings
  • Invalid mode selection

All exceptions include contextual details to speed up debugging.


License

This project is licensed under the MIT License. Refer to the LICENSE file for full terms.


Contributing

Contributions are welcome. If you intend to submit pull requests, please follow standard coding style practices and ensure all changes include appropriate test coverage.


Project details


Download files

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

Source Distribution

digit_counter-1.0.3.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

digit_counter-1.0.3-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file digit_counter-1.0.3.tar.gz.

File metadata

  • Download URL: digit_counter-1.0.3.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for digit_counter-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b05cbc7ebbf0d20d951201ab05c3e2f0117c45678f9f5272a9568a84de36c86b
MD5 5911053ac622a8b234d32d37259b2e0e
BLAKE2b-256 1bae31e7e56c4e82de6c482b3af87ba5e1bb1b8fad0e7d053a2b0a09109f8093

See more details on using hashes here.

File details

Details for the file digit_counter-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: digit_counter-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for digit_counter-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9b5a9386956022b66db39fa0cef5d1ac9407ea2681082eb143dba90031a22808
MD5 c5a4c19ebf5889fa5b1cf6cdc29eea92
BLAKE2b-256 670d73891ae8f8e08cc6d7a6be020560556ef6714f1f6f88b29783fccc1295c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page