Render ppt like a jupyter notebook
Project description
DOCX Renderer
This package lets you run your Microsoft Word documents like a script. You can insert placeholders in the document and use either a Python function or an equivalent command-line tool to convert it into an output rendered document.
Installation
pip install docx-renderer
Usage
Below is a simple example.
from docx_renderer import DOCXRenderer
p = DOCXRenderer("template.docx")
someval = "world!"
def mymethod(abc):
return f"{abc} " * 5
p.render(
"output.docx",
{
"variable": someval, "mymethod": mymethod, "myimage": "is_it_worth.png"
}
)
This will replace placeholders in the template document with the provided values.
Before
After
You can define some functions within the document itself by writing Python code in the comments section. The variables and functions in this code can be used in the main document.
For example: write the following in one of the comments in the document.
```python
def myfunc(input):
return input * 42
```
Now you can, for example, add the placeholder {{{myfunc(42)}}} in your document.
If the template document is a self-contained Python script (i.e., it does not require variable values and function definitions to be passed from outside), you can generate the output document directly from the command line using the following command.
docx-renderer input_template.docx output_file.docx
Placeholders
You can have placeholders for text, images, or tables. Placeholders can be added
as regular text. All placeholders should be enclosed within a pair
of triple braces ({{{ and }}}).
Text
Any placeholder which can be evaluated into a string can act as a text placeholder.
For example: {{{"hello " * 10/2}}} or {{{abs(-2)}}}
Image
If you have added :image() as a suffix to the Python statement, the renderer will
try to convert the value of the Python statement to a file location and insert an
image from that file location.
For example: {{{"c:\\temp\\myimage.png":image()}}}
Table
Tables are similar to images, but instead of a string, the Python
statement should evaluate to a list of lists. Then you can add :table() as a
suffix, and it will be converted to a table inside the document.
For example: {{{[["col1", "col2", "col3"],[1, 2, 3]]:table()}}} will render to
| col1 | col2 | col3 |
|---|---|---|
| 1 | 2 | 3 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docx_renderer-0.2.0.tar.gz.
File metadata
- Download URL: docx_renderer-0.2.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
356e1ca2454f24abad1669d238bba9ba91551ae7a0db43abf34e5b7e8ede6c9b
|
|
| MD5 |
e2de295b687cff127a14011852b67742
|
|
| BLAKE2b-256 |
f306a712d631054ac8753a3a87317a3e7cc99026457f82c758890615593a895a
|
Provenance
The following attestation bundles were made for docx_renderer-0.2.0.tar.gz:
Publisher:
python-publish.yml on idling-mind/docx_renderer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docx_renderer-0.2.0.tar.gz -
Subject digest:
356e1ca2454f24abad1669d238bba9ba91551ae7a0db43abf34e5b7e8ede6c9b - Sigstore transparency entry: 212165651
- Sigstore integration time:
-
Permalink:
idling-mind/docx_renderer@14b1b3227d762b344dfa0c30d357f289d6e35b95 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/idling-mind
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@14b1b3227d762b344dfa0c30d357f289d6e35b95 -
Trigger Event:
release
-
Statement type:
File details
Details for the file docx_renderer-0.2.0-py3-none-any.whl.
File metadata
- Download URL: docx_renderer-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ce4e9b9d71554ea4f19f084173416f7f8dea155297ab23c5112b1d26cc500a6
|
|
| MD5 |
a055f21bc6b6b243dcc1a19fcd1554bd
|
|
| BLAKE2b-256 |
65ac2a553c5cc841a38747d5d075d7f348de5da57cd77a3d2c6dc268c20271d7
|
Provenance
The following attestation bundles were made for docx_renderer-0.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on idling-mind/docx_renderer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docx_renderer-0.2.0-py3-none-any.whl -
Subject digest:
0ce4e9b9d71554ea4f19f084173416f7f8dea155297ab23c5112b1d26cc500a6 - Sigstore transparency entry: 212165656
- Sigstore integration time:
-
Permalink:
idling-mind/docx_renderer@14b1b3227d762b344dfa0c30d357f289d6e35b95 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/idling-mind
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@14b1b3227d762b344dfa0c30d357f289d6e35b95 -
Trigger Event:
release
-
Statement type: