Skip to main content

https://github.com/kudo/collection-filter

Build Status Unit Test Coverage

This library provides a DSL filter for list or dict data. It is original designed for RESTful API partial response. Tested with Python 2.6, 2.7.

Quick Start

To install, use pip:

$ pip install collection-filter

Then:

$ python

>>> from collection_filter import collection_filter

# Query a dict
>>> collection_filter({'foo': 1, 'bar': 2}, 'foo')
{'foo': 1}

# Query a dict with multiple elements (seperated by comma)
>>> collection_filter({'foo': 1, 'bar': 2}, 'foo,bar')
{'foo': 1, 'bar': 2}

# Query a dict deeply
>>> collection_filter({'foo': {'bar': 2, 'orange': 'sweet'}}, 'foo.bar')
{'foo': {'bar': 2}}

# Query a list
>>> collection_filter([{'foo': 1, 'bar': 2}, {'foo': 3, 'bar': 4}], '[].foo')
[{'foo': 1}, {'foo': 3}]

# list/dict combination example
>>> collection_filter({'foo': 'bar', 'aListOfDict': [{'foo': 1, 'bar': 2}], 'aListOfDict[].foo')
{'aListOfDict': [{'foo': 1}]}

Syntax

Currently support operators

Operator

Description

,

Multiple field query sperated by comma

[]

To indicate the data should be handled as list

.

Dot notation should follow with a symbol name which to specify a field in current dict data

Release files for collection-filter 0.5

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

Source distribution (sdist)

Source distribution for collection-filter 0.5
File Size Uploaded
collection-filter-0.5.tar.gz 3.7 kB Details

Release files / collection-filter-0.5.tar.gz

Download URL collection-filter-0.5.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5908cdd4db3efe3003eda0ee8c63f9f4d2b58ba7d69c163db442814f6bca99bd
BLAKE2b-256 checksum
How to use checksums
e708c6734aba73e246929374d7b82f948de9ae3227403b9a69b27e2ba50ebc30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5 This release

1 release file

0.3

1 release file

0.2

1 release file

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