#!/usr/bin/python3 import cerberus from schwifty import IBAN, BIC import datetime def valid_iban(field, value, error): try: IBAN(value) return True except ValueError: error(field, 'not a valid IBAN') def valid_bic(field, value, error): try: BIC(value) return True except ValueError: error(field, 'not a valid BIC') def iso_date(field, value, error): try: datetime.datetime.strptime(value, "%Y-%m-%d") return True except ValueError: error(field, 'not a valid IDO 8601 date') document = {'finanzdaten': {'bic': 'BELADEBEXXX', 'holder': '', 'iban': 'DE68100500004164690823', 'issuance': '2013-02-12', 'reference': '0023', 'scan-sepa-mandate': ''}, 'mitgliederdaten': {'bis': '', 'mitgliedsbeitrag': '30', 'scan-antrag': '', 'schliessberechtigung': 'Ja', 'spendenbeitrag': '', 'status': 'V', 'von': '2012-05-06'}, 'stammdaten': {'address_code': '39106', 'address_country': 'DE', 'address_label': 'David Kilias\nHohepfortestr. 9\n39106 Magdeburg', 'address_locality': 'Magdeburg', 'address_region': '', 'address_street': 'Hohepfortestr. 9', 'birth_date': '1986-11-29', 'birth_location': 'Karl-Marx-Stadt', 'email': 'david.kilias@netz39.de', 'fullname': 'David Kilias', 'nickname': 'dkdent', 'pgp-key': '', 'ssh-key': ''}, 'timestamp': '2020-03-25T23:58:11', 'id': '6af68'} schema_fin={'bic': {'type': 'string', 'check_with': valid_bic}, 'iban': {'type': 'string', 'check_with': valid_iban}, 'issuance': {'type': 'string', 'check_with': iso_date}, 'reference': {'type': 'string'}, 'scan-sepa-mandate': {'type': 'string'}, 'holder': {'type': 'string'}} v = cerberus.Validator() v.validate(document['finanzdaten'], schema_fin)