Skip to main content
https://img.shields.io/pypi/v/plucky.svg https://img.shields.io/pypi/l/plucky.svg https://img.shields.io/pypi/wheel/plucky.svg https://img.shields.io/pypi/pyversions/plucky.svg https://api.travis-ci.org/randomir/plucky.svg?branch=master

plucky.pluckable happily wraps any Python object and allows for chained soft plucking with attribute- and item- getters (e.g. .attr, ["key"], [idx], [::2], or a combination: ["key1", "key2"], and [0, 3:7, ::-1]; even: ["length", 0:5, 7]).

plucky.pluck will allow you to pluck same as with pluckable (regarding the plucking operations), but accepting a string selector instead of a Python expression.

plucky.plucks enables you to safely extract several-levels deep values by using a concise string selector comprised of dictionary-like keys and list-like indices/slices. Stands for pluck simplified, since it supports only a subset of pluck syntax. It’s simpler and a more efficient.

plucky.merge facilitates recursive merging of two data structures, reducing leaf values with the provided binary operator.

Installation

plucky is available as a zero-dependency Python package. Install with:

$ pip install plucky

Usage

from plucky import pluck, plucks, pluckable, merge

pluckable(obj).users[2:5, 10:15].name["first", "middle"].value

pluck(obj, 'users[2:5, 10:15].name["first", "middle"]')

plucks(obj, 'users.2:5.name.first')

merge({"x": 1, "y": 0}, {"x": 2})

Examples

obj = {
    'users': [{
        'uid': 1234,
        'name': {
            'first': 'John',
            'last': 'Smith',
        }
    }, {
        'uid': 2345,
        'name': {
            'last': 'Bono'
        }
    }, {
        'uid': 3456
    }]
}

plucks(obj, 'users.1.name')
# -> {'last': 'Bono'}

plucks(obj, 'users.name.last')
# -> ['Smith', 'Bono']

plucks(obj, 'users.*.name.first')
# -> ['John']

pluckable(obj).users.name.first.value
# -> ['John']

pluckable(obj).users.uid[0, 2, 1].value
# -> [1234, 3456, 2345]

pluckable([datetime.datetime.now(), None, {'month': 8}])[::2].month
# -> [5, 8]

pluckable(obj, skipmissing=False, default='Unnamed').users.name.first.value
# -> ['John', 'Unnamed', 'Unnamed']

More Examples! :)

pluckable(obj).users[:, ::-1].name.last.value
# -> ['Smith', 'Bono', 'Bono', 'Smith']

pluckable(obj).users[:, ::-1].name.last[0, -1].value
# -> ['Smith', 'Smith']

pluck(obj, 'users[:, ::-1].name.last[0, -1]')
# -> ['Smith', 'Smith']

plucks([1, {'val': 2}, 3], 'val')
# -> [2]

plucks([1, {'val': [1,2,3]}, 3], '1.val.-1')
# -> 3

merge({"x": 1, "y": 0}, {"x": 2})
# -> {"x": 3, "y": 0}

merge({"a": [1, 2], "b": [1, 2]}, {"a": [3, 4], "b": [3]})
# -> {"a": [4, 6], "b": [1, 2, 3]}

Metadata

Release files for plucky 0.4.3

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

Source distribution (sdist)

Source distribution for plucky 0.4.3
File Size Uploaded
plucky-0.4.3.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for plucky 0.4.3
File Interpreter ABI Platform
plucky-0.4.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 19.0 kB

Release files / plucky-0.4.3.tar.gz

Download URL plucky-0.4.3.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5bc75d43ae6b40f1b7ba42000b37e4934fa6bd2d6a6cd4e47461f803a404c194
BLAKE2b-256 checksum
How to use checksums
4f4ea2d3157ec7031ea3ccc313400db27b92a65a9c002396a709e7457626f7ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.5

Release files / plucky-0.4.3-py2.py3-none-any.whl

Download URL plucky-0.4.3-py2.py3-none-any.whl
Size 10.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a358878f3e45b5e51d0b4e5b5c89d704422a72c2cf8ee9aaf9acedfa53f89105
BLAKE2b-256 checksum
How to use checksums
d8707b43e7280284bafecb345f4edb3eea7042cf0d089c5d112920eda650fda5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.5

Release history Release notifications | RSS feed

This release

0.4.3 This release

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

3 release files

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