Metadata-Version: 2.0
Name: plucky
Version: 0.3
Summary: Plucking (deep) keys/paths safely from python collections has never been easier.
Home-page: https://github.com/randomir/plucky
Author: Radomir Stevanovic
Author-email: radomir.stevanovic@gmail.com
License: MIT
Keywords: pluck itemgetter safe nested get
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules

plucky: concise deep obj.get()
==============================

``plucky.pluck`` enables you to safely extract several-levels deep values by 
using a concise selector comprised of dictionary-like keys and list-like 
indices. Slices over list items are also supported.


Installation
------------

``plucky`` is available as a Python package. Install with::

    $ pip install plucky


Usage
-----

.. code-block:: python

    from plucky import pluck

    pluck(obj, 'selector.*.path.2')


Examples
--------

.. code-block:: python

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

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

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

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


More Examples! :)
-----------------

.. code-block:: python

    pluck([1,2,3], '2')
    # -> 3

    pluck([1,2,3], '-1')
    # -> 3

    pluck([1,2,3], '*')
    # -> [1,2,3]

    pluck([1,2,3], '-2:')
    # -> [2,3]

    pluck([1,2,3], '::-1')
    # -> [3,2,1]

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

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


