Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scribe_templates-0.3.1.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scribe_templates-0.3.1-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

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

Hashes for scribe_templates-0.3.1.tar.gz
Algorithm Hash digest
SHA256 c792c331e4fb1dca96e83f7712df9657cafdce877115e079dd60a8e312d5846a
MD5 f58b99478802c30c71201c527517c216
BLAKE2b-256 981531f65d5a4c85aa81adc4edf68aafd0cfe07973c7bff45c7085288c4c1dee

See more details on using hashes here.

Provenance

The following attestation bundles were made for scribe_templates-0.3.1.tar.gz:

Publisher: publish.yml on aswann45/scribe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scribe_templates-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for scribe_templates-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0986b9aa6a8bbf0296bf3391122a951d329ec29090cc771017b42c37c905da7c
MD5 db3adddd0d799d5f385eb9eb0616841d
BLAKE2b-256 47235f1e28aa7bef037e4f2ece323f3d6539163b90c854da43f2693bf5a1b696

See more details on using hashes here.

Provenance

The following attestation bundles were made for scribe_templates-0.3.1-py3-none-any.whl:

Publisher: publish.yml on aswann45/scribe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page