On this page
  1. shutil.make_archive
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from shutil import make_archive
help(make_archive)

Linked from

Related notes