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.6
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.6.tar.gz | 7.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| deep_apply-1.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.6 kB
Release files / deep_apply-1.0.6.tar.gz
| Download URL | deep_apply-1.0.6.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
750062b7e05bd28cba57612133b0daaf1a96886a4290d0276ec504bf27602b77
|
|
BLAKE2b-256 checksum How to use checksums |
157b9976b4a05e937bbc18bf59714f87d55f88cfe54d80f78938d1ad4c920f62
|
| 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.6-py3-none-any.whl
| Download URL | deep_apply-1.0.6-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f3ed26d9ee10e7e73260978d82eb42940cc01fca9f411b1e4b646bad17c198a
|
|
BLAKE2b-256 checksum How to use checksums |
db401b5d6c78751ba3dc62dac3aefa2601325e4fcc266bfa1dbad99ae9e74980
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|