Skip to main content

Utility data structures with simple but powerful features.

Project description

DictKit

A Python package that provides utility data structures with simple but powerful features, with a focus on flexibility and user experience.

UtilDict

A feature-enriched dictionary.

  • Access items with dot notation.
  • Flexible subscripting:
    • Get multiple items at once.
    • Set multiple items or the same value to multiple items at once.
  • Add items without mutating - return an updated copy
  • Drop items without mutating - return a filtered copy
  • Accept a variety of positional argument types at creation, such as other dictionaries, 2-column dataframes, series, or other iterables

Examples

from dictkit import UtilDict

# Initialize UtilDict with a variety of types
ud = UtilDict({"a": 1}, [("b", 2)], c=3)
print(ud)  # {'a': 1, 'b': 2, 'c': 3}

# Dot notation access
print(ud.a)  # 1

# Get multiple items at once
selected_items = ud[["a", "c"]]
print(selected_items)  # {'a': 1, 'c': 3}

# Set multiple items at once
ud[["a", "c"]] = 10, 30
print(ud)  # {'a': 10, 'b': 2, 'c': 30}

# Set the same value to multiple keys at once
ud[["a", "c"]] = 99
print(ud)  # {'a': 99, 'b': 2, 'c': 99}

# Add items from a variety of types
ud2 = ud.add({"c": 3}, ("d", 4), e=5)
print(ud2)  # {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}

# Add items from a 2-column dataframe
import pandas as pd
ud = UtilDict(a=1, b=2)
df = pd.DataFrame({"key": ["c", "d"], "value": [3, 4]})
ud2 = ud.add(df)
print(ud2)  # {'a': 1, 'b': 2, 'c': 3, 'd': 4}

# Drop multiple items at once
>>> ud3 = ud2.drop("a", "c")
>>> print(ud3)  # {'b': 2, 'd': 4}

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

dictkit-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

dictkit-0.1.1-py2.py3-none-any.whl (4.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dictkit-0.1.1.tar.gz.

File metadata

  • Download URL: dictkit-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for dictkit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fa3ab1112fdd91ebede84b5732bc8d42f91150444503af0357b6166976318352
MD5 3dc195f6cc16f26d29e2c8832e8a35e0
BLAKE2b-256 737c340f1015bdf3227e8140d89150d9cddf87f6bfc7c1ce0c6bf9c96911559b

See more details on using hashes here.

Provenance

File details

Details for the file dictkit-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: dictkit-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for dictkit-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4ad72542d1a9399853ee8e37700129a3a73a58cd9aa539e5f721d480fd001685
MD5 9d94fd510df4e1f81a092e026b098839
BLAKE2b-256 32ca684ce90aa9cfccd8a2aaa1a8b72940bb18630923d2ee1d8d37c89821a1a0

See more details on using hashes here.

Provenance

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