Settings¶
Configure django-snapshots by setting SNAPSHOTS in your Django settings module.
Both a plain dict and a typed SnapshotSettings instance
are accepted; either form is normalised to SnapshotSettings during
AppConfig.ready().
# settings.py — dict style
SNAPSHOTS = {
"STORAGE": {
"BACKEND": "django_snapshots.storage.LocalFileSystemBackend",
"OPTIONS": {"location": "/var/backups/snapshots"},
},
"SNAPSHOT_FORMAT": "directory",
"DEFAULT_ARTIFACTS": ["database", "media", "environment"],
"PRUNE": {"keep": 30, "keep_daily": 14, "keep_weekly": 8},
"METADATA": {"env": "production"},
}
# settings.py — typed style (better IDE support)
from django_snapshots import SnapshotSettings, PruneConfig
from django_snapshots.storage import LocalFileSystemBackend
SNAPSHOTS = SnapshotSettings(
storage=LocalFileSystemBackend(location="/var/backups/snapshots"),
snapshot_format="directory",
prune=PruneConfig(keep=30, keep_daily=14, keep_weekly=8),
metadata={"env": "production"},
)
SnapshotSettings¶
- class django_snapshots.SnapshotSettings(*args, **kwargs)[source]¶
Bases:
ConfigBaseTop-level django-snapshots configuration.
Set as the SNAPSHOTS Django setting. Accepts either a plain dict or a SnapshotSettings instance; both are normalised to SnapshotSettings in AppConfig.ready().
- __init__(storage: ~typing.Any = None, snapshot_format: ~django_snapshots.defines.SnapshotFormat = SnapshotFormat.DIRECTORY, snapshot_name: str | ~typing.Callable[[~datetime.datetime], str] = '{timestamp_utc}', metadata: dict[str, ~typing.Any] = <factory>, encryption: ~typing.Any = None, database_connectors: dict[str, ~typing.Any] = <factory>, prune: ~django_snapshots.settings.PruneConfig | None = None) None¶
- prune: PruneConfig | None = None¶
Default retention policy used by
snapshots prunewhen no flags are given.
- snapshot_format: SnapshotFormat = 'directory'¶
Snapshot container format:
"directory"(default) or"archive".
- snapshot_name: str | Callable[[datetime], str] = '{timestamp_utc}'¶
Template string or callable for generating snapshot names.
- storage: Any = None¶
Storage backend instance. Defaults to
LocalFileSystemBackendrooted at the current working directory when not explicitly configured.
PruneConfig¶
- class django_snapshots.PruneConfig(keep: int | None = None, duration: relativedelta | None = None, max_size: int | None = None)[source]¶
Bases:
ConfigBaseRetention policy for the prune command.
Policies use union semantics: a snapshot is kept if any policy retains it.
- __init__(keep: int | None = None, duration: relativedelta | None = None, max_size: int | None = None) None¶