Skip to main content
https://travis-ci.org/eflglobal/filters.svg?branch=master https://readthedocs.org/projects/filters/badge/?version=latest

Filters

The Filters library provides an easy and readable way to create complex data validation and processing pipelines, including:

  • Validating complex JSON structures in API requests or config files.

  • Parsing timestamps and converting to UTC.

  • Converting Unicode strings to NFC, normalizing line endings and removing unprintable characters.

  • Decoding Base64, including URL-safe variants.

And much more!

The output from one filter can be “piped” into the input of another, enabling you to “chain” filters together to quickly and easily create complex data pipelines.

Examples

Validate a latitude position and round to manageable precision:

(
    f.Required
  | f.Decimal
  | f.Min(Decimal(-90))
  | f.Max(Decimal(90))
  | f.Round(to_nearest='0.000001')
).apply('-12.0431842')

Parse an incoming value as a datetime, convert to UTC and strip tzinfo:

f.Datetime(naive=True).apply('2015-04-08T15:11:22-05:00')

Convert every value in an iterable (e.g., list) to unicode and strip leading/trailing whitespace. This also applies Unicode normalization, strips unprintable characters and normalizes line endings automatically.

f.FilterRepeater(f.Unicode | f.Strip).apply([
  b'\xe2\x99\xaa ',
  b'\xe2\x94\x8f(\xc2\xb0.\xc2\xb0)\xe2\x94\x9b ',
  b'\xe2\x94\x97(\xc2\xb0.\xc2\xb0)\xe2\x94\x93 ',
  b'\xe2\x99\xaa ',
])

Parse a JSON string and check that it has correct structure:

(
    f.JsonDecode
  | f.FilterMapper(
      {
        'birthday':  f.Date,
        'gender':    f.CaseFold | f.Choice(choices={'m', 'f', 'x'}),

        'utcOffset':
            f.Decimal
          | f.Min(Decimal('-15'))
          | f.Max(Decimal('+15'))
          | f.Round(to_nearest='0.25'),
      },

      allow_extra_keys   = False,
      allow_missing_keys = False,
    )
).apply('{"birthday":"1879-03-14", "gender":"M", "utcOffset":"1"}')

Requirements

Filters is compatible with Python versions 3.6, 3.5 and 2.7.

Installation

Install the latest stable version via pip:

pip install filters

Extensions

The following extensions are available:

  • Django Filters: Adds filters designed to work with Django applications. To install:

    pip install filters[django]
  • ISO Filters: Adds filters for interpreting standard codes and identifiers. To install:

    pip install filters[iso]

Metadata

Release files for filters 1.3.2

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

Source distribution (sdist)

Source distribution for filters 1.3.2
File Size Uploaded
filters-1.3.2.tar.gz 57.6 kB Details

Built distribution (wheel)

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

Total release size: 94.7 kB

Release files / filters-1.3.2.tar.gz

Download URL filters-1.3.2.tar.gz
Size 57.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b74fad6a7885f1380dd12fde0f849e8c5e459919ce314f76c2352064c7a30796
BLAKE2b-256 checksum
How to use checksums
537808fb3baa3ff3cd3833866ae13de7871b702fe3fcd8ea9c49c8493de74572
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / filters-1.3.2-py2.py3-none-any.whl

Download URL filters-1.3.2-py2.py3-none-any.whl
Size 37.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
248150dfd768f9211f4c897696f3f4c370697e0f19b9c1f85577a27495b18496
BLAKE2b-256 checksum
How to use checksums
3ebd8d307686d7b058f5e0c51d5f188a438259a670ec0d5f8ebda7ebe9b447af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.3.2 This release

2 release files

1.3.1

2 release files

1.3.0

3 release files

1.2.3

3 release files

1.2.2

3 release files

1.2.1

3 release files

1.2.0

3 release files

1.1.7

3 release files

1.1.6

3 release files

1.1.5

2 release files

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

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