Skip to main content
from datetime import datetime
from verity import Type, field

def parse_date(value):
    return datetime.strptime(value, '%Y-%m-%d').date()

class Person(Type):
    name = field(str)
    birthdate = field(parse_date)
>>> data = {'name': 'Bob', 'birthdate': '1980-12-21'}
>>> person = Person(data)
>>> person.birthdate
datetime.date(1980, 12, 21)

Types are nestable:

class Food(Type):
    name = field(str)
    energy = field(float)


class Person(Type):
    name = field(str)
    birthdate = field(parse_date)
    favourite_food = field(Food)
>>> data = {'name': 'Bob', 'birthdate': '1980-12-21', 'favourite_food': {'name': 'Pizza', 'energy': '1200'}}
>>> person = Person(**data)
>>> person.favourite_food.name
'Pizza'

Types can JSON-ify themselves

>>> person.__json__()
{'name': 'Bob', 'birthdate': datetime.date(1980, 12, 21), 'favourite_food': Food()}

Though it’s not recurive.

However, it can cooperate with json_default:

>>> from verity import json
>>> json.dumps(person)
'{"birthdate": "1980-12-21", "favourite_food": {"energy": 1200.0, "name": "Pizza"}, "name": "Bob"}'

Release files for verity 0.1

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

Source distribution (sdist)

Source distribution for verity 0.1
File Size Uploaded
verity-0.1.tar.gz 3.4 kB Details

Built distribution (wheel)

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

Total release size: 7.5 kB

Release files / verity-0.1.tar.gz

Download URL verity-0.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9a90bb94146f937057a10c630386f631018c77b52805ca86031d5a9ff6926b4e
BLAKE2b-256 checksum
How to use checksums
a16b6261ffeda91e4763e700cf1439038ccbc3b64f520a18f2b61e76c1205b8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / verity-0.1-py2.py3-none-any.whl

Download URL verity-0.1-py2.py3-none-any.whl
Size 4.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0366c9f644a5838064581182e180759181ee37d287fda40400bf6a52231352d9
BLAKE2b-256 checksum
How to use checksums
3cbe1f850f675102be9f8f3a4ddac90f8f5eb705fc82e5d2b74792c458faaa92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

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