Skip to main content

High-performance digit counting library for integers, floats, and Decimal values 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.4.tar.gz (16.6 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.4-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: digit_counter-1.0.4.tar.gz
  • Upload date:
  • Size: 16.6 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.4.tar.gz
Algorithm Hash digest
SHA256 51912c2b91f678987a622853d8082429eb5f2a93ed4ba938935c1ea0d7ecaa91
MD5 42763ddec8207e0f6493a9ca6ebcd689
BLAKE2b-256 72d033b236c58d9f6de0e43766ac798898ed0b830e5dd7b8dfaa78f50799d9c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: digit_counter-1.0.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9d2548b3027d5de12f1e9514b8ad9f53180b8649b46c609f4a25730fc659e0a8
MD5 a2cdb68294f821247214996f9717227d
BLAKE2b-256 b4b6a678320a809cf46c35a187c0145cd227857d6a7e856f70098b6948b40caa

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