package documentation

Interfaces for serializing Django objects. Usage:: from django.core import serializers json = serializers.serialize("json", some_queryset) objects = list(serializers.deserialize("json", json)) To add your own serializers, use the SERIALIZATION_MODULES setting:: SERIALIZATION_MODULES = { "csv": "path.to.csv.serializer", "txt": "path.to.txt.serializer", }

Module base Module for abstract serializer/unserializer base classes.
Module json Serialize data to/from JSON
Module jsonl Serialize data to/from JSON Lines
Module python A Python "serializer". Doesn't do much serializing per se -- just converts to and from basic Python data types (lists, dicts, strings, etc.). Useful as a basis for other serializers.
Module pyyaml YAML serializer.
Module xml_serializer XML serializer.

From __init__.py:

Class BadSerializer Stub serializer to hold exception raised during registration
Function deserialize Deserialize a stream or a string. Return an iterator that yields ``(obj, m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* -- object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name : list_of_related_objects}``.
Function get_deserializer Undocumented
Function get_public_serializer_formats Undocumented
Function get_serializer Undocumented
Function get_serializer_formats Undocumented
Function register_serializer Register a new serializer.
Function serialize Serialize a queryset (or any iterator that returns database objects) using a certain serializer.
Function sort_dependencies Sort a list of (app_config, models) pairs into a single list of models.
Function unregister_serializer Unregister a given serializer. This is not a thread-safe operation.
Constant BUILTIN_SERIALIZERS Undocumented
Function _load_serializers Register built-in and settings-defined serializers. This is done lazily so that user code has a chance to (e.g.) set up custom settings without needing to be careful of import order.
Variable _serializers Undocumented
BUILTIN_SERIALIZERS: dict[str, str] = (source)

Undocumented

Value
{'xml': 'django.core.serializers.xml_serializer',
 'python': 'django.core.serializers.python',
 'json': 'django.core.serializers.json',
 'yaml': 'django.core.serializers.pyyaml',
 'jsonl': 'django.core.serializers.jsonl'}
_serializers: dict = (source)

Undocumented

def register_serializer(format, serializer_module, serializers=None): (source)

Register a new serializer. ``serializer_module`` should be the fully qualified module name for the serializer. If ``serializers`` is provided, the registration will be added to the provided dictionary. If ``serializers`` is not provided, the registration will be made directly into the global register of serializers. Adding serializers directly is not a thread-safe operation.

def unregister_serializer(format): (source)

Unregister a given serializer. This is not a thread-safe operation.

def get_serializer(format): (source)

Undocumented

def get_serializer_formats(): (source)

Undocumented

def get_public_serializer_formats(): (source)

Undocumented

def get_deserializer(format): (source)

Undocumented

def serialize(format, queryset, **options): (source)

Serialize a queryset (or any iterator that returns database objects) using a certain serializer.

def deserialize(format, stream_or_string, **options): (source)

Deserialize a stream or a string. Return an iterator that yields ``(obj, m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* -- object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name : list_of_related_objects}``.

def _load_serializers(): (source)

Register built-in and settings-defined serializers. This is done lazily so that user code has a chance to (e.g.) set up custom settings without needing to be careful of import order.

def sort_dependencies(app_list, allow_cycles=False): (source)

Sort a list of (app_config, models) pairs into a single list of models. The single list of models is sorted so that any model with a natural key is serialized before a normal model, and any model with a natural key dependency has it's dependencies serialized first. If allow_cycles is True, return the best-effort ordering that will respect most of dependencies but ignore some of them to break the cycles.