Rapid DOCX generation from Jinja2 templates – YAML + pydantic + Typer.
Project description
scribe
Rapid DOCX generation from Jinja2 templates – YAML + pydantic + Typer
scribe turns structured data (YAML / JSON / CSV / Excel) into polished Microsoft Word documents using docxtpl templates.
It targets bulk workflows (tens - hundreds of files) yet remains friendly for single-document scripting.
Installation
pip install scribe # from PyPI (coming soon)
# or from source
pip install -e .
Python 3.10 + and LibreOffice/Microsoft Word (to open the results) are
required. On first use it will create outputs/ directory next to the project root.
Quick Start
# see registered templates
$ scribe list-templates
• annual_report templates/annual_report.docx
# scan disk for unregistered templates
$ scribe list-templates --all
# generate one file
$ scribe generate annual_report data/report.yaml
# bulk render from CSV (one row per document)
$ scribe generate annual_report data/bulk.csv --delimiter ';'
Global flags:
| flag | default | description |
|---|---|---|
--log-level |
INFO | DEBUG / INFO / WARNING / ERROR |
--log-json / --no-log-json |
- | one-line JSON logs (for CI / k8s) |
Discover and register new templates
$ scribe discover-templates
✓ 3 template(s) written to config/discovered_templates.yaml
# merge the snippet into config/app.yaml
Public API (import and use in your own scripts)
from pathlib import Path
from decimal import Decimal
from scribe import (
DataLoader,
TemplateFinder,
get_settings,
make_context,
generate_docx,
)
# 1) pick a template
tpl_cfg = TemplateFinder().discover()[0] # annual_report
# 2) load data
raw = DataLoader.load(Path("data/report.yaml")) # dict or list[dict]
# 3) validate via side-car schema (if any)
ctx = make_context(tpl_cfg.path, raw) # BaseDocContext or subclass
# 4) render
out_path = generate_docx(ctx, tpl_cfg, Path("outputs"))
print("wrote", out_path)
Configuration
| source | precedence |
|---|---|
| CLI kwargs | highest |
SCRIBE_* environment variables |
|
.env file in CWD |
|
config/app.yaml |
base |
Environment variables
| name | example | purpose |
|---|---|---|
SCRIBE_OUTPUT_DIR |
/tmp/reports |
override default outputs dir |
SCRIBE_TEMPLATES_DIR |
/srv/docx:/opt/private (path-sep list) |
additional template search roots |
SCRIBE_LOG_JSON |
1 |
enable JSON logs in any context |
Template validation (optional)
Add a file next to your template:
# templates/annual_report.schema.yaml
client_name: str
report_date: date
summary: str
revenue: Decimal
details: List[scribe.models.custom:Detail]
make_context will generate a Pydantic model on the fly and coerce/validate incoming data before rendering.
Rich text/conditional styling
config/app.yaml
templates:
- name: annual_report
path: templates/annual_report.docx
output_naming: "{client_name}_{report_date:%Y%m%d}.docx"
options:
richtext:
status:
- when: { equals: "APPROVED" }
style: { bold: true, color: "008000" }
- when: { equals: "REJECTED" }
style: { bold: true, color: "CC0000" }
In your DOCX reference {{ richtext_status }} to get coloured text; the plain {{ status }} remains unchanged.
Development & tests
# Linting & type-checking
ruff check scribe
mypy scribe
# Test suite
pytest -q --cov=scribe
Commit conventions
- Black-formatted, fully-typed code
- NumPy-style docstrings
- CI matrix: Python 3.10 & 3.11
Feel free to open issues or PRs – contributions welcome!
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 scribe_templates-0.3.1.tar.gz.
File metadata
- Download URL: scribe_templates-0.3.1.tar.gz
- Upload date:
- Size: 29.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c792c331e4fb1dca96e83f7712df9657cafdce877115e079dd60a8e312d5846a
|
|
| MD5 |
f58b99478802c30c71201c527517c216
|
|
| BLAKE2b-256 |
981531f65d5a4c85aa81adc4edf68aafd0cfe07973c7bff45c7085288c4c1dee
|
Provenance
The following attestation bundles were made for scribe_templates-0.3.1.tar.gz:
Publisher:
publish.yml on aswann45/scribe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scribe_templates-0.3.1.tar.gz -
Subject digest:
c792c331e4fb1dca96e83f7712df9657cafdce877115e079dd60a8e312d5846a - Sigstore transparency entry: 331276158
- Sigstore integration time:
-
Permalink:
aswann45/scribe@ec708306b66119d5d88f2c5fc4d3afcee67f2bdf -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/aswann45
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ec708306b66119d5d88f2c5fc4d3afcee67f2bdf -
Trigger Event:
release
-
Statement type:
File details
Details for the file scribe_templates-0.3.1-py3-none-any.whl.
File metadata
- Download URL: scribe_templates-0.3.1-py3-none-any.whl
- Upload date:
- Size: 37.6 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 |
0986b9aa6a8bbf0296bf3391122a951d329ec29090cc771017b42c37c905da7c
|
|
| MD5 |
db3adddd0d799d5f385eb9eb0616841d
|
|
| BLAKE2b-256 |
47235f1e28aa7bef037e4f2ece323f3d6539163b90c854da43f2693bf5a1b696
|
Provenance
The following attestation bundles were made for scribe_templates-0.3.1-py3-none-any.whl:
Publisher:
publish.yml on aswann45/scribe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scribe_templates-0.3.1-py3-none-any.whl -
Subject digest:
0986b9aa6a8bbf0296bf3391122a951d329ec29090cc771017b42c37c905da7c - Sigstore transparency entry: 331276179
- Sigstore integration time:
-
Permalink:
aswann45/scribe@ec708306b66119d5d88f2c5fc4d3afcee67f2bdf -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/aswann45
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ec708306b66119d5d88f2c5fc4d3afcee67f2bdf -
Trigger Event:
release
-
Statement type: