Monoscript is a Python tool designed to merge multi-file modules into a single, self-contained Python file. This output file can then be used as a portable standalone script/module or included in other projects without the hassle of adding it to the packaging system.
Features
Multiple ``__all__`` Strategies:
``AUTO``: Automatically determines __all__ definitions by combining explicit __all__ definitions and implicit internal imports from the module’s __init__.py.
``custom``: Allows you to set a custom __all__ definition.
``INIT``: Takes only the explicit __all__ definition from __init__.py.
``NONE``: No __all__ definition is added.
Removes Internal Imports: Internal imports within the module are automatically removed.
Organized Imports: Top-level imports are cleaned up and organized. Redundant imports are removed.
Test Scripts Integration: Merges and/or runs your test scripts.
Metadata Support: Includes support for metadata such as author, description, version, requirements, and more.
Limitations
Monoscript is intended for small modules and should not be used for larger projects. Merging code from multiple files into a single file can cause unwanted behaviors:
No Namespaces: All code is merged into a single file, which may result in global name conflicts. The script warns you if conflicts are detected.
Complex Top-Level Imports: Imports within conditional statements (e.g., if statements or try/except blocks) are not reorganized and are left as-is.
Complex ``__all__`` Assignments: Only simple assignments or incremental updates to lists of strings are supported. Complex operations on __all__ are ignored.
Installation
Install Monoscript using pip:
pip install monoscript
Alternatively, download monoscript.py from releases and use it directly.
Usage
Command Line
Run Monoscript via the command line:
python -m monoscript path/to/module --output-dir="dist"
Or directly:
python monoscript.py path/to/module --output-dir="dist"
Usage:
$ python3 monoscript.py --help
usage: monoscript.py [-h] [-D OUTPUT_DIR] [--process-all {NONE,AUTO,INIT}] [--custom-all CUSTOM_ALL] [--additional-all ADDITIONAL_ALL] [--no-organize-imports] [--module-name MODULE_NAME] [--module-version MODULE_VERSION]
[--module-description MODULE_DESCRIPTION] [--author AUTHOR] [--license LICENSE] [--project-website PROJECT_WEBSITE] [--requirements REQUIREMENTS] [--requirements-filename REQUIREMENTS_FILENAME]
[--additional-headers ADDITIONAL_HEADERS] [--test-scripts-dirname TEST_SCRIPTS_DIRNAME] [--merge-test-scripts] [--no-run-test-scripts]
module_path
A Python tool that merges multi-file modules into a single, self-contained script.
positional arguments:
module_path Path to the module directory.
options:
-h, --help show this help message and exit
-D OUTPUT_DIR, --output_dir OUTPUT_DIR
Output directory for the merged script.
--process-all {NONE,AUTO,INIT}
Strategy for processing __all__ variable.
--custom-all CUSTOM_ALL
Custom __all__ value (comma-separated).
--additional-all ADDITIONAL_ALL
Additional items to add to __all__ (comma-separated).
--no-organize-imports
Disable import organization.
--module-name MODULE_NAME
Name of the output module.
--module-version MODULE_VERSION
Module version.
--module-description MODULE_DESCRIPTION
Module description.
--author AUTHOR Author of the module.
--license LICENSE Module license.
--project-website PROJECT_WEBSITE
Project website.
--requirements REQUIREMENTS
Module requirements (comma-separated).
--requirements-filename REQUIREMENTS_FILENAME
Module requirements file name.
--additional-headers ADDITIONAL_HEADERS
Additional headers (e.g., 'Key1=Value1,Key2=Value2').
--test-scripts-dirname TEST_SCRIPTS_DIRNAME
Directory name for test scripts.
--merge-test-scripts Merge test scripts into the output.
--no-run-test-scripts
Disable running test scripts after merging.
License
Monoscript is licensed under the MIT License.
Metadata
Release files for monoscript 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| monoscript-1.0.3.tar.gz | 15.7 kB | Without provenance | Details |
Release files / monoscript-1.0.3.tar.gz
| Download URL | monoscript-1.0.3.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dab99071291258f160ef1748e3091498c54dccf120797cdac307a169de9b3a42
|
|
BLAKE2b-256 checksum How to use checksums |
c896de064bc8cfc79911d727480cd36376b046c39efe1009f0c790624c527dcb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Security for monoscript 1.0.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.