Skip to main content

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)

Metadata

Release files for ezserialize 1.0

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

Source distribution (sdist)

Source distribution for ezserialize 1.0
File Size Uploaded
ezserialize-1.0.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ezserialize 1.0
File Interpreter ABI Platform
ezserialize-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.5 kB

Release files / ezserialize-1.0.tar.gz

Download URL ezserialize-1.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5fb9cce7d3d568df40f4fc1d0e1eee6a6673cf85b6fbfb84cd4390532d7ee097
BLAKE2b-256 checksum
How to use checksums
498e2977e440fba95bfcc11c1bcc67bc2cad40e535f262469111194c3d7f8664
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / ezserialize-1.0-py3-none-any.whl

Download URL ezserialize-1.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad0f1ebe59cef6c841e4fc3807ea604b188f6cbe202118f6c4be7cd4f416b968
BLAKE2b-256 checksum
How to use checksums
c8616ba878a7ba888f09526c80dbe96500dc0c9fdf334638aee309d31b8ce26c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.0 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