Skip to main content

transform-data-schema: simple transform and validate schema


transform-data-schema is a library for converting complex datatypes, such as objects, to and from native Python datatypes.

from transform_data_schema import (
    BaseSchemaTransform, 
    EXCLUDE, 
    fields, 
    transform_fields, 
    ValidationError
)


class EventJBTransformSchema(BaseSchemaTransform):
    class Meta:
        unknown = EXCLUDE

    ID = fields.Str()
    PROFILE_ID = transform_fields.NestedValueField(
        nested_key='data_event.profile_id',
        type_class=fields.Str,
        required=True
    )
    JOURNEY_ID = transform_fields.NestedValueField(
        nested_key='data_event.journey_id',
        type_class=fields.Str,
        required=True
    )
    MC_ID = transform_fields.NestedValueField(
        nested_key='data_event.master_campaign_id',
        type_class=fields.Str,
        required=True
    )
    MERCHANT_ID = transform_fields.NestedValueField(
        nested_key='data_event.merchant_id',
        type_class=fields.Str,
        required=True
    )
    DATA_TYPE = fields.Str(data_key='event_type')
    ACTION_TIME = transform_fields.NestedValueField(
        nested_key='data_event.action_time',
        type_class=transform_fields.DatetimeFromTimeStamp,
        required=True
    )
    NODE_CODE = transform_fields.NestedValueField(
        nested_key='data_event.node_code',
        type_class=fields.Str,
    )
    NODE_ID = transform_fields.NestedValueField(
        nested_key='data_event.node_id',
        type_class=fields.Str
    )

if __name__ == '__main__':
    raw_data = {
        "message_id": "19db4e86-0cef-11ed-9d73-aea73dddcfef",
        "data_event": {
            "action_time": 1658845656.471722,
            "journey_id": "1a596c15-3ccb-4d51-8d75-03223c5bce8e",
            "merchant_id": "1b99bdcf-d582-4f49-9715-1b61dfff3924",
            "node_id": "64690a9e-e807-4b2a-8da2-f2d28d085fd2",
            "node_code": "WEB_PUSH",
            "event_type": "IN_NODE",
            "profile_id": "ff5d808c-5a28-415f-b60d-9070519e7f1a",
            "master_campaign_id": "a065a9fd-2341-468b-8580-dba1cc4b3459",
            "event_id": "061dbe38-b5db-4470-a1e5-8e2ce2e14851"
        },
        "event_type": "profile_in_node"
    }
    result = EventJBTransformSchema.transform(raw_data)
    pprint(result, indent=2)
    
    """
    { 
        'ACTION_TIME': datetime.datetime(2022, 7, 26, 14, 27, 36, 471722, tzinfo=datetime.timezone.utc),
        'DATA_TYPE': 'profile_in_node',
        'JOURNEY_ID': '1a596c15-3ccb-4d51-8d75-03223c5bce8e',
        'MC_ID': 'a065a9fd-2341-468b-8580-dba1cc4b3459',
        'MERCHANT_ID': '1b99bdcf-d582-4f49-9715-1b61dfff3924',
        'NODE_CODE': 'WEB_PUSH',
        'NODE_ID': '64690a9e-e807-4b2a-8da2-f2d28d085fd2',
        'PROFILE_ID': 'ff5d808c-5a28-415f-b60d-9070519e7f1a'
    }
    """

In short, transform-data-schema can be used to:

  • Validate input data.
  • Deserialize input data to app-level objects.

Get It Now

$ pip install -U transform-data-schema

Requirements

  • Python >= 3.7

Metadata

Release files for transform-data-schema 1.2.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 transform-data-schema 1.2.5
File Size Uploaded Provenance Actions
transform-data-schema-1.2.5.tar.gz 6.8 kB Without provenance Details for transform-data-schema-1.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for transform-data-schema 1.2.5
File Interpreter ABI Platform Actions
transform_data_schema-1.2.5-py3-none-any.whl Python 3 none any Details for transform_data_schema-1.2.5-py3-none-any.whl

Total release size: 13.8 kB

Release files / transform-data-schema-1.2.5.tar.gz

Download URL transform-data-schema-1.2.5.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9b9c65f649d6082e094a84347f76ef8441ffd22c2f2297e67eea331f0ba68a75
BLAKE2b-256 checksum
How to use checksums
bfe2600782a07c382d635972a814c6f43a4fe6b8937af57e5c399893c7e41aaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.8

Release files / transform_data_schema-1.2.5-py3-none-any.whl

Download URL transform_data_schema-1.2.5-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9980ba3ad6e8015b1cfbd8e992be465007da788becde2080d3054e64218cc247
BLAKE2b-256 checksum
How to use checksums
609544e43af5f69323ea3f983f4eb71632ac00b046599776736705a5dde3c937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.8

Security for transform-data-schema 1.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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