Skip to main content

A Python typing library for data validation.

Project description

This library allows type tests and transformation and can be used for data loading, storing and validation.

Usage

Simple type-checking:

import typed

            t1 = typed.int | typed.string

            assert t1.test('abc')
            assert t1.test(u'xyz')
            assert t1.test(30)
            assert not t1.test(1.2)
            assert not t1.test(True)
            assert not t1.test(None)

            t2 = typed.list(typed.int)

            assert t1.test([1, 2, 3])
            assert t1.test([])
            assert not t1.test(['a', 'b', 'c'])

            t3 = typed.list(typed.int | typed.string)

            assert t3.test([1, 'a', 2, 'b'])

            t4 = typed.list(typed.int) | typed.list(typed.string)

            assert t4.test([1, 2, 3])
            assert t4.test(['a', 'b', 'c'])
            assert not t4.test([1, 'a', 2, 'b'])

            t5 = typed.set(1, 2, 3)

            assert t5.test(2)
            assert not t5.test(4)

            t6 = typed.dict({
                            'a': typed.int,
                            'b': typed.bool.optional,
                            'c': (typed.int | typed.none).optional,
                    })

Project details


Release history Release notifications

This version
History Node

0.6

History Node

0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
typed-0.6.tar.gz (7.0 kB) Copy SHA256 hash SHA256 Source None Jul 23, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page