Skip to main content

Typed Python Case Insensitive Dictionary

Project description

Case Insensitive Dict

Typed Python Case Insensitive Dictionary

Publish

Python 3.7+ PyPI - License PyPI - Version

CodeQL codecov pre-commit.ci status

Imports: isort Code style: black Checked with mypy

Install

Install and update using pip.

$ pip install -U case-insensitive-dictionary

API Reference

Method Description
clear() Removes all elements from the dictionary.
copy() Returns a copy of the dictionary.
get(key, default) Returns the value (case-insensitively), of the item specified with the key.
Falls back to the default value if the specified key does not exist.
fromkeys(iterable, value) Returns a dictionary with the specified keys and the specified value.
keys() Returns the dictionary's keys.
values() Returns the dictionary's values.
items() Returns the key-value pairs.
pop(key) Remove the specified item (case-insensitively).
The value of the removed item is the return value.
popitem() Remove the last item that was inserted into the dictionary.
For Python version <3.7, popitem() removes a random item.

Example

CaseInsensitiveDict:

>>> from typing import Union

>>> from case_insensitive_dict import CaseInsensitiveDict

>>> case_insensitive_dict = CaseInsensitiveDict[Union[str, int], str](data={"Aa": "b", 1: "c"})
>>> case_insensitive_dict["aa"]
'b'
>>> case_insensitive_dict[1]
'c'

which also supports json encoding/decoding:

>>> import json

>>> from case_insensitive_dict import CaseInsensitiveDict, CaseInsensitiveDictJSONEncoder, case_insensitive_dict_json_decoder

>>> case_insensitive_dict = CaseInsensitiveDict[str, str](data={"Aa": "b"})
>>> json_string = json.dumps(obj=case_insensitive_dict, cls=CaseInsensitiveDictJSONEncoder)
>>> json_string
'{"Aa": "b"}'

>>> case_insensitive_dict = json.loads(s=json_string, object_hook=case_insensitive_dict_json_decoder)
>>> case_insensitive_dict
CaseInsensitiveDict({'Aa': 'b'})

Contributing

Contributions are welcome via pull requests.

First time setup

$ git clone git@github.com:DeveloperRSquared/case-insensitive-dict.git
$ cd case-insensitive-dict
$ poetry install
$ poetry shell

Tools including black, mypy etc. will run automatically if you install pre-commit using the instructions below

$ pre-commit install
$ pre-commit run --all-files

Running tests

$ poetry run pytest

Links

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

case-insensitive-dictionary-0.2.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file case-insensitive-dictionary-0.2.0.tar.gz.

File metadata

  • Download URL: case-insensitive-dictionary-0.2.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.11.0-1027-azure

File hashes

Hashes for case-insensitive-dictionary-0.2.0.tar.gz
Algorithm Hash digest
SHA256 73684ef78fad72b47c2d27c8aa62e1ca819f2b6ae984f5987744289e74c1fbf2
MD5 24b74c0287fdccefdf8aff3418d1c9e3
BLAKE2b-256 29b0c6dc86944a97162de0eafa402effcded4178ca64e43f2c986e07a5742912

See more details on using hashes here.

File details

Details for the file case_insensitive_dictionary-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for case_insensitive_dictionary-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b164cf3aa968633e133d617f94a4d147b1171a06415f56730748d8c3cd3104dc
MD5 69be04fed83f56ba13b41d1977bb63b9
BLAKE2b-256 896ae655aba867a30ed9429803f03d2672d29c83e74ebfd0258bb705b759990c

See more details on using hashes here.

Supported by

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