polyfile-weave
A utility to recursively map the structure of a file.
What it is and what it does
PolyFile is a file analysis utility that identifies file types and recursively maps their internal structure, including detecting polyglots (files with multiple valid formats), chimeras, and embedded files. It includes a cleanroom pure-Python implementation of libmagic that supports 263 MIME types and can act as a drop-in replacement for the Unix `file` command, but with the added capability to recursively identify files embedded within other files—similar to binwalk.
The package supports parsing and semantic mapping of PDF, ZIP, JPEG/JFIF, iNES, and any format specified in a Kaitai Struct grammar. It offers multiple output formats (including an extension of the SBuD JSON format), an interactive debugger for troubleshooting file matching and parsing, and both command-line and programmatic interfaces. The package automatically patches a known issue with Kaitai Struct's auto-generated Python code on import.
Use it for:
- Analyze polyglot files to understand all embedded file types and their byte offsets within a single file.
- Recursively extract and identify all files embedded within ZIP archives or PDF documents programmatically.
- Generate interactive HTML hex viewers of files with semantic structure annotations for forensic analysis.
- Debug why a file is not being classified with the expected MIME type using the built-in interactive debugger.
- Replace the system `file` command in scripts while gaining recursive file identification capabilities.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Identifies and maps the semantic and syntactic structure of files, including polyglots and embedded files, with a pure-Python libmagic implementation that can replace the `file` command and recursively extract embedded content.
Yes, if you need recursive file identification and polyglot detection. The pure-Python libmagic implementation and low install friction make it accessible, and Apache 2.0 licensing poses no restrictions. However, the aging maintenance status (204 days since last release, minimal repository activity) and 14 runtime dependencies warrant caution for production use—verify that the package remains stable for your specific file formats and that dependency bloat is acceptable for your use case.
Install
polyfile-weave on PyPI
pip
pip install polyfile-weaveuv
uv add polyfile-weavepoetry
poetry add polyfile-weaveInstalling polyfile-weave
Before you install
Low install friction with a pure-Python wheel. Maintenance status is aging—last release was 204 days ago and the repository has minimal activity (2 stars), though it remains unarchived and the codebase was last updated on 2026-01-22.
License in practice
Licensed under Apache 2.0 (permissive), which allows commercial and private use with minimal restrictions, making it safe to adopt in most projects.
Quickstart
pip install polyfile-weave
from polyfile.magic import MagicMatcher
with open("file_to_test", "rb") as f:
for match in MagicMatcher.DEFAULT_INSTANCE.match(f.read()):
for mimetype in match.mimetypes:
print(f"Matched MIME: {mimetype}")
Java must be installed before installing from source, as it is required to run the Kaitai Struct compiler for file format definitions.
Verify before relying
- Whether the 14 runtime dependencies (including graphviz, Pillow, pdfminer.six) are all truly required for basic file identification or only for specific features.
- Current stability and bug-fix rate given the aging maintenance status and minimal repository activity.
- Whether the automatic patching of the Kaitai Struct Python reserved keyword issue works reliably across all installation scenarios.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 14 — abnf, chardet, cint, fickling, filelock, graphviz, intervaltree, jinja2, kaitaistruct, networkx, Pillow, pyreadline3, pyyaml, pdfminer.six |
| Maintenance | aging — 204 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 935,471/month — #4,694 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: polyfile_weave-0.5.9-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
python-magicIdentifies file types by reading file headers…
permissive · top 1,000 on PyPI
libmagicProvides Python bindings to the libmagic…
copyleft · top 15,000 on PyPI
python-magic-binIdentifies file types by examining file headers…
permissive · top 15,000 on PyPI
typecodeDetects file types and MIME types using…
permissive · top 15,000 on PyPI
file-magicfile-magic provides a Python interface to…
permissive · top 15,000 on PyPI
puremagicIdentifies file types by analyzing magic…
permissive · top 5,000 on PyPI
filetypeInfers file type and MIME type by examining…
permissive · top 1,000 on PyPI
typecode-libmagicProvides a prebuilt native libmagic binary and…
copyleft · top 15,000 on PyPI
mo-parsingmo-parsing is a PEG parser generator that lets…
permissive · top 15,000 on PyPI
identifyIdentifies file types by examining file paths,…
permissive · top 1,000 on PyPI