Skip to main content

Caseless data type container implementations for Python.

Project description

Caselessly

The caselessly library provides several case-less container data type implementations:

  • a dict subclass that allows for case-insensitive comparison of its string keys
  • a list subclass that allows for case-insensitive comparison of its string items
  • a set subclass that allows for case-insensitive comparison of its string items
  • a tuple subclass that allows for case-insensitive comparison of its string items

Requirements

The Caselessly library has been tested with Python 3.10, 3.11, 3.12 and 3.13. The library is not compatible with Python 3.9 or earlier.

Installation

The Caselessly library is available from PyPI, so may be added to a project's dependencies via its requirements.txt file or similar by referencing the Caselessly library's name, caselessly, or the library may be installed directly into your local runtime environment using pip via the pip install command by entering the following into your shell:

$ pip install caselessly

Example Usage

To use the Caselessly library, import the library and the data type or data types you need and use them just like their regular counterparts, with the knowledge that they support setting and getting values without regard to the casing of any string keys:

Caseless Dictionary

from caselessly import caselessdict

data = caselessdict({"a": 1, "B": 2}, c=3)

assert isinstance(data, caselessdict)
assert isinstance(data, dict)

assert len(data) == 3

assert data == {"A": 1, "B": 2, "c": 3}
assert data == {"a": 1, "b": 2, "c": 3}
assert data == {"a": 1, "B": 2, "c": 3}
assert data == {"A": 1, "b": 2, "C": 3}

Caseless List

from caselessly import caselesslist

data: list[str] = ["A", "B", "c", "D", "e", "f"]

assert isinstance(data, list)
assert len(data) == 6

assert "A" in data
assert "B" in data
assert not "C" in data

data = caselesslist(data)

assert isinstance(data, list)
assert isinstance(data, caselesslist)
assert len(data) == 6

assert "A" in data
assert "B" in data
assert "C" in data  # note that "C" does not exist in the list but "c" does
assert "D" in data
assert "E" in data  # note that "E" does not exist in the list but "e" does
assert "f" in data  # note that "f" does not exist in the list but "f" does

Caseless Set

from caselessly import caselessdict

data = caselessdict({"a": 1, "B": 2}, c=3)

assert isinstance(data, caselessdict)
assert isinstance(data, dict)

assert len(data) == 3

assert data == {"A": 1, "B": 2, "c": 3}
assert data == {"a": 1, "b": 2, "c": 3}
assert data == {"a": 1, "B": 2, "c": 3}
assert data == {"A": 1, "b": 2, "C": 3}

Caseless Tuple

from caselessly import caselesstuple

data = tuple(["A", "B", "c", "D", "E", "f"])

assert "A" in data
assert "B" in data
assert not "C" in data

data = caselesstuple(data)

assert "A" in data
assert "B" in data
assert "C" in data  # note that "C" does not exist in the list but "c" does
assert "D" in data
assert "E" in data
assert "F" in data  # note that "F" does not exist in the list but "f" does

Classes & Methods

The Caselessly library provides the following data type subclasses and each class offers a shorthand alias that prefixes the superclass' name with ci to denote that the class is its case-insensitive variant. The aliases can be used interchangeably with the fully qualified class names as they are direct aliases rather than further subclasses.

Subclass Superclass Subclass Alias
caselessdict dict cidict
caselesslist list cilist
caselessset set ciset
caselesstuple tuple cituple

The Caselessly library classes can be used interchangeably with their superclasses where one needs the ability to place items into and retrieve items from the containers without regard to case sensitivity. The classes offer all the usual functionality that their superclasses offer, and all the usual methods and interactions are available.

Unit Tests

The Caselessly library includes a suite of comprehensive unit tests which ensure that the library functionality operates as expected. The unit tests were developed with and are run via pytest.

To ensure that the unit tests are run within a predictable runtime environment where all of the necessary dependencies are available, a Docker image is created within which the tests are run. To run the unit tests, ensure Docker and Docker Compose is installed, and perform the following commands, which will build the Docker image via docker compose build and then run the tests via docker compose run – the output of running the tests will be displayed:

$ docker compose build
$ docker compose run tests

To run the unit tests with optional command line arguments being passed to pytest, append the relevant arguments to the docker compose run tests command, as follows, for example passing -vv to enable verbose output:

$ docker compose run tests -vv

See the documentation for PyTest regarding available optional command line arguments.

Copyright & License Information

Copyright © 2025 Daniel Sissman; licensed under the MIT License.

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

caselessly-1.0.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

caselessly-1.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file caselessly-1.0.0.tar.gz.

File metadata

  • Download URL: caselessly-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for caselessly-1.0.0.tar.gz
Algorithm Hash digest
SHA256 425ab12f2d46a42883923b22fd7a6325a70a92e5677af746d7f399d059c3d29c
MD5 e053193727758ccfa1caf8da389aa882
BLAKE2b-256 34313a91698675ac0e6359c0c44abf580edc541985417eeb6f3e1ffd3fc8eedf

See more details on using hashes here.

Provenance

The following attestation bundles were made for caselessly-1.0.0.tar.gz:

Publisher: python-publish.yml on bluebinary/caselessly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file caselessly-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: caselessly-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for caselessly-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a69dab795cfd668035c89e8725e21af96a06f5fa0ee61d9e7408fb78dc59abc
MD5 5c7b8e0ebbe66b6a986ff2ac3310660b
BLAKE2b-256 a0fe8bd6e2d07568301f25965688ab5969e0a90df71891a4c1c299da92258c65

See more details on using hashes here.

Provenance

The following attestation bundles were made for caselessly-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on bluebinary/caselessly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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