Skip to main content

schleppy

Utilities for traversing and transforming data structures

Inspired by Hapi framework for .js (especially the Hoek plugin), I really missed some of these utilities in python so decided to port them over.

reach(source, pattern, [options])

Insipred by Hoek.reach

Converts an object key chain string to reference

  • options - optional settings

    • separator - string to split chain path on, defaults to ‘.’

    • default - value to return if the path or value is not present, default is None

    • strict - if true, will throw an error on missing member, default is False

A pattern including negative numbers will work like negative indices on an array.

If pattern is False-y, the object itself will be returned.

from schleppy import reach

pattern = 'a.b.c'
source_obj = {'a' : {'b' : { 'c' : 1}}}

reach(source_obj, pattern) # returns 1

pattern = 'a.b.-1'
source_obj = {'a' : {'b' : [2,3,6]}}

reach(source_obj, pattern) # returns 6

transform(source, transform, [options])

Insipred by Hoek.transform

Transforms an existing object into a new one based on the supplied obj and transform map. options are the same as the reach options. The first argument can also be an array of objects. In that case the method will return an array of transformed objects. Note that options.separator will be respected for the keys in the transform object as well as values.

from schleppy import transform

source = {
    'address': {
        'one': '123 main street',
        'two': 'PO Box 1234'
    },
    'title': 'Warehouse',
    'state': 'CA'
}

result = transform(source, {
    'person.address.lineOne': 'address.one',
    'person.address.lineTwo': 'address.two',
    'title': 'title',
    'person.address.region': 'state'
})
# Results in
# {
#     'person': {
#         'address': {
#             'lineOne': '123 main street',
#             'lineTwo': 'PO Box 1234',
#             'region': 'CA'
#         }
#     },
#     'title': 'Warehouse'
# }

Metadata

Release files for schleppy 1.1.22

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

Source distribution (sdist)

Source distribution for schleppy 1.1.22
File Size Uploaded Provenance Actions
schleppy-1.1.22.tar.gz 3.7 kB Without provenance Details for schleppy-1.1.22.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for schleppy 1.1.22
File Interpreter ABI Platform Actions
schleppy-1.1.22-py3-none-any.whl Python 3 none any Details for schleppy-1.1.22-py3-none-any.whl

Total release size: 9.0 kB

Release files / schleppy-1.1.22.tar.gz

Download URL schleppy-1.1.22.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
566edecf1abe51bb880036dc276a0d1da8576e312715c26b685e2aa95fc0c9f7
BLAKE2b-256 checksum
How to use checksums
7f5213fa2603ff1e38fd33efd4668984a73b72b4122c925a340419aa718ca3e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.26.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.3

Release files / schleppy-1.1.22-py3-none-any.whl

Download URL schleppy-1.1.22-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d8dbac7cd518bf60c7fbbdf12ed9eeaea44d54e897217591eb813243dd45870
BLAKE2b-256 checksum
How to use checksums
7d69a11c9f19b9ab4ba00903c9679ec0af80e661eec8cd09b68b6707a700517c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.26.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.3

Security for schleppy 1.1.22

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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