Weavon for Python
This package converts, compares, chunks and checks documents in the Python process. It also gives a typed Pandoc AST for filters that you write in Python.
The package uses the Weavon C library (libweavon_c) through ctypes. It starts no subprocess and needs no Python package outside the standard library. It replaces pypandoc and JSON filters that run as separate processes.
Install
-
Build the C library.
cargo build -p weavon-c --release
-
Install the package.
pip install ./bindings/python
-
Tell the package where the library is. Set
WEAVON_LIB_PATHto the library file or to its directory.export WEAVON_LIB_PATH="$PWD/target/release/libweavon_c.dylib"
The package looks for the library in this order.
- The
lib_pathargument ofWeavonClient. - The
WEAVON_LIB_PATHenvironment variable. - The
weavonpackage directory. - The search path of the system linker.
The library file is libweavon_c.dylib on macOS, libweavon_c.so on Linux and weavon_c.dll on Windows. If the package cannot find the library, it raises WeavonLibraryNotFoundError.
Convert
import weavon
html = weavon.convert("# Hello\n\nSome *text*.", "html", "markdown")
# Binary formats give bytes. The built-in engine makes PDF 1.7.
pdf = weavon.convert_bytes("# Report", "pdf", "markdown")
# Keep only the main article of a web page, and make the links absolute.
text = weavon.convert(page, "markdown", "html",
main_content=True, clean=True, base_url="https://example.com/")
With no input format, Weavon finds the format from the input. CompatMode.PANDOC_3_13 gives output that is byte-identical to Pandoc 3.13.
from weavon import CompatMode
weavon.convert("*x*", "html", "markdown", mode=CompatMode.PANDOC_3_13)
Compare
weavon.diff("The old text.", "The new text.") # CriticMarkup text
weavon.diff(old, new, "html", author="Ann") # HTML text
docx = weavon.diff(old, new, "docx", author="Ann") # bytes with tracked changes
pdf = weavon.diff(old, new, "pdf") # bytes, changes in color
Chunk for retrieval
for chunk in weavon.chunk(text, "markdown", max_tokens=512, overlap_tokens=64):
print(chunk["heading_path"], chunk["markdown"])
Check
findings = weavon.lint(text, "markdown") # a list of findings
sarif = weavon.lint(text, "markdown", format="sarif") # a SARIF 2.1.0 log
report = weavon.lint(text, "markdown", format="human") # text
Filters in the process
parse reads a document into a typed Document. walk applies your callbacks to the nodes. render writes the result. All three steps run in the process.
import weavon
from weavon import ast as A
doc = weavon.parse("# Hello\n\nVisit *world*.", "markdown")
def shift_headers(node):
if node.t == "Header":
node.level += 1
return node
return None
def strong_emphasis(node):
if node.t == "Emph":
return A.Strong(node.content)
return None
doc = weavon.walk(doc, block=shift_headers, inline=strong_emphasis)
print(weavon.render(doc, "html"))
A callback returns one of these values.
Nonekeeps the node.- A node replaces the node.
- A list of nodes puts the nodes in the place of the node. An empty list deletes the node.
The walk is bottom-up. A callback gets a node with filtered children. The walk reaches nodes in metadata, notes, table cells, captions, lists and quotes. The meta callback gets the metadata dict and can return a new dict. The walk does not change the input document.
Each node keeps the exact Pandoc JSON structure in node.t and node.c. A node type that the package does not know keeps its content, so Document.from_json(raw).to_json() gives the same JSON. Typed accessors give access to common fields, for example node.text, node.content, node.attr, node.level and node.target. The weavon.ast module has a constructor for each common node, for example Str, Para, Header, Link, Div and Table.
Move from pypandoc
Change one import line, and your pypandoc calls run in the process with no pandoc program.
from weavon import compat as pypandoc
html = pypandoc.convert_text("# Hello", "html", format="md")
pypandoc.convert_file("report.md", "pdf", outputfile="report.pdf")
convert_text, convert_file and get_pandoc_version take the same arguments as in pypandoc, and the output matches Pandoc 3.13. A PDF comes from the built-in engine, so it needs no TeX. The library writes the document body for text formats, so extra_args accepts --pdf-engine=embedded and, for binary formats such as DOCX, --standalone. Any other option raises weavon.compat.CompatError, which is a RuntimeError like the errors of pypandoc.
Errors
Each error is a WeavonError with a status attribute.
| Class | Status | Cause |
|---|---|---|
WeavonInvalidArgError |
1 | An argument is not valid. A string argument with a NUL character is an example. |
WeavonConvertError |
2 | The conversion failed. An unknown format is an example. |
WeavonPanicError |
3 | Weavon stopped on an internal error. |
WeavonUtf8Error |
4 | A text input or a string argument is not valid UTF-8. |
Run the tests
WEAVON_LIB_PATH=/path/to/libweavon_c.dylib python3 -m unittest discover -s bindings/python/tests -v
License
MIT OR Apache-2.0
Metadata
Release files for weavon 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| weavon-0.1.0-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for weavon-0.1.0-py3-none-win_amd64.whl |
| weavon-0.1.0-py3-none-manylinux_2_35_x86_64.whl | Python 3 | none | Linux glibc 2.35+ x86-64 | Details for weavon-0.1.0-py3-none-manylinux_2_35_x86_64.whl |
| weavon-0.1.0-py3-none-manylinux_2_35_aarch64.whl | Python 3 | none | Linux glibc 2.35+ ARM64 | Details for weavon-0.1.0-py3-none-manylinux_2_35_aarch64.whl |
| weavon-0.1.0-py3-none-macosx_12_0_x86_64.whl | Python 3 | none | macOS 12.0+ x86-64 | Details for weavon-0.1.0-py3-none-macosx_12_0_x86_64.whl |
| weavon-0.1.0-py3-none-macosx_12_0_arm64.whl | Python 3 | none | macOS 12.0+ ARM64 | Details for weavon-0.1.0-py3-none-macosx_12_0_arm64.whl |
Total release size: 31.8 MB
Release files / weavon-0.1.0-py3-none-win_amd64.whl
| Download URL | weavon-0.1.0-py3-none-win_amd64.whl |
|---|---|
| Size | 6.3 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
9a80210e3b22bc287aba1dd1235d536862fdeba5a280ae7c86001152c0fffb1b
|
|
BLAKE2b-256 checksum How to use checksums |
ba72f10241c3e636feaeb4f1fbb996dd28d7e56393d0c810812bda10a23f1dbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logRelease files / weavon-0.1.0-py3-none-manylinux_2_35_x86_64.whl
| Download URL | weavon-0.1.0-py3-none-manylinux_2_35_x86_64.whl |
|---|---|
| Size | 6.7 MB |
| Tags | Linux glibc 2.35+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
79a5980c6f796d4ee0646de38dc4e75e2c5e0439811e828cb6d57d5b70be4a10
|
|
BLAKE2b-256 checksum How to use checksums |
24ce69233897d6f6ddfb360a29d73cbd5111301df9bd1070e5d172f0311a8d39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logRelease files / weavon-0.1.0-py3-none-manylinux_2_35_aarch64.whl
| Download URL | weavon-0.1.0-py3-none-manylinux_2_35_aarch64.whl |
|---|---|
| Size | 6.5 MB |
| Tags | Linux glibc 2.35+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
386ee2011bc0511b4db672dc7a8e73c455d234ee47654cbff5d0558fedd90d70
|
|
BLAKE2b-256 checksum How to use checksums |
b31856c3a94cf358fb2a5b7cda7776eb8fdf0f5236047e2f1486c8ffe874f476
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logRelease files / weavon-0.1.0-py3-none-macosx_12_0_x86_64.whl
| Download URL | weavon-0.1.0-py3-none-macosx_12_0_x86_64.whl |
|---|---|
| Size | 6.2 MB |
| Tags | Python 3 macOS 12.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
e471920e75a4e4a3512d5c5b4ec44ad76ec2d9235667f45724a09cd361753d84
|
|
BLAKE2b-256 checksum How to use checksums |
53578320c33be9799fdfd42afb827e1a60b8a3d37ed4ca84019186e2c3fea3a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logRelease files / weavon-0.1.0-py3-none-macosx_12_0_arm64.whl
| Download URL | weavon-0.1.0-py3-none-macosx_12_0_arm64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | Python 3 macOS 12.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
58bd856ccc55a1daaedfa90777f4b0acb4dc4d0e486fe8f5e8f9de25d6601535
|
|
BLAKE2b-256 checksum How to use checksums |
11af0edd4320738e9afceb8b0787b08b56775ad0816222da76c4b06b60aaefe2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logSecurity for weavon 0.1.0
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.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for weavon-0.1.0-py3-none-win_amd64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logA 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.