Release of Scalpl (v0.2.5) ✨🍰✨ - a lightweight wrapper for your nested dictionaries
guillaume.paulet at giome.fr
guillaume.paulet at giome.fr
Mon Jun 26 11:04:47 EDT 2017
Hi everyone !
I released a new version (0.2.5) of **Scalpl** which is available on
PyPI :)
https://github.com/ducdetronquito/scalpl
You can install it via pip:
pip3 install scalpl
Scalpl is a lightweight wrapper that helps you to operate on nested
dictionaries through the built-in dict API, by using dot-separated
string keys.
You might find it useful when working with document-oriented database
queries, REST APIs, configuration files, etc...
It's not a drop-in replacement for your dictionaries, just syntactic
sugar to avoid this['annoying']['kind']['of']['things'] and
prefer['a.different.approach'].
The benefits of Scalpl are the following:
* Faster than addict or Box.
* Allows you to use the entire dict API 'with.this.kind.of.keys'.
* Almost no instantiation/conversion cost, it's just a wrapper.
This new release (0.2.5) is just a small API improvement.
In the previous version of Scalpl, if you wanted to iterate a list of
dictionaries and and operate on it, you would have done the following:
```
data = {
'pokemons': [
{
'name': 'Bulbasaur',
'type': ['Grass', 'Poison'],
'category': 'Seed',
'ability': 'Overgrow'
},
{
'name': 'Charmander',
'type': 'Fire',
'category': 'Lizard',
'ability': 'Blaze',
},
{
'name': 'Squirtle',
'type': 'Water',
'category': 'Tiny Turtle',
'ability': 'Torrent',
}
],
'trainers': [
{
'name': 'Ash',
'hometown': 'Pallet Town'
}
]
}
proxy = Cut(data)
pokemons = proxy['pokemons']
for pokemon in Cut.all(pokemons):
pokemon.setdefault('moves.Scratch', {'power': 40})
```
Now, the API allows you to provied composite key directly to the Cut.all
method:
```
for pokemon in proxy.all('pokemons'):
pokemon.setdefault('moves.Scratch', {'power': 40})
```
Do not hesitate to give me feedbacks on the module itself, it is one of
my first public project !
Have a great afternoon :)
More information about the Python-list
mailing list