Skip to main content

A smarter Python dictionary with filtering, mapping, merging, and JSON utilities.

Project description

🧠 MindDict

A smarter Python dictionary with filtering, mapping, merging, and JSON utilities.

PyPI Python License Tests


✨ Overview

MindDict is a lightweight Python package that extends the built-in dict with practical utilities for data manipulation.
It makes your dictionaries more expressive, readable, and fun to use — all without dependencies.

💡 Ideal for:

  • data manipulation and transformation
  • JSON serialization/deserialization
  • configuration management
  • clean, functional-style programming

🚀 Installation

pip install minddict

or from TestPyPI (for development builds):

pip install -i https://test.pypi.org/simple/ minddict

🧩 Quick Start

from minddict import MindDict

data = MindDict(a=1, b=2, c=3)

# 🔍 Filter values
filtered = data.filter(lambda k, v: v > 1)
print(filtered)
# → MindDict(b=2, c=3)

# 🔄 Transform keys and values
mapped = data.map(lambda k, v: (k.upper(), v * 10))
print(mapped)
# → MindDict(A=10, B=20, C=30)

# 💾 Serialize to JSON
print(data.to_json(indent=2))
# {
#   "a": 1,
#   "b": 2,
#   "c": 3
# }

# 🧠 Invert keys and values
print(data.invert())
# → MindDict({1: 'a', 2: 'b', 3: 'c'})

⚙️ Features

Method Description
.filter(fn) Keep items where fn(key, value) is True.
.map(fn) Transform each key/value pair via fn(key, value) → (new_key, new_value).
.invert() Swap keys and values (last wins on conflicts).
.diff(other, strict=False) Compare two dicts and get differences.
.merge(other) Combine two dicts without mutating the originals.
.flatten(separator=".") Convert nested dicts into flat key paths.
.unflatten(separator=".") Rebuild nested structure from flattened keys.
.to_json(indent=0) Serialize into JSON string.
.from_json(string) Load from a JSON string.

🧪 Examples

🔹 Filtering

data = MindDict(name="Alice", age=25, city="Paris")
adults = data.filter(lambda k, v: k == "age" and v >= 18)
print(adults)
# MindDict(age=25)

🔹 Mapping

data = MindDict(x=1, y=2)
result = data.map(lambda k, v: (k.upper(), v ** 2))
# MindDict(X=1, Y=4)

🔹 Flatten & Unflatten

nested = MindDict({
    "user": {"name": "Bob", "info": {"city": "Paris", "age": 30}},
    "active": True
})

flat = nested.flatten()
# MindDict({'user.name': 'Bob', 'user.info.city': 'Paris', 'user.info.age': 30, 'active': True})

rebuilt = flat.unflatten()
# MindDict({'user': {'name': 'Bob', 'info': {'city': 'Paris', 'age': 30}}, 'active': True})

🔹 Diff & Merge

a = MindDict(a=1, b=2)
b = MindDict(b=3, c=4)

print(a.diff(b))
# MindDict({'b': (2, 3), 'c': (None, 4)})

print(a.merge(b))
# MindDict({'a': 1, 'b': 3, 'c': 4})

🧱 Project Structure

minddict/
├── minddict/
│   ├── __init__.py
│   └── core.py
├── tests/
│   └── test_core.py
├── README.md
├── LICENSE
└── pyproject.toml

🧩 Design Principles

  • Pure functional methods — never mutate the original instance
  • Always return a new MindDict
  • Clean, explicit, Pythonic code
  • Zero dependencies (only standard library)

🧰 Development

Run tests

pytest -v

Build package

python -m build

Upload to TestPyPI

python -m twine upload --repository testpypi dist/*

📜 License

MIT License Copyright © 2025


👥 Author

Maintained with ❤️ by iamsan. Contributions, issues, and feature requests are welcome on 👉 GitHub Issues


🌟 Support

If you find MindDict useful, star ⭐ the repository on GitHub and share it! Every star helps keep the project alive 🚀

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

minddict-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

minddict-0.2.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file minddict-0.2.0.tar.gz.

File metadata

  • Download URL: minddict-0.2.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for minddict-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e59b68b3c4b7341f13eb0a24192692e56ee0882f661adcba94630e43182ec7f4
MD5 f9d505a12ee914959034de54491b4f1a
BLAKE2b-256 317d3711400c5f47308656fbc89a196e10710a58d8680bb739c034f9d77c8d82

See more details on using hashes here.

File details

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

File metadata

  • Download URL: minddict-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for minddict-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cadb6b11171660d4d2fb744ea212522e3d0273c6e9004ef8b369eb8c6d1c2138
MD5 8075aae944fa6cea3d52bfc0990be3a6
BLAKE2b-256 a3acc049519eb635bf334681b92b232c620516f0ceb4541e41c1b35d51e94cf0

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