Skip to main content

Easy to use python json serializer and deserializer tool using syntax similar to dataclasses

Project description

ezserialize 1.0

An easy to use python json serializer and deserializer for custom objects using similar syntax to dataclasses

Install

On the terminal, type the following command:
pip install ezserialize

Usage

# Import ezserialize
from ezserialize import serializable, serialize, deserialize, List, pretty_print
# Use your IDE to inspect the rest of the functions which are similar to the ones imported

# Tell ezserialize which objects you want to serialize. Each attribute must be serializable aswell

@serializable
class Pet:
    pet_type: str
    name: str
    age: int
    weight: float

@serializable
class Person:
    name: str
    age: int
    profession: str
    pets: List(Pet)
# When you use a default value, the type hint can be avoided, except for lists. Always use ezserialize.List and not 'list' for type hinting.

# Create your object. The __init__ method is automatically implemented, and use keyword arguments
person = Person(
    name = "John",
    age = 19,
    profession = "vet",
    pets = [
        Pet(
            pet_type = "cat",
            name = "luna",
            age = 6,
            weight = 2.5,
        ),
    ]
)

# Serialize your object to make it a JSON dict. You can then save it to a file using ezserialize.save() or manually dumping it using builtins.json
serialized_person = serialize(person)

# When you need your person back, use deserialize with the JSON object and the type you want back
deserialized_person = deserialize(serialized_person, Person)

# When you print the person (using pretty_print/(pretty_format for the string alone)) person and deserialized_person should look the same
print("Normal:")
pretty_print(person)
print("Deserialized:")
pretty_print(deserialized_person)

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

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

Source Distribution

ezserialize-1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ezserialize-1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file ezserialize-1.0.tar.gz.

File metadata

  • Download URL: ezserialize-1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for ezserialize-1.0.tar.gz
Algorithm Hash digest
SHA256 5fb9cce7d3d568df40f4fc1d0e1eee6a6673cf85b6fbfb84cd4390532d7ee097
MD5 0fbf4200c42507716e962cb68349b182
BLAKE2b-256 498e2977e440fba95bfcc11c1bcc67bc2cad40e535f262469111194c3d7f8664

See more details on using hashes here.

File details

Details for the file ezserialize-1.0-py3-none-any.whl.

File metadata

  • Download URL: ezserialize-1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for ezserialize-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad0f1ebe59cef6c841e4fc3807ea604b188f6cbe202118f6c4be7cd4f416b968
MD5 dc8e98edc32d63a6f126be46128f0050
BLAKE2b-256 c8616ba878a7ba888f09526c80dbe96500dc0c9fdf334638aee309d31b8ce26c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page