Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Deep Replacer

Given a list, set, tuple or dictionary as data input, loop through the data and replace all values that are not a list, set, tuple or dictionary using a replace function.

NOTE: THIS PROJECT WAS REPLACED WITH https://github.com/zaironjacobs/deep-apply.

How to use

Basic example

from deep_replacer import DeepReplacer

replacer = DeepReplacer()


def my_replace_func(value: str):
    """Return value to upper case"""

    return value.upper()


data = [
    {
        "name": "John Doe",
        "hobbies": {
            "sport": ["football", "tennis"],
            "music": ["singing", "guitar", "piano"],
        },
    }
]
data_replaced = replacer.replace(data=data, replace_func=my_replace_func)

print(data_replaced)

Output:

[
  {
    "name": "JOHN DOE",
    "hobbies": {
      "sport": [
        "FOOTBALL",
        "TENNIS"
      ],
      "music": [
        "SINGING",
        "GUITAR",
        "PIANO"
      ]
    }
  }
]

Example using key_depth_rules argument

from deep_replacer import DeepReplacer
from deep_replacer import key_depth_rules

replacer = DeepReplacer()


def my_replace_func(value: str):
    """Return value to upper case"""

    return value.upper()


data = [
    {
        "name": "John Doe",
        "hobbies": {
            "sport": ["football", "tennis"],
            "music": ["singing", "guitar", "piano"],
        },
    }
]
data_replaced = replacer.replace(
    data=data,
    replace_func=my_replace_func,
    key_depth_rules={"hobbies:sport": [key_depth_rules.IGNORE]},  # Ignore key at depth 'hobbies:sport'
)

print(data_replaced)

Output:

[
  {
    "name": "JOHN DOE",
    "hobbies": {
      "sport": [
        "football",
        "tennis"
      ],
      "music": [
        "SINGING",
        "GUITAR",
        "PIANO"
      ]
    }
  }
]

Metadata

Release files for deep-replacer 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deep-replacer 0.0.6
File Size Uploaded
deep_replacer-0.0.6.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for deep-replacer 0.0.6
File Interpreter ABI Platform
deep_replacer-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / deep_replacer-0.0.6.tar.gz

Download URL deep_replacer-0.0.6.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a73d2d1b0bae790dc8611f019e9660119007769fd1ce8b24bc4bb6c050027e85
BLAKE2b-256 checksum
How to use checksums
c441bae0ac29bf2b1f81130eae03fa9a001ea071257b0aab570c643245d3d709
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21

Release files / deep_replacer-0.0.6-py3-none-any.whl

Download URL deep_replacer-0.0.6-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
946a131edf89595695e919e2b4f366f2c284b259c9df799956fb1725277696b8
BLAKE2b-256 checksum
How to use checksums
84776aaf4ae8b223676bd1e1d2e66fd5193d3050fb1bd5fc2d99a8a6185f8686
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page