Skip to main content

A project that calculates unique character counts with caching

Project description

Character Occurrence Counter with Caching

This Python package calculates the number of unique characters in a given string or text file, while using caching to optimize performance for repeated calculations.

Features

  • Unique Character Counting: Identify characters that occur only once in a string or file.
  • Caching Mechanism: Uses lru_cache to speed up repeated character counting operations.
  • Command-Line Interface (CLI): Allows processing of input directly from the terminal.
  • Optimized Performance: Leverages the collections module for efficient counting.
  • Robust Testing: Comprehensive tests written with pytest to handle various edge cases and performance scenarios.
  • Coverage Reports: Ability to generate coverage reports to ensure all code is thoroughly tested.

Prerequisites

Before installing, ensure you have the following:

  • Python 3.6 or later installed.

Installation

You can install the package directly from PyPI:

pip install unique_character_counter

Usage

1. As a Module

You can import and use the module in your Python scripts as follows:

from collection.unique_char_count import get_unique_character_count

result = get_unique_character_count("abcdefg")
print(f"Number of unique characters: {result}")

2. Command-Line Interface

After installing, you can use the provided CLI commands to process strings or files:

To Process a String:

unique-counter --string "abcdefg"

To Process a File:

unique-counter --file path/to/your/file.txt

Testing

This package includes tests to ensure all features are working as expected. You can use pytest to run the tests after installation.

Important Note About Tests

Ensure that the tests folder contains an __init__.py file. This file is necessary to make tests a proper package that can be discovered by pytest during the installation process.

Run All Tests

Specify the package name to run all tests:

pytest --pyargs collection.tests

This ensures pytest can locate and run all test files included in the installed package.

Alternatively, Specify the Path to the Tests Folder:

pytest collection/tests

Generate a Coverage Report

To generate a coverage report, use the following commands:

coverage run -m pytest --pyargs collection.tests
coverage report

Ensure pytest is installed if it isn't already:

pip install pytest

Optional: Create a Virtual Environment

It is recommended to use a virtual environment to keep dependencies isolated. This step is optional but can help maintain a clean development environment.

To create a virtual environment:

python -m venv venv

Activate the virtual environment:

  • On Windows:
    venv\Scripts\activate
    
  • On macOS/Linux:
    source venv/bin/activate
    

License

This project is licensed under the MIT License. See the LICENSE file for more details.


Support

If you encounter any issues or have suggestions, please feel free to open an issue on the GitLab repository.

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

unique_character_counter-0.1.3.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

unique_character_counter-0.1.3-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file unique_character_counter-0.1.3.tar.gz.

File metadata

File hashes

Hashes for unique_character_counter-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d3df8d092c0f49f354cd81db6a3c618957a06ae8ed95598624d472c92a3555d8
MD5 e020265f6c6f25690d0f1b867fc9a52a
BLAKE2b-256 a85946819ad57d5056bbb0accff0358b596405d86fc838a4ceafaf42e1789bfa

See more details on using hashes here.

File details

Details for the file unique_character_counter-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for unique_character_counter-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 de92b47920258541f830f3f5b044956a31c01f58083f5eec00053cf710e701ef
MD5 828c10fbd485d1f0b6dc0f8e9f5f3739
BLAKE2b-256 28dfbef9ec445b55e93d167213c4585cfd148d21f6d38179f8a8011afbd84e61

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