plucky


Nameplucky JSON
Version 0.4.3 PyPI version JSON
download
home_pagehttps://github.com/randomir/plucky
SummaryPlucking (deep) keys/paths safely from python collections has never been easier.
upload_time2018-09-05 06:14:27
maintainer
docs_urlNone
authorRadomir Stevanovic
requires_python
licenseMIT
keywords pluck itemgetter safe nested get
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            plucky: concise deep obj.get()
==============================

.. image:: https://img.shields.io/pypi/v/plucky.svg
    :target: https://pypi.python.org/pypi/plucky

.. image:: https://img.shields.io/pypi/l/plucky.svg
    :target: https://pypi.python.org/pypi/plucky

.. image:: https://img.shields.io/pypi/wheel/plucky.svg
    :target: https://pypi.python.org/pypi/plucky

.. image:: https://img.shields.io/pypi/pyversions/plucky.svg
    :target: https://pypi.python.org/pypi/plucky

.. image:: https://api.travis-ci.org/randomir/plucky.svg?branch=master
    :target: https://travis-ci.org/randomir/plucky


``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
-----

.. code-block:: python

    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
--------

.. code-block:: python

    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! :)
-----------------

.. code-block:: python

    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]}

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/randomir/plucky",
    "name": "plucky",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pluck itemgetter safe nested get",
    "author": "Radomir Stevanovic",
    "author_email": "radomir.stevanovic@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4f/4e/a2d3157ec7031ea3ccc313400db27b92a65a9c002396a709e7457626f7ad/plucky-0.4.3.tar.gz",
    "platform": "",
    "description": "plucky: concise deep obj.get()\n==============================\n\n.. image:: https://img.shields.io/pypi/v/plucky.svg\n    :target: https://pypi.python.org/pypi/plucky\n\n.. image:: https://img.shields.io/pypi/l/plucky.svg\n    :target: https://pypi.python.org/pypi/plucky\n\n.. image:: https://img.shields.io/pypi/wheel/plucky.svg\n    :target: https://pypi.python.org/pypi/plucky\n\n.. image:: https://img.shields.io/pypi/pyversions/plucky.svg\n    :target: https://pypi.python.org/pypi/plucky\n\n.. image:: https://api.travis-ci.org/randomir/plucky.svg?branch=master\n    :target: https://travis-ci.org/randomir/plucky\n\n\n``plucky.pluckable`` happily wraps any Python object and allows\nfor chained soft plucking with attribute- and item- getters (e.g. ``.attr``,\n``[\"key\"]``, ``[idx]``, ``[::2]``, or a combination: ``[\"key1\", \"key2\"]``,\nand ``[0, 3:7, ::-1]``; even: ``[\"length\", 0:5, 7]``).\n\n``plucky.pluck`` will allow you to pluck *same as with* ``pluckable``\n(regarding the plucking operations), but accepting a string selector\ninstead of a Python expression.\n\n``plucky.plucks`` enables you to safely extract several-levels deep values by\nusing a concise string selector comprised of dictionary-like keys and list-like\nindices/slices. Stands for *pluck simplified*, since it supports only a subset of\n``pluck`` syntax. It's simpler and a more efficient.\n\n``plucky.merge`` facilitates recursive merging of two data structures, reducing\nleaf values with the provided binary operator.\n\n\nInstallation\n------------\n\n``plucky`` is available as a **zero-dependency** Python package. Install with::\n\n    $ pip install plucky\n\n\nUsage\n-----\n\n.. code-block:: python\n\n    from plucky import pluck, plucks, pluckable, merge\n\n    pluckable(obj).users[2:5, 10:15].name[\"first\", \"middle\"].value\n\n    pluck(obj, 'users[2:5, 10:15].name[\"first\", \"middle\"]')\n\n    plucks(obj, 'users.2:5.name.first')\n\n    merge({\"x\": 1, \"y\": 0}, {\"x\": 2})\n\n\nExamples\n--------\n\n.. code-block:: python\n\n    obj = {\n        'users': [{\n            'uid': 1234,\n            'name': {\n                'first': 'John',\n                'last': 'Smith',\n            }\n        }, {\n            'uid': 2345,\n            'name': {\n                'last': 'Bono'\n            }\n        }, {\n            'uid': 3456\n        }]\n    }\n\n    plucks(obj, 'users.1.name')\n    # -> {'last': 'Bono'}\n\n    plucks(obj, 'users.name.last')\n    # -> ['Smith', 'Bono']\n\n    plucks(obj, 'users.*.name.first')\n    # -> ['John']\n\n    pluckable(obj).users.name.first.value\n    # -> ['John']\n\n    pluckable(obj).users.uid[0, 2, 1].value\n    # -> [1234, 3456, 2345]\n\n    pluckable([datetime.datetime.now(), None, {'month': 8}])[::2].month\n    # -> [5, 8]\n\n    pluckable(obj, skipmissing=False, default='Unnamed').users.name.first.value\n    # -> ['John', 'Unnamed', 'Unnamed']\n\n\nMore Examples! :)\n-----------------\n\n.. code-block:: python\n\n    pluckable(obj).users[:, ::-1].name.last.value\n    # -> ['Smith', 'Bono', 'Bono', 'Smith']\n\n    pluckable(obj).users[:, ::-1].name.last[0, -1].value\n    # -> ['Smith', 'Smith']\n\n    pluck(obj, 'users[:, ::-1].name.last[0, -1]')\n    # -> ['Smith', 'Smith']\n\n    plucks([1, {'val': 2}, 3], 'val')\n    # -> [2]\n\n    plucks([1, {'val': [1,2,3]}, 3], '1.val.-1')\n    # -> 3\n\n    merge({\"x\": 1, \"y\": 0}, {\"x\": 2})\n    # -> {\"x\": 3, \"y\": 0}\n\n    merge({\"a\": [1, 2], \"b\": [1, 2]}, {\"a\": [3, 4], \"b\": [3]})\n    # -> {\"a\": [4, 6], \"b\": [1, 2, 3]}\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Plucking (deep) keys/paths safely from python collections has never been easier.",
    "version": "0.4.3",
    "split_keywords": [
        "pluck",
        "itemgetter",
        "safe",
        "nested",
        "get"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "cbb5b73fadd4a0921db6f96957c65ee1",
                "sha256": "a358878f3e45b5e51d0b4e5b5c89d704422a72c2cf8ee9aaf9acedfa53f89105"
            },
            "downloads": -1,
            "filename": "plucky-0.4.3-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cbb5b73fadd4a0921db6f96957c65ee1",
            "packagetype": "bdist_wheel",
            "python_version": "3.5",
            "requires_python": null,
            "size": 10566,
            "upload_time": "2018-09-05T06:14:29",
            "upload_time_iso_8601": "2018-09-05T06:14:29.278124Z",
            "url": "https://files.pythonhosted.org/packages/d8/70/7b43e7280284bafecb345f4edb3eea7042cf0d089c5d112920eda650fda5/plucky-0.4.3-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "b91764b23264d7ae5d8109f9db0628f6",
                "sha256": "5bc75d43ae6b40f1b7ba42000b37e4934fa6bd2d6a6cd4e47461f803a404c194"
            },
            "downloads": -1,
            "filename": "plucky-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "b91764b23264d7ae5d8109f9db0628f6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8478,
            "upload_time": "2018-09-05T06:14:27",
            "upload_time_iso_8601": "2018-09-05T06:14:27.532190Z",
            "url": "https://files.pythonhosted.org/packages/4f/4e/a2d3157ec7031ea3ccc313400db27b92a65a9c002396a709e7457626f7ad/plucky-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2018-09-05 06:14:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "randomir",
    "github_project": "plucky",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "plucky"
}
        
Elapsed time: 0.02129s