Skip to main content

Logo

Description

PyPI - Version PyPI - Python Version PyPI - Status PyPI - Downloads PyPI - License Gitea Issues Gitea Last Commit

Muppy means MarkUp Preprocessor for Python. If you want some Python in markup, not some markup in Python—Muppy is probably the thing you need.


WARNING: This script is using exec(). Be careful when you execute Muppy with a file you get from strangers, and keep in mind that it can be harmful as any other Python script. Use Muppy script standalone from the git repo if you have reasons not to trust the wheel.

Installation

The script is pure Python and a part of PyPI, so can be installed via pip:

python3 -m pip install muppy

So, what does it do, exactly?

Technically, Muppy gets comments in various formats and executes them as Python code. Any text between comment blocks is treated as string literals.

Basic HTML example

Contents of test.html. Mind Python indentation after <!-- (py):, placeholders ?????, and empty lines <!-- (py):-->:

<!-- (py):
result = ?????-->
<html>
 <head>
  <title>
   <!-- (py):if lang == 'en':--><!-- (py): result += ?????-->Hello world!<!-- (py):-->
   <!-- (py):if lang == 'ru':--><!-- (py): result += ?????-->Привет, мир!<!-- (py):-->
<!-- (py):result += ?????-->
  </title>
 </head>
 <body>
 </body>
</html>
<!-- (py):print(result)-->

Shell command:

muppy compile -s xml -i test.html -d "lang = 'en'"

The preprocessor code to be executed:

# string literals
__muppy0 = ''
__muppy1 = '\n<html>\n <head>\n  <title>\n   '
__muppy2 = ''
__muppy3 = 'Hello world!'
__muppy4 = '\n   '
__muppy5 = ''
__muppy6 = 'Привет, мир!'
__muppy7 = '\n'
__muppy8 = '\n  </title>\n </head>\n <body>\n </body>\n</html>\n'
__muppy9 = '\n'

# definitions
lang = 'en'

# code
result = __muppy1
if lang == 'en':
 result += __muppy3

if lang == 'ru':
 result += __muppy6

result += __muppy8
print(result)

Result:

<html>
 <head>
  <title>
   Hello world!
  </title>
 </head>
 <body>
 </body>
</html>

Comment styles

For now, Muppy supports the following comment styles (-s):

Style Start tag End tag Description
xml <!-- (py): --> Any XML format: HTML, SVG, FB2, etc.
c /* (py): */ C, C++, CSS, PHP, etc.
tex % (py): Newline TeX-compatible markup
shell # (py): Newline Bash, Python, etc.

Definitions

You can define (-d) any variables as you do in common Python code:

muppy compile -s tex -i test.html -d 'var1 = 10' 'some_list = ["a", "b", "c"]'

Bugs

Feel free to report bugs and request features here.

Metadata

Release files for muppy 1.0.3

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

Source distribution (sdist)

Source distribution for muppy 1.0.3
File Size Uploaded Provenance
muppy-1.0.3.tar.gz 7.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 12.8 kB

Release files / muppy-1.0.3.tar.gz

Download URL muppy-1.0.3.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
037c1aa0fb4f47aa297b7868654112e04c06f51a616a2cf52cc1e9cdb542f325
BLAKE2b-256 checksum
How to use checksums
0ca02f2545813aec1ee42cd93818131003c6bd6065098641868ce2585031d092
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / muppy-1.0.3-py3-none-any.whl

Download URL muppy-1.0.3-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3c5378879479d531d4a125bcc8413878dc4f10af8f0275d673a641f3cdb2e17
BLAKE2b-256 checksum
How to use checksums
d9bab6896ede75605f2acc00846e62386c4eb4ef61f00cb817fd1026d6737ea7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Security for muppy 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.

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