Welcome to the Grave Settings documentation!#
A library for automatic serialization of python object hierarchies to storage.
from pathlib import Path
from grave_settings.config_file import ConfigFile
from datetime import datetime
class MyObject:
def __init__(self):
self.attribute1 = 'test'
self.attribute2 = datetime.now()
with ConfigFile(Path('test.toml'), data=MyObject, formatter='toml') as config:
pass # file will be saved automatically at the end of the with block
with open('test.toml', 'r') as f:
print(f.read())
__class__ = "__main__.MyObject"
attribute1 = "test"
[attribute2]
__class__ = "datetime.datetime"
state = [
2023,
1,
24,
19,
8,
34,
522692,
]
Install#
pip install grave-settings
Getting Started:#
This library was primarily created to manage configuration files in “human readable” formats.
Limitations:#
Security#
By default this library allows for the importing and instantiation of arbitrary python modules / classes. This is a security concern in many production environments. There are a couple of mechanisms built in to deal with this, but they have not been a main concern of mine. Feel free to reach out with suggestions ect.
If security wasn’t your first thought, its likely that importing arbitrary modules is not really a concern with your use case. Just dont do anything too crazy like automatically deserializing HTTP request bodies and expect no one to get weird with it.
Read this page (with examples) about security concerns.
Circular References#
Circular references can be a problem when deserializing structures because of a “chicken and egg” problem in the
recursive process. There is an automatic process for dealing with circular references, but only if the nested reference
associated with the attribute of a managed object, like an object that implements
grave_settings.abstract.Serializable
’s interface. If the reference is nested in a list or a python dictionary
then custom code will have to take care of switching the grave_settings.formatter_settings.PreservedReference
objects out for their proper references. The interface outlined in Serializable makes it easy to get a callback when the
deserialization is finished and provides a reference to the grave_settings.formatter_settings.FormatterContext
.
With this method it is simple to resolve the circular references, but you will likely have to have some idea of where
the references might be.
Also, note that the “automatic” handling of circular references is only enabled if you add the
grave_settings.semantics.NotifyFinalizedMethodName
semantic to a context. This must be manually enabled because
the default implementation of finalize is inefficient. See grave_settings.abstract.Serializable.finalize()
For examples and more info on dealing with circular references. Circular References
- Limitations
- API Reference
- Examples
- API Documentation
- abstract
Serializable
VersionedSerializable
VersionedSerializable.VERSION
VersionedSerializable.get_version()
VersionedSerializable.get_version_object()
VersionedSerializable.get_conversion_manager()
VersionedSerializable.check_convert_update()
VersionedSerializable.conversion_manager_converted()
VersionedSerializable.get_versioning_endpoint()
make_kill_converter()
IASettings
- base
Settings
SlotSettings
SlotSettings.SETTINGS_KEYS
SlotSettings.assemble_settings_keys_from_base()
SlotSettings.get_versioning_endpoint()
SlotSettings.get_settings_keys_rems()
SlotSettings.get_settings_keys_base_slots()
SlotSettings.get_settings_keys()
SlotSettings.safe_update()
SlotSettings.generate_key_value_pairs()
SlotSettings.to_dict()
- config_file
PassLogFilePath
LogFileLink
ConfigFile
ConfigFile.FORMATTER_STR_DICT
ConfigFile.add_config_dependency()
ConfigFile.add_log_file_link()
ConfigFile.is_loaded()
ConfigFile.backup_settings_file()
ConfigFile.settings_invalidated()
ConfigFile.validate_file_path()
ConfigFile.save()
ConfigFile.check_in_serialization_context()
ConfigFile.get_serialization_context()
ConfigFile.handle_serialize_IASettings()
ConfigFile.load()
ConfigFile.check_in_deserialization_context()
ConfigFile.get_deserialization_context()
ConfigFile.handle_deserialize_LogFileLink()
ConfigFile.instantiate_data()
ConfigFile.get_load_data_obj()
ConfigFile.to_dict()
ConfigFile.from_dict()
ConfigFile.handle_me()
- conversion_manager
- default_handlers
force_instantiate()
NotSerializableException
SerializationHandler
SerializationHandler.init_handler()
SerializationHandler.handle_path()
SerializationHandler.handle_Complex()
SerializationHandler.handle_Rational()
SerializationHandler.handle_method()
SerializationHandler.omit()
SerializationHandler.handle_bytes()
SerializationHandler.handle_partial()
SerializationHandler.handle_Enum()
SerializationHandler.handle_PreservedReference()
SerializationHandler.handle_Iterable()
SerializationHandler.handle_Mapping()
SerializationHandler.handle_type()
SerializationHandler.handle_function_type()
SerializationHandler.handle_NoneType()
SerializationHandler.handle_serializable()
SerializationHandler.handle_datetime()
SerializationHandler.handle_date()
SerializationHandler.handle_timedelta()
SerializationHandler.default_handler()
SerializationHandler.handle()
DeSerializationHandler
DeSerializationHandler.init_handler()
DeSerializationHandler.handle_path()
DeSerializationHandler.handle_Complex()
DeSerializationHandler.handle_Rational()
DeSerializationHandler.handle_method()
DeSerializationHandler.handle_bytes()
DeSerializationHandler.handle_partial()
DeSerializationHandler.handle_Enum()
DeSerializationHandler.handle_NoneType()
DeSerializationHandler.handle_PreservedReference()
DeSerializationHandler.handle_KeySerializableDict()
DeSerializationHandler.handle_tuple()
DeSerializationHandler.handle_set()
DeSerializationHandler.handle_type()
DeSerializationHandler.handle_serializable()
DeSerializationHandler.handle_datetime()
DeSerializationHandler.handle_date()
DeSerializationHandler.handle_timedelta()
DeSerializationHandler.default_handler()
DeSerializationHandler.add_handlers_by_type_hints()
- formatter
ProcessingException
Processor
IFormatter
IFormatter.to_buffer()
IFormatter.write_to_file()
IFormatter.from_buffer()
IFormatter.read_from_file()
IFormatter.serialized_obj_to_buffer()
IFormatter.buffer_to_obj()
IFormatter.get_serialization_handler()
IFormatter.get_deserialization_handler()
IFormatter.get_serialization_frame_context()
IFormatter.get_deserialization_frame_context()
IFormatter.get_serialization_context()
IFormatter.get_deserialization_context()
IFormatter.dumps()
IFormatter.loads()
IFormatter.get_serializer()
IFormatter.get_deserializer()
IFormatter.serialize()
IFormatter.free_deser_obj()
IFormatter.deserialize()
Serializer
Serializer.set_default_semantics()
Serializer.supports_semantic()
Serializer.check_in_object()
Serializer.handle_serialize_list_in_place()
Serializer.handle_serialize_dict_in_place()
Serializer.handle_user_list()
Serializer.handle_user_dict()
Serializer.handle_add_semantics()
Serializer.handle_temporary()
Serializer.template_object_serialize()
Serializer.handle_default()
Serializer.process()
Serializer.serialize()
Serializer.dispose()
DeSerializer
DeSerializer.set_default_semantics()
DeSerializer.supports_semantic()
DeSerializer.run_semantics_through_path()
DeSerializer.handle_list()
DeSerializer.handle_dict()
DeSerializer.handle_preserved_referece()
DeSerializer.handle_default()
DeSerializer.handle_secondary_preserved_reference()
DeSerializer.cache_instance_ref()
DeSerializer.process()
DeSerializer.deserialize()
DeSerializer.dispose()
Formatter
- formatter_settings
AddSemantics
NoRef
Temporary
PreservedReference
FormatterSpec
FormatterSpec.ROUTE_PATH_TRANSLATION
FormatterSpec.ROUTE_PATH_REGEX
FormatterSpec.PRIMITIVES
FormatterSpec.SPECIAL
FormatterSpec.ATTRIBUTE
FormatterSpec.TYPES
FormatterSpec.get_primitive_types()
FormatterSpec.get_special_types()
FormatterSpec.get_attribute_types()
FormatterSpec.path_to_str()
FormatterSpec.str_to_path()
FormatterSpec.get_part_from_path()
FormatterSpec.is_circular_ref()
FormatterSpec.copy()
FormatterContext
- framestack_context
- handlers
- helper_objects
- semantics
SymantecNotSupportedError
SymantecConfigurationInvalid
SecurityException
OmitMeError
Negate
Semantic
Semantics
SemanticContext
IgnoreDuckTypingForType
IgnoreDuckTypingForSubclasses
OmitMe
PreserveDictionaryOrdering
PreserveSerializableKeyOrdering
OverrideClassString
SerializeNoneVersionInfo
AutoKeySerializableDictType
Indentation
AutoPreserveReferences
EnforceReferenceLifecycle
DetonateDanglingPreservedReferences
ResolvePreservedReferences
NotifyFinalizedMethodName
DoNotAllowImportingModules
ClassStringPassFunction
KeySemanticsTemplate
- utilities
- validation
- Formatters
- abstract