Skip to main content

grandschemathings

Automatic JSON serialization, deserialization, and schema generation for Python dataclasses.

The grandschemathings Python package provides automatic loading and saving of JSON based on Python objects, with validation against an automatically-generated schema. It is designed to make it easy to serialize and deserialize objects to and from JSON.

Repository: github.com/cambridgeconsultants/GrandSchemaThings

User Guide

System Requirements

  • Python >= 3.13

Installation

Install from PyPI using pip:

pip install grandschemathings

Or, if you use uv or Poetry:

uv add grandschemathings
poetry add grandschemathings

Usage

Simple Usage Example

Here's a simple example to illustrate how you can use grandschemathings to serialize and deserialize an object.

from dataclasses import dataclass
from pathlib import Path

from grandschemathings import GrandSchemaThings


@dataclass
class MyData(GrandSchemaThings):
    name: str
    age: int


# Create an instance
data = MyData(name="Alice", age=30)

# Serialize to JSON file
data.to_file(Path("data.json"), pretty=True)

# Deserialize from JSON file
loaded_data = MyData.from_file(Path("data.json"))
print(loaded_data)

Complex Usage Example

This demonstrates how to handle nested objects and dictionaries with enum keys.

from dataclasses import dataclass
from enum import Enum
from pathlib import Path

from grandschemathings import GrandSchemaThings


class Hobby(Enum):
    READING = "reading"
    CYCLING = "cycling"
    COOKING = "cooking"
    GARDENING = "gardening"


@dataclass
class Address(GrandSchemaThings):
    street: str
    city: str
    postcode: str


@dataclass
class User(GrandSchemaThings):
    name: str
    age: int
    address: Address
    hobbies: dict[Hobby, int]


# Create an instance
user = User(
    name="Bob",
    age=25,
    address=Address(street="456 Elm St", city="Faketown", postcode="AB12 3CD"),
    hobbies={Hobby.READING: 5, Hobby.CYCLING: 3, Hobby.COOKING: 4, Hobby.GARDENING: 1},
)

# Serialize to JSON file
user.to_file(Path("user.json"), pretty=True)

# Deserialize from JSON file
loaded_user = User.from_file(Path("user.json"))
print(loaded_user)

API Reference

The following instance and class methods are available for GrandSchemaThings objects.

Method Name Description Type
from_file(...) Creates an instance from a JSON file. Class Method
to_file(...) Writes the instance to a JSON file. Instance Method
from_json_dict(...) Creates an instance of the class from JSON data (in Python dict form). Class Method
to_json_dict() Creates a Python dict containing JSON-compatible data representing the instance. Instance Method
list_from_file(...) Loads a list of instances from a JSON file. Class Method
list_to_file(...) Writes a list of instances to a specified file. Class Method
schema(...) Generates a full schema for the class, optionally including the schema version. Class Method
schema_to_file(...) Saves the schema for the class to a specified file. Class Method

Developer Guide

Development Setup

To modify GrandSchemaThings, you can clone the repository and install the development dependencies using Poetry:

  1. Install Poetry: If you haven't already got Poetry installed, follow the instructions on their website.
  2. Clone the repository:
    git clone https://github.com/cambridgeconsultants/GrandSchemaThings.git
    cd grandschemathings
    
  3. Install dependencies:
    poetry install
    

Running Tests

Run the validation suite:

poetry run validate

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Release files for grandschemathings 1.1.7

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

Source distribution (sdist)

Source distribution for grandschemathings 1.1.7
File Size Uploaded
grandschemathings-1.1.7.tar.gz 9.5 kB Details

Built distribution (wheel)

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

Total release size: 20.3 kB

Release files / grandschemathings-1.1.7.tar.gz

Download URL grandschemathings-1.1.7.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3956dd6824fe2a1bd9af1d93625af8282c13296e101b69f1370a361cdd68da3f
BLAKE2b-256 checksum
How to use checksums
d0d85707325363b7eb53db2c546bcd5419fef5bec62321ae6333005c986c08ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.

Transparency log

Release files / grandschemathings-1.1.7-py3-none-any.whl

Download URL grandschemathings-1.1.7-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1aac1511a7ff75c1f45f941162479745c9b0d1e113cf2f4fc377ca78eb1ba8a9
BLAKE2b-256 checksum
How to use checksums
1e4113b1182b2e2640a1d3bb79c7cefccd33999b0c7d8a2e8149ccc0e0748da2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.

Transparency log

Release history Release notifications | RSS feed

1.1.9

2 release files

1.1.8

2 release files

This release

1.1.7 This release

2 release files

1.1.6

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