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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file magiccionary-0.1.4.tar.gz.
File metadata
- Download URL: magiccionary-0.1.4.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f04511cf4380d24e95fbe95c628dd2592c2b0c9accde5a9157ea49263d1b42a
|
|
| MD5 |
3cb327de9c558750c372c53d4dd51aa7
|
|
| BLAKE2b-256 |
c64c595665333de784ecf11ebe6384d1d50a35c4314c8e8ba821669cf4a5703f
|
File details
Details for the file magiccionary-0.1.4-py3-none-any.whl.
File metadata
- Download URL: magiccionary-0.1.4-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d589381a48ef46a800b76ecb29ecb8dbf6fccf0b066dc363deb88306650ad0d
|
|
| MD5 |
ae139d9a0d21e9b0d82b849582d6783d
|
|
| BLAKE2b-256 |
014cadd0e0a9778775dd2fbcea33d880a0587e53af41b18835f5d8d94708d302
|