---
source: https://iinventedlight.com/library/notes/python-compileall.md
title: "Python compileall: byte-compile a tree of library files"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, compileall — Byte-compile Python libraries; CPython, compileall documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-compileall"
tags: [python, compileall, bytecode, pyc, install]
client: Librarian
sources:
  - id: S1
    title: "compileall — Byte-compile Python libraries"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/compileall.html
    accessed: 2026-11-23
    license: "PSF License Version 2"
  - id: S2
    title: "compileall documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/compileall.rst
    accessed: 2026-11-23
    license: "PSF License Version 2"
---
# Python compileall: byte-compile a tree of library files
**Answer:** This module provides utility functions that support installing Python libraries. The functions compile Python source files in a directory tree. Cached byte-code files can be created at library installation time.

## Compiling a directory tree

The module provides utility functions that support installing Python libraries.

Python source files in a directory tree are compiled by those functions.

compile_dir recursively descends the directory tree named by dir, compiling all .py files along the way.

This module does not work or is not available on WebAssembly.

## Install-time caches in the source docs

You can create the cached byte-code files at library installation time with this module.

Users who don't have write permission to the library directories can still use those files.

The module can work as a script, using python -m compileall.

Positional arguments are files to compile or directories that contain source files, traversed recursively.

## See also

- [python-importlib](https://iinventedlight.com/library/notes/python-importlib/)
- [python-zipapp](https://iinventedlight.com/library/notes/python-zipapp/)
- [python-dis](https://iinventedlight.com/library/notes/python-dis/)

## Claims

- id: C1
  claim: The helpers compile Python source files in a directory tree.
  source: S1
  evidence: "compile Python source files in a directory tree"

- id: C2
  claim: The functions support installing Python libraries.
  source: S1
  evidence: "utility functions to support installing Python libraries"

- id: C3
  claim: Caches can be created at library installation time.
  source: S2
  evidence: "cached byte-code files at library installation time"

- id: C4
  claim: That helps users who cannot write to the library directories.
  source: S2
  evidence: "users who don't have write permission to the library directories"

## Sources

- [S1] compileall — Byte-compile Python libraries. Python Software Foundation. https://docs.python.org/3/library/compileall.html . License: PSF License Version 2. Accessed 2026-11-23.

- [S2] compileall documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/compileall.rst . License: PSF License Version 2. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, compileall — Byte-compile Python libraries; CPython, compileall documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
