openfloor.json_serializable

class openfloor.json_serializable.JsonSerializable[source]

Bases: ABC

Abstract base class for JSON serializable objects

classmethod from_dict(data)[source]

Create an instance from a dictionary or instance

Return type:

JsonSerializableDict

classmethod from_file(filepath, **kwargs)[source]

Create an instance from a JSON file

Return type:

JsonSerializable

classmethod from_json(json_str)[source]

Create an instance from a JSON string

Return type:

JsonSerializable

to_file(filepath, **kwargs)[source]

Save instance to a JSON file

Return type:

None

to_json(**kwargs)[source]

Convert instance to JSON string

Return type:

str

class openfloor.json_serializable.JsonSerializableDataclass[source]

Bases: JsonSerializable

Base class for JSON serializable objects that are dataclasses

copy()[source]

Create a copy of the dataclass

Return type:

JsonSerializableDataclass

classmethod from_dict(data)[source]

Create an instance from a dictionary

Return type:

JsonSerializableDataclass

class openfloor.json_serializable.JsonSerializableDict(*args, **kwargs)[source]

Bases: JsonSerializable

Base class for JSON serializable objects that serialize to dictionaries

clear()[source]

Clear all items

Return type:

None

copy()[source]

Create a copy of the dictionary

Return type:

JsonSerializableDict

get(key, default=None)[source]

Get a value by key with a default value

Return type:

Any

update(other)[source]

Update with values from another dictionary

Return type:

None

class openfloor.json_serializable.JsonSerializableList(*args, **kwargs)[source]

Bases: JsonSerializable

Base class for JSON serializable objects that serialize to lists

append(item)[source]

Add an item to the list

Return type:

None

clear()[source]

Clear all items from the list

Return type:

None

extend(items)[source]

Add multiple items to the list

Return type:

None

to_file(filepath, **kwargs)[source]

Save instance to a JSON file

Return type:

None

to_json(**kwargs)[source]

Convert instance to JSON string

Return type:

str

openfloor.json_serializable.split_kwargs(cls, kwargs)[source]

Split kwargs into defined and undefined fields for a dataclass class.

Parameters:
  • cls (Type) – The class to check fields against

  • kwargs (Dict[str, Any]) – Dictionary of keyword arguments to split

Return type:

Tuple[Dict[str, Any], Dict[str, Any]]

Returns:

Tuple of (defined_fields, undefined_fields) where each is a dictionary of the respective fields from kwargs. Defined fields that are not in kwargs will be included in defined_fields with a value of None.