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 | json |
Serialize data to/from JSON |
Module | base |
Module for abstract serializer/unserializer base classes. |
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
:
Function | get_serializer |
Undocumented |
Constant | BUILTIN_SERIALIZERS |
Undocumented |
Class | BadSerializer |
Stub serializer to hold exception raised during registration |
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. |
Function | deserialize |
No summary |
Function | get_deserializer |
Undocumented |
Function | get_public_serializer_formats |
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. |
Variable | _serializers |
Undocumented |
dict[ str, str]
=
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.
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.