A Python Benedict extension to include fuzzy logic for matching keys (using keypaths)
Project description
FuzzBenedict
A Python Benedict extension to include fuzzy logic for matching keys (using keypaths)
Installation
pip install fuzzbenedict
Usage
from fuzzbenedict import FuzzBenedict
data = {
"person": {
"name": "John Doe",
"address": {
"city": "New York",
"zipcode": 10001
}
}
}
fb = FuzzBenedict(data)
print(fb.fuzzy_get("pers.name")) # Test fuzzy match
You can also set a custom threshold for the fuzzy matching:
fb = FuzzBenedict(data, threshold=90)
print(fb.fuzzy_get("pers.name")) # Test fuzzy match
Or adjust the threshold at runtime:
fb = FuzzBenedict(data)
fb.threshold=90
print(fb.fuzzy_get("pers.name")) # Test fuzzy match
And set a default factory if the key is not found/matched:
fb = FuzzBenedict(data, default_factory=lambda: None)
print(fb.fuzzy_get("pers.name")) # Test fuzzy match
You can also adjust the behavior of the class:
FuzzBenedict.Config.fuzzy_in_getitem = True
print(fb["pers.name"])
License
MIT
Author
Christophe Druet - christophe@stoachup.com
Copyright
Copyright (c) 2024 Stoachup SRL - All rights reserved.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ez_fuzzbenedict-0.1.0.tar.gz
(5.0 kB
view details)
File details
Details for the file ez_fuzzbenedict-0.1.0.tar.gz.
File metadata
- Download URL: ez_fuzzbenedict-0.1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be8557d53f674815b061bb79fba16678b95d3dcfbae339506006e05bc0f4aada
|
|
| MD5 |
38009904af9b599d82281a977d6d9bca
|
|
| BLAKE2b-256 |
aedf6412fd946653772f827da1d82f103c257eff044ef8398fd345d385ecb904
|