A Python Object-JSON-Object serializer package
Project description
Introducing Python Data Contracts
With this package you can define your own data contracts strictly and define data validations and pre-processing steps which will insure data integrity and capable of serializing to-and-from JSON format.
Example Usage
from serializer import Interface
class IP(Interface):
# Declaring data type validations
ip_address = str
host_name = str
class Record(Interface):
user_name = str
age = int
ip = IP
# Pre-processors to standardize data
def __user_name__(value):
return value.capitalize()
args = {
'user_name': 'ximi',
'age': 21,
'ip': IP(ip_address='192.168.2.1', host_name='localhost')
}
request = Record(**args)
print ("Serializing from Object to JSON: \n", request.serialize())
# Serializing from Object to JSON:
# {'user_name': 'Ximi', 'age': 21, 'ip': {'ip_address':'192.168.2.1', 'host_name': 'localhost'}}
args = {
'user_name': 'ximi',
'age': 21,
'ip': {
'ip_address': '192.168.2.1',
'host_name': 'localhost'
}
}
request = Record(**args)
print ("Serialise with Reverse type conversion: \n", request.serialize())
# Serialise with Reverse type conversion:
# {'user_name': 'Ximi', 'age': 21, 'ip': {'ip_address': '192.168.2.1', 'host_name': 'localhost'}}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for python_serializer-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d23304980848d858ccd5b724fb63267fc1a179316a257a3266bd13f656cd7f9c |
|
MD5 | ff91795c1b9e0ff20e79545bb3ff9186 |
|
BLAKE2b-256 | 5ef461c2c6b45ac7a9f769500e64e7e6356f274d60ea84b993b4aea04eb62d2e |