Skip to main content

Moedularizer

PyPI version CI License

Automatically modularize monolithic Python files into packages.

Given a single Python file, moedularizer analyzes symbol dependencies, clusters related code, and generates a proper package structure with cross-module imports and a re-exporting __init__.py.

Install

pip install moedularizer

Zero dependencies beyond the Python standard library.

Quick Start

# Command line
python -m moedularizer.cli monolith.py ./my_package/ --package-name my_package

# Dry run (preview without writing)
python -m moedularizer.cli monolith.py ./my_package/ --package-name my_package --dry-run

# Verbose output
python -m moedularizer.cli monolith.py ./my_package/ --package-name my_package --verbose
# Programmatic API
from moedularizer import Moedularizer, MoedularizerConfig
from pathlib import Path

config = MoedularizerConfig(
    source_file=Path("monolith.py"),
    output_dir=Path("my_package/"),
    package_name="my_package",
)

mod = Moedularizer(config)
result = mod.modularize(Path("monolith.py").read_text())

print(f"Generated {len(result.modules)} modules")
print(f"Preserved exports: {len(result.preserved_exports)}")

for warning in result.warnings:
    print(f"Warning: {warning}")

if not result.errors:
    mod.write(result)

How It Works

  1. Analyze — Parse Python source via ast, extract symbols (classes, functions, constants) and their dependencies
  2. Cluster — Group symbols by dependency density, respecting configurable heuristics (separate dataclasses, constants, pure functions)
  3. Generate — Produce module files with proper from pkg.mod import sym cross-references
  4. Validate — Check for circular imports, API preservation, module naming, symbol coverage

Options

Flag Default Description
--max-symbols 10 Max symbols per generated module
--separate-dataclasses True Put dataclasses in their own module
--separate-constants True Put constants in their own module
--absolute-imports True Use absolute imports
--dry-run False Preview without writing files
--no-backup False Skip backing up existing files
--verbose False Detailed symbol/dependency/cluster output
--force-groupings — Force symbols together: name=Sym1,Sym2

License

MIT

Metadata

Release files for moedularizer 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moedularizer 0.2.0
File Size Uploaded Provenance Actions
moedularizer-0.2.0.tar.gz 170.4 kB With provenance Details for moedularizer-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for moedularizer 0.2.0
File Interpreter ABI Platform Actions
moedularizer-0.2.0-py3-none-any.whl Python 3 none any Details for moedularizer-0.2.0-py3-none-any.whl

Total release size: 236.0 kB

Release files / moedularizer-0.2.0.tar.gz

Download URL moedularizer-0.2.0.tar.gz
Size 170.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e2684bc8abd6e90b6a90e04190bd5b3b820df26d1d2e6782c459857197008504
BLAKE2b-256 checksum
How to use checksums
a98a8d52f6fe245d7ddfe3f4b5c5c15561dbb6b982e57cc494c47ff8fba8bced
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Release files / moedularizer-0.2.0-py3-none-any.whl

Download URL moedularizer-0.2.0-py3-none-any.whl
Size 65.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4809360c253207e580d4a12e2dd92102c4ba12f95d1778c32150d5d070ff584
BLAKE2b-256 checksum
How to use checksums
601b7b2939b6ae3125578518e7789714f0159a292d16b44a3100bc642c8659ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Security for moedularizer 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for moedularizer-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page