haul.containers package¶
Submodules¶
haul.containers.base module¶
Module contents¶
- class haul.containers.ExportContainer(exporters: List[Type[haul.serializers.Exporter]] = [], policy: Optional[haul.policy.ExportPolicy] = None, ignore_unknown=False)[source]¶
Bases:
haul.containers.base.BaseContainer
Your starting point for object export.
- export_objects(objects: Iterable[django.db.models.base.Model])[source]¶
Serializes objects and adds them to the container.
- iter_objects() Iterable[haul.types.ObjectData] [source]¶
- write(stream: IO[bytes], format: haul.types.ContainerFormat = ContainerFormat.YAML, metadata: Optional[Any] = None)[source]¶
Writes the serialized objects from the container into a data stream.
- Parameters
stream – The stream to write into. For
ContainerFormat.ZIP_*
, has to be seekable.metadata – a free-form metadata object that will be stored in the stream. It’s available later through
ImportContainer.metadata
.
- class haul.containers.ImportContainer(exporters: List[Type[haul.serializers.Exporter]] = [], policy: Optional[haul.policy.ImportPolicy] = None, ignore_unknown=False)[source]¶
Bases:
haul.containers.base.BaseContainer
Your starting point for object import.
- import_objects() haul.containers._import.ImportReport [source]¶
Untangles the object graph, relinks objects and imports them into the database.
- metadata: Any = None¶
free-form metadata as stored by
ExportContainer.write()
- read(stream: BinaryIO)[source]¶
Reads a data stream, deserializes objects in it and stores them inside the container.
This is a context manager which has to be kept open when
import_objects()
is called:c = ImportContainer(exporters=...) with open(...) as f: with c.read(f): c.import_objects()