Python builder for generating OVAPortableText / Report Profile v1 JSON documents
Project description
OVAPortableText
OVAPortableText is a Python authoring package for building JSON documents that conform to the OVA Report Profile v1.0 protocol.
OVAPortableText 是一个 Python 端的协议生成包,用于创建符合 OVA Report Profile v1.0 协议的 JSON 文档。
It is not a PDF renderer. Its job is to help Python code produce a typed, validated, protocol-aligned document payload that can be handed off to a downstream renderer.
它不是 PDF 渲染器。它的职责是帮助 Python 代码以强类型、可校验、可维护的方式生成协议 JSON,再交给下游渲染器处理。
1. What this package is for / 这个包解决什么问题
Use OVAPortableText when you need to:
适合在以下场景使用 OVAPortableText:
- build report JSON in Python instead of hand-writing nested dictionaries
在 Python 中构建报告 JSON,而不是手工拼接多层嵌套 dict - keep document structure aligned with the protocol
让文档结构始终与协议保持一致 - validate registry references, IDs, anchors, sections, and text-layer semantics before handoff
在交给下游之前先校验 registry 引用、ID、anchor、章节树和文本层语义 - generate reusable assets / datasets / bibliography / footnotes / glossary registries
生成可复用的 assets / datasets / bibliography / footnotes / glossary 顶层 registry - hand a stable JSON contract to a Java or other downstream renderer
给 Java 或其他下游渲染器提供稳定 JSON 合同
OVAPortableText is especially useful when the rendering stack and the authoring stack are separated.
当“内容生成端”和“渲染端”分离时,OVAPortableText 尤其有价值。
2. What this package is not / 这个包不做什么
OVAPortableText does not try to:
OVAPortableText 不负责:
- lay out final PDF pages
最终 PDF 页面排版 - decide exact typography, spacing, page breaking, or printer behavior
精确的字体、间距、分页、打印行为 - replace your Java / web / document renderer
替代你的 Java / Web / 文档渲染器
The package ends at structured JSON generation + validation + debugging support.
本包的职责边界到 结构化 JSON 生成 + 校验 + 调试辅助 为止。
3. Current protocol scope implemented by the package / 当前包已实现的协议范围
This package intentionally implements the stable, author-facing subset of Report Profile v1.0.
当前包刻意只实现了 Report Profile v1.0 中已经稳定、适合作者侧使用的那部分能力。
Currently implemented / 当前已实现:
- top-level document skeleton
顶层文档骨架schemaVersion / meta / theme / assets / datasets / bibliography / footnotes / glossary / sections
- section-tree-first authoring
以章节树为核心的 authoring 方式 - Portable Text style text blocks
Portable Text 风格文本块_type="block"_type="span"marks / markDefslistItem / level
- protocol text styles
协议定义的文本样式normalblockquotecaptionfigure_captiontable_captionequation_captionsmallprintleadquote_sourcesubheading
- decorator marks
装饰 marksstrongemunderlinecode
- inline references / annotations
行内引用 / 注解linkxrefcitation_reffootnote_refglossary_terminline_mathhard_break
- block objects
块级对象imagecharttablemath_blockcallout
- registries
顶层 registryassets.images / logos / backgrounds / icons / attachmentsdatasets.charts (pie)datasets.tables (record / grid)datasets.metricsbibliographyfootnotesglossary
- validation, resolver, numbering, round-trip IO
校验、解析器、编号、读写回转
Not yet first-class authoring helpers / 暂未形成一等 authoring helper 的能力:
- reserved taxonomy items that exist in the protocol but are not yet stabilized in the package
协议里已预留、但还未在包里稳定暴露 helper 的 taxonomy 项 - renderer-side visual contracts
渲染器侧视觉合同 - PDF pagination / page layout decisions
PDF 分页 / 页面布局决策
4. Repository layout / 仓库结构
OVAPortableText/
├── src/ova_portable_text/ # package source / 包源码
├── examples/ # runnable examples / 可直接运行的示例脚本
├── docs/ # user-facing docs / 面向使用者的文档
├── tests/ # test suite / 测试集
├── README.md # project overview / 项目总览
├── PROTOCOL.md # OVAPortableText PROTOCOL / 协议文档
├── CHANGELOG.md # release history / 版本变更历史
└── pyproject.toml # packaging config / 打包配置
Recommended reading order for new users:
新用户建议阅读顺序:
README.mdPROTOCOL.mddocs/QUICKSTART.mddocs/API_REFERENCE.mdexamples/
5. Installation / 安装
5.1 Install from PyPI / 从 PyPI 安装
pip install OVAPortableText
5.2 Local editable install / 本地可编辑安装
pip install -e .
5.3 Python import name / Python 导入名
import ova_portable_text
Package name on PyPI: OVAPortableText
PyPI 包名:OVAPortableText
Import name in Python: ova_portable_text
Python 导入名:ova_portable_text
6. Quick start / 快速开始
from ova_portable_text import create_document
report = create_document(
title="Patent Valuation Report",
language="en",
documentType="valuationReport",
strict_ids=True,
)
intro = report.new_section(id="sec-intro", level=1, title="Executive Summary")
intro.append_lead("This report is generated as protocol-aligned JSON.")
intro.append_paragraph("The renderer will consume the exported JSON payload.")
method = intro.new_subsection(id="sec-intro-method", title="Methodology")
method.append_paragraph("The protocol separates registries from body instances.")
report.assert_valid()
print(report.to_json(indent=2))
Why this is the recommended style / 为什么推荐这种写法:
- start from one
Document
从一个Document开始 - append sections and registries incrementally
逐步追加 section 和 registry - validate before handoff
在交接下游前先校验
7. Core authoring workflow / 核心 authoring 工作流
7.1 Build the registries first / 先准备 registry
For reusable resources and datasets, prefer:
对于会被正文引用的资源和数据,优先使用 registry:
assets.images / logos / backgrounds / icons / attachmentsdatasets.charts / tables / metricsbibliography / footnotes / glossary
7.2 Build the section tree second / 再构建章节树
Sections are the formal document structure.
章节树是正式文档结构。
Use:
推荐用法:
Document.new_section(...)Section.new_subsection(...)Section.append_paragraph(...)Section.append_*_with_caption(...)
7.3 Validate early / 尽早校验
validation = report.validate()
print(validation.to_text())
7.4 Fail fast before handoff / 交接下游前强制校验
report.assert_valid()
7.5 Export JSON / 导出 JSON
report.save_json("build/report.json")
8. Capability map / 能力地图
8.1 Top-level metadata and registries / 顶层元信息与 registry
You can author:
可构造:
metathemeassetsdatasetsbibliographyfootnotesglossarysections
8.2 Text layer / 文本层
You can author:
可构造:
- paragraphs
- lists
- blockquotes
- captions
- lead paragraphs
- subheadings
- decorator marks
- annotation
markDefs - inline references
8.3 Registry-backed block objects / registry 引用型块对象
You can author body instances that reference top-level registries:
可以在正文中构造引用顶层 registry 的实例对象:
image→assets.images[]chart→datasets.charts[]table→datasets.tables[]math_blockcallout
8.4 Table modes / 表格模式
The package supports both protocol table modes:
当前包支持协议中的两种表格模式:
recordfor regular structured tables
record:规则结构化表格gridfor irregular / merged / layout-oriented tables
grid:不规则 / 跨行跨列 / 偏版式表格
8.5 Image-source model / 图片来源模型
The package uses the protocol’s pure imageSource model:
当前包使用协议中的纯 imageSource 模型:
kind="url"kind="embedded"
9. Example scripts / 样例代码总览
All examples live under examples/.
所有示例脚本都在 examples/ 目录下。
Basic authoring / 基础 authoring
examples/minimal_report.py
Smallest valid document. / 最小可用文档examples/save_and_load_json_demo.py
Save JSON to disk and load it back. / JSON 落盘与读回examples/builder_numbering_roundtrip_demo.py
Builder API + numbering + round-trip. / builder API + 编号 + 回转
Text and inline semantics / 文本层与行内语义
examples/marks_and_lists_report.py
Decorator marks, lists, and text styles. / 装饰 marks、列表和文本样式examples/inline_objects_report.py
Inline refs such asxref,citation_ref,footnote_ref,glossary_term,hard_break. / 行内引用对象示例examples/references_and_marks_demo.py
MarkDefs-based inline annotations, bibliography / footnotes / glossary linking, and inline math. / 基于 markDefs 的行内注解、参考文献/脚注/术语引用与行内公式
Registries, assets, and datasets / registry、资源与数据集
examples/registry_blocks_report.py
Registry-first images / charts / tables. / 先 registry 后正文引用examples/extended_registries_demo.py
Logos, backgrounds, icons, attachments, metrics. / logo、背景、图标、附件、指标集examples/image_sources_demo.py
URL and embedded image sources for images / logos / backgrounds / icons. / URL 与内嵌图片来源模式examples/grid_table_demo.py
recordandgridtable datasets, including duplicate headers and irregular layouts. /record与grid表格模式示例
Validation and debugging / 校验与调试
examples/validation_context_demo.py
Validation output with context. / 带上下文的校验输出examples/validation_report.py
End-to-end validation report generation. / 端到端校验报告示例
Full reports / 更完整的报告示例
examples/full_report_workflow_demo.py
End-to-end authoring workflow. / 端到端报告构造流程examples/patent_valuation_style_report.py
Business-shaped valuation report example. / 更接近业务报告的估值示例
10. Documentation map / 文档导航
docs/QUICKSTART.md
Start here for first-time usage. / 新手快速上手docs/API_REFERENCE.md
Practical API map for the public surface. / 面向使用者的 API 地图docs/EXAMPLES.md
Example index and recommended reading order. / 示例索引与阅读顺序docs/REAL_WORLD_RECIPES.md
Practical authoring patterns. / 更贴近真实业务的写法模式docs/PROTOCOL_ALIGNMENT.md
What part of the protocol is already aligned. / 协议对齐范围说明docs/VALIDATION_AND_RESOLVER.md
Validation, resolver, and debugging workflow. / 校验、解析器与调试流程docs/TEST_MATRIX.md
Test coverage map. / 测试覆盖范围docs/USER_TESTING_CHECKLIST.md
Manual user testing checklist. / 人工回测清单docs/PUBLISHING_CHECKLIST.md
Release checklist. / 发布清单
11. Development notes / 开发说明
11.1 Recommended development command / 推荐开发命令
python -m pytest -q
11.2 Build sanity check / 打包自检
python -m build
twine check dist/*
11.3 Release note / 发布说明
The current package version is 0.1.3.
当前包版本为 0.1.3。
This branch of the package is aligned to the current Report Profile v1.0 protocol draft used in this repository.
当前这版包对齐的是本仓库内维护的 Report Profile v1.0 协议版本。
12. License / 许可
See LICENSE.
详见 LICENSE。
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
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 ovaportabletext-0.1.4.tar.gz.
File metadata
- Download URL: ovaportabletext-0.1.4.tar.gz
- Upload date:
- Size: 123.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbf5f6e6e0f6e7315b1c96cc62df976b49a03ea0205f3ae590ace594fbe69d4b
|
|
| MD5 |
b766d7a4899ce2044a017dc47d438242
|
|
| BLAKE2b-256 |
31ee1e5ec605638d551f7571e37d36f7540b5fe8bd9a211cc4743f7cb5935cee
|
File details
Details for the file ovaportabletext-0.1.4-py3-none-any.whl.
File metadata
- Download URL: ovaportabletext-0.1.4-py3-none-any.whl
- Upload date:
- Size: 57.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc67586a54b3e0016a386863bdba1481e7552fa67ecfa08f799d5f136b5a2b00
|
|
| MD5 |
2275bf32cf8635d7113124744c9b406a
|
|
| BLAKE2b-256 |
a51cf61397bcf1886c8cf7485ba1f9851d1c1fe18c394039fc6d7575bbd25d6e
|