Deep Apply
Deep traverse through an object and apply a function on its values.
Supports the following object types:
- Dictionaries
- Lists
- Sets
- Tuples
- Pydantic models
Install
pip install deep-apply
Usage
Apply upper() on values
import deep_apply
# 1. Create your callback function.
def to_upper(value, **kwargs):
"""
To uppercase.
"""
# Other arguments passed to the callback function:
# key: str = kwargs["key"]
# depth_level: int = kwargs["depth_level"]
# depth_key: str = kwargs["depth_key"]
# Apply upper() and return the value
if isinstance(value, str):
return value.upper()
# Always return the unedited value
return value
# 2. Your data.
data = [
{
"id": "pZnZMffPCpJx",
"name": "John Doe",
"hobbies": {
"sport": ["football", "tennis"],
"music": ["singing", "guitar", "piano"],
},
}
]
# 3. Run apply().
data = deep_apply.apply(data=data, func=to_upper)
[
{
'id': 'PZNZMFFPCPJX',
'name': 'JOHN DOE',
'hobbies': {
'sport': ['FOOTBALL', 'TENNIS'],
'music': ['SINGING', 'GUITAR', 'PIANO']
}
}
]
Metadata
Release files for deep-apply 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| deep_apply-1.0.7.tar.gz | 7.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| deep_apply-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.8 kB
Release files / deep_apply-1.0.7.tar.gz
| Download URL | deep_apply-1.0.7.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28b8a59909cc31eb60895dc7b66d27061b29f8d3b8c40ad5d5446796818e10c0
|
|
BLAKE2b-256 checksum How to use checksums |
23fcc90b82bd28f17b0ff7edc998961349e281039ef7ce4a709dc2c277e0f128
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / deep_apply-1.0.7-py3-none-any.whl
| Download URL | deep_apply-1.0.7-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76b0f1acdac62f8c789047810eccd328befac8966690cc72782b1d94ebc5128e
|
|
BLAKE2b-256 checksum How to use checksums |
8ef8eb21bdd3c5a8b6abbe882f6a3d809d01ef84c6b99e43fe2c08f26770d15f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|