macholib
Mach-O header analysis and editing
What it is and what it does
macholib is a pure-Python library for reading and modifying Mach-O headers, the binary executable format used by macOS. Despite targeting a platform-specific format, it is written to be platform and endian independent, making it portable across systems. The library is commonly used as a dependency analysis tool to understand which dynamic libraries a macOS binary depends on, and to rewrite dylib load commands so they use relative paths like @executable_path instead of absolute paths.
The package is typically integrated into macOS build and packaging workflows, particularly in tools that need to analyze or relocate binaries. It provides both a programmatic API for working with Mach-O structures and command-line utilities (accessed via `python -m macholib`) for common tasks like dumping binary information, finding dependencies, and creating standalone application bundles.
Use it for:
- Analyze dependencies of macOS binaries to understand which dylibs they load at runtime.
- Rewrite dylib references in Mach-O headers to use relative paths for relocatable application bundles.
- Inspect and debug Mach-O headers and load commands in binary files during macOS development.
- Automate binary relocation tasks in build pipelines that package Python applications for macOS.
- Parse and validate Mach-O structures in custom macOS tooling or security analysis workflows.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Analyzes and edits Mach-O headers, the executable format used by macOS, and rewrites dylib references to be @executable_path relative.
Yes, if you are doing macOS binary analysis or packaging. The low install friction, permissive MIT license, and lack of known vulnerabilities make it a safe choice. However, the aging maintenance status (265 days since last release) means you should verify that recent macOS SDK features are supported if you need to work with newly compiled binaries.
Install
macholib on PyPI
pip
pip install macholibuv
uv add macholibpoetry
poetry add macholibInstalling macholib
Before you install
Low install friction with a single pure-Python dependency (altgraph). Maintenance status is aging—last release 265 days ago—but the repository remains active with recent commits and no archived status.
License in practice
MIT license permits commercial and private use with minimal restrictions, making it safe to include in most projects.
Quickstart
pip install macholib
from macholib.MachO import MachO
m = MachO('/path/to/binary')
for header in m.headers:
print(header)
Requires a Mach-O binary file to analyze; intended for macOS development workflows.
Verify before relying
- Whether the package is actively maintained or in maintenance-only mode given the aging status and 265-day release gap.
- Real-world performance characteristics when processing large or complex binaries.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — altgraph |
| Maintenance | aging — 265 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,658,604/month — #2,954 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: macholib-1.16.4-py2.py3-none-any.whl
Keywords: Mach-O, dyld
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
liefLIEF parses, modifies, and abstracts binary…
permissive · top 5,000 on PyPI
delocateDelocate finds and relocates dynamic libraries…
permissive · top 15,000 on PyPI
pyobjc-framework-OpenDirectoryProvides Python bindings to macOS's…
permissive · top 15,000 on PyPI
ropperRopper displays binary file metadata and…
permissive · top 15,000 on PyPI
fb-idbA command-line and Python client for automating…
permissive · top 15,000 on PyPI
membrowseAnalyzes binary size and memory footprint of…
unclear · top 15,000 on PyPI
readlineProvides GNU readline library support for…
copyleft · top 15,000 on PyPI
pyobjc-framework-ExecutionPolicyProvides Python bindings for macOS's…
permissive · top 15,000 on PyPI
find-exeFinds executables on the system matching…
unclear · top 15,000 on PyPI
pyobjc-framework-VideoToolboxProvides Python bindings to macOS's…
permissive · top 15,000 on PyPI