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 |
XML serializer. |
From __init__.py
:
Class |
|
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 |
Undocumented |
Function | get |
Undocumented |
Function | get |
Undocumented |
Function | get |
Undocumented |
Function | register |
Register a new serializer. |
Function | serialize |
Serialize a queryset (or any iterator that returns database objects) using a certain serializer. |
Function | sort |
Sort a list of (app_config, models) pairs into a single list of models. |
Function | unregister |
Unregister a given serializer. This is not a thread-safe operation. |
Constant | BUILTIN |
Undocumented |
Function | _load |
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 |
Undocumented
Value |
|
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.
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}``.
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.
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.