Skip to main content

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

Install the prebuilt wheel from PyPI. Wheels bundle libweavon_c for macOS, Linux, and Windows, so no Rust toolchain or WEAVON_LIB_PATH is needed.

pip install weavon

Build from source

  1. Build the C library with the dist-lib profile (which keeps panic = "unwind" for safe C ABI error boundaries).

    cargo build -p weavon-c --profile dist-lib
    
  2. Install the local package.

    pip install ./bindings/python
    
  3. Tell the package where the library is. Set WEAVON_LIB_PATH to the library file or to its directory.

    export WEAVON_LIB_PATH="$PWD/target/dist-lib/libweavon_c.dylib"
    

The package looks for the library in this order.

  1. The lib_path argument of WeavonClient.
  2. The WEAVON_LIB_PATH environment variable.
  3. The weavon package directory.
  4. 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.

  • None keeps 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.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for weavon 0.2.0
File Actions
weavon-0.2.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for weavon-0.2.0-py3-none-win_amd64.whl
weavon-0.2.0-py3-none-manylinux_2_35_x86_64.whl Python 3 none Linux glibc 2.35+ x86-64 Details for weavon-0.2.0-py3-none-manylinux_2_35_x86_64.whl
weavon-0.2.0-py3-none-manylinux_2_35_aarch64.whl Python 3 none Linux glibc 2.35+ ARM64 Details for weavon-0.2.0-py3-none-manylinux_2_35_aarch64.whl
weavon-0.2.0-py3-none-macosx_12_0_x86_64.whl Python 3 none macOS 12.0+ x86-64 Details for weavon-0.2.0-py3-none-macosx_12_0_x86_64.whl
weavon-0.2.0-py3-none-macosx_12_0_arm64.whl Python 3 none macOS 12.0+ ARM64 Details for weavon-0.2.0-py3-none-macosx_12_0_arm64.whl

Total release size: 31.6 MB

Release files / weavon-0.2.0-py3-none-win_amd64.whl

Download URL weavon-0.2.0-py3-none-win_amd64.whl
Size 6.2 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
8fae9c94177ec217a19642917bac23fc1111b6851e9a1ab07b13c0d45ec479e5
BLAKE2b-256 checksum
How to use checksums
4c37cb15c9c93246bd606fe6b7a111918bd97f546fb37138f3f9f9157781ae18
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 4, 2026.

Transparency log

Release files / weavon-0.2.0-py3-none-manylinux_2_35_x86_64.whl

Download URL weavon-0.2.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
316d0c624793419332fe9aef4f6109ac3a77843f45045f5cb4d4251c20172449
BLAKE2b-256 checksum
How to use checksums
f97c30ed460865a205f3b3c81352d5851ed573a0d99731031533cfbda40debe9
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 4, 2026.

Transparency log

Release files / weavon-0.2.0-py3-none-manylinux_2_35_aarch64.whl

Download URL weavon-0.2.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
5a2d94a774d511622f33bb8bc76921da021b73125afdff194dc069874dea49c2
BLAKE2b-256 checksum
How to use checksums
b2f1526e4a4cecd7913e51dcfc6e741112739dbf209f24a3ef1280b72c8c0d5f
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 4, 2026.

Transparency log

Release files / weavon-0.2.0-py3-none-macosx_12_0_x86_64.whl

Download URL weavon-0.2.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
7161adfeb2bd8b4c95badde94b7bf0196bd7950143d1ea1e0b8e4c90f1b06f0d
BLAKE2b-256 checksum
How to use checksums
1d8cdd146fe738531d9aa986986f8b1ccdbb67a243656e6b930ce451485a8b27
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 4, 2026.

Transparency log

Release files / weavon-0.2.0-py3-none-macosx_12_0_arm64.whl

Download URL weavon-0.2.0-py3-none-macosx_12_0_arm64.whl
Size 6.0 MB
Tags Python 3 macOS 12.0+ ARM64
SHA-256 checksum
How to use checksums
fb4708ce2521aa4424930f2b8aa75920cd5081f7425199cdde73b5331bd4b854
BLAKE2b-256 checksum
How to use checksums
6d7ee24743b1eb4c3e3793d95bd956d91e4f4a1bcbd81d08c786f47256367515
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 4, 2026.

Transparency log

Security for weavon 0.2.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.

Select from 5 files

Attestation for weavon-0.2.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 4, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page