On this page
shutil.make_archive
Prev: shutil.ignore_patterns | Up: shutil | Next: shutil.move
Rel: shutil.chown, shutil.copy, shutil.copy2, shutil.copyfile
Ref: docs.python.org — shutil.make_archive
Tags: #public #python3 #stdlib #shutil
Import
import shutil
from shutil import make_archive
Signature & Overview
shutil.make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0, dry_run=0, owner=None, group=None, logger=None)
Create an archive file (eg. zip or tar).
Usage
from pathlib import Path
import shutil
import tempfile
with tempfile.TemporaryDirectory() as tmp:
src = Path(tmp) / "pkg"
src.mkdir()
(src / "readme.txt").write_text("hi", encoding="utf-8")
archive = shutil.make_archive(str(Path(tmp) / "release"), "zip", root_dir=src)
assert Path(archive).name == "release.zip" and Path(archive).exists()
Gotchas
base_nameomits the extension:make_archive("release", "zip", ...)automatically appends.zipand returns the full output path.- Watch
root_dirvs.base_dir: Passroot_dir=srcto zip the contents ofsrcwithout baking absolute parent folders into the archive.
REPL Inspect
from shutil import make_archive
help(make_archive)
Linked from
Related notes
- tuts/python3/stdlib_module/shutil/ignore_patterns Linked here; links to this page; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/move Linked here; links to this page; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/shutil/chown Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copy Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copy2 Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copyfile Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copyfileobj shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copymode shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copystat shared tags: #shutil, #stdlib