Skip to main content

Add your description here

Project description

Magiccionary

A Python utility package for powerful dictionary manipulation, allowing you to easily remove or keep specific keys in nested dictionaries.

Installation

pip install magiccionary

Features

  • Deep dictionary manipulation
  • Support for nested structures including lists and dictionaries
  • Wildcard key matching using "*"
  • List traversal using "[]" notation

Usage

Remove Keys

Remove specific keys from nested dictionaries while preserving the original structure:

from magiccionary import remove_keys

# Simple key removal
data = {"a": 1, "b": 2, "c": 3}
result = remove_keys(data, ["c"])
# result = {"a": 1, "b": 2}

# Nested key removal
data = {
    "a": {
        "b": {
            "c": 3,
        }
    },
    "d": 4,
}
result = remove_keys(data, [["a", "b", "c"]])
# result = {"a": {"b": {}}, "d": 4}

# Using wildcards and list traversal
data = {
    "a": {
        "list": [
            {"x": 1, "y": 2},
            {"x": 3, "y": 4}
        ]
    }
}
result = remove_keys(data, [["a", "list", "[]", "x"]])
# result = {"a": {"list": [{"y": 2}, {"y": 4}]}}

Keep Keys

Keep only specific keys in nested dictionaries:

from magiccionary import keep_keys

# Simple key retention
data = {"a": 1, "b": 2, "c": 3}
result = keep_keys(data, ["a", "b"])
# result = {"a": 1, "b": 2}

# Nested key retention
data = {
    "a": {
        "b": 2,
        "c": 3,
    }
}
result = keep_keys(data, [["a", "b"]])
# result = {"a": {"b": 2}}

Key Path Syntax

  • Use strings for top-level keys: ["key_name"]
  • Use arrays for nested paths: [["parent", "child", "grandchild"]]
  • Use "*" as a wildcard to match any key at that level
  • Use "[]" to traverse list elements

Features

  • Non-destructive operations (original dictionaries are not modified)
  • Support for deeply nested structures
  • Wildcard key matching
  • List traversal support
  • Type-safe operations

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

magiccionary-0.1.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

magiccionary-0.1.3-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: magiccionary-0.1.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.10

File hashes

Hashes for magiccionary-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8ffda4662c408669538c79cb5ce68f72f384b7570888c227e558787a5ed54aa9
MD5 78b5040a8d3865bd1840fa975e65adf5
BLAKE2b-256 4e349434cf07fc6a7e68413de279776f2d8c16a0797e6f40faff3b54aa04beac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magiccionary-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7aba3522eb86af6d8586dc8c04c7bcb7684749dafbbb6dea376e483ea3f5ee4f
MD5 1d37e35550f4b774d2cc1e3e39a21d58
BLAKE2b-256 33448501d3f54cbb4ab027b1d3a4fc8f9514fbde8237a083f670b8af29c7eff8

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