Skip to main content

extract values from collection items

Project description

pluckit

Extract values from collection items.

Install

pip install pluckit

Usage

from pluckit import pluck

data = [
  {'x': 1, 'y': 2},
  {'x': 2, 'y': 4},
  {'x': 3, 'y': 6},
]
pluck(data, 'x')
> [1, 2, 3]


# supports arbitrarily deep plucks and function calls
people = [
    { 'name': 'Daniel', 'friends': [ 'Josh', 'Mel' ] },
    { 'name': 'Mel', 'friends': [ 'Daniel', 'Suzy' ] },
]
pluck(people, 'friends[-1].lower[:3]')
> [ 'mel', 'suz' ]



# use Pluckables for built-in functionality

from pluckit.pluckable import PluckableList

PluckableList([
  {'x': 1, 'y': 2},
  {'x': 2, 'y': 4},
  {'x': 3, 'y': 6},
]).pluck('x')
> [1, 2, 3]


# use the Pluckable mixin to build your own

from pluckit import Pluckable
class MyDict(dict, Pluckable): pass

MyDict({
  'home' : {'x' : 1, 'y' : 2},
  'work' : {'x' : 3, 'y' : 6},
}).pluck('x')
> {'home' : 1, 'work' : 3}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pluckit-0.6.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

pluckit-0.6.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pluckit-0.6.0.tar.gz.

File metadata

  • Download URL: pluckit-0.6.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pluckit-0.6.0.tar.gz
Algorithm Hash digest
SHA256 975148f31de6d38bdc9e1022821e8834e817860035a4c2b6a0b899b2865258c6
MD5 5ac5267fe49856d9c7178f9c45c41481
BLAKE2b-256 3b50476771bba6afa872b8d42073a74f46a667a25266e1ee5f004f9c92c9a23b

See more details on using hashes here.

File details

Details for the file pluckit-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pluckit-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pluckit-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 188d97c801d3cb82c4c6b56b1bca879c42cd404080f97e8e6a1c4acb57e93b8b
MD5 ebc106ce34c33b3bc4dcb18fcbfafa5e
BLAKE2b-256 61b797fb8cad75ed15bd7d68ce36820d85905add71a499774fb552fa87b4fbb4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page