skillfed

polyfile-weave

A utility to recursively map the structure of a file.

polyfile-weave v0.5.9 935.5K downloads/30d#4,694 on PyPI2
Permissive license AGING released

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-weave

uv

uv add polyfile-weave

poetry

poetry add polyfile-weave

Installing 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

Development Status :: 4 - BetaEnvironment :: ConsoleIntended Audience :: Science/ResearchLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: Python :: 3 :: OnlyTopic :: SecurityTopic :: Software Development :: TestingTopic :: Utilities

Tags

file type identificationpolyglot file detectionembedded file extractionfile format analysisrecursive file parsinglibmagic python implementationfile structure mapping
file-analysispolyglot-detectionforensics

More Utilities packages