py-chunks
Part of chunk-engine — one Rust engine, three byte-identical SDKs (py-chunks · js-chunks · rs-chunks). Full documentation, playground and benchmarks: chunkengine.dev
The Python binding for chunk-engine. Turn any of 36 document formats into typed, structure-aware chunks for RAG — parsing and chunking run in a compiled Rust core, not a stack of Python dependencies.
Install
pip install py-chunks
Python 3.9+, and no runtime dependencies. The Rust engine ships compiled inside the wheel: it parses PDF itself, and vendors PDFium for the one job that needs a rasteriser — rendering a scanned PDF's pages when the file carries no embedded page image of its own.
Quick start
from py_chunks import get_chunks, stream_chunks, get_markdown
# Batch — works for every supported format
chunks = get_chunks("report.pdf", mode="semantic")
for chunk in chunks:
print(chunk["content_type"]) # "heading", "table", "semantic", …
print(chunk["content"])
print(chunk["metadata"]) # format- and mode-specific
# Streaming — one chunk at a time
for chunk in stream_chunks("large.pdf", mode="section"):
handle(chunk)
# Markdown conversion
md = get_markdown("report.docx")
Every chunk is a dict with content, content_type, and metadata.
📖 Chunking modes · Supported formats · Output schema · Metadata reference
Input sources
get_chunks / stream_chunks auto-detect the source:
| Source | Example |
|---|---|
Path (str / Path) |
get_chunks("report.pdf") |
bytes / bytearray / memoryview |
get_chunks(data, filename="report.pdf") |
File-like (BytesIO, open file) |
get_chunks(BytesIO(data), filename="doc.md") |
FastAPI / Starlette UploadFile |
get_chunks(upload_file) |
| HTTP(S) / S3 pre-signed URL | get_chunks("https://bucket.s3…/f.pdf?sig=…") |
Explicit helpers are also exported — get_chunks_from_path,
get_chunks_from_bytes, get_chunks_from_fileobj, get_chunks_from_upload,
get_chunks_from_s3_presigned_url, plus the matching stream_chunks_from_*.
A
filenameis required for bytes and unnamed file objects — dispatch is by extension.get_markdownaccepts paths, bytes, and file objects, but not URLs.
Signatures
get_chunks(
source, *,
filename: str | None = None,
mode: str = "default",
window_size: int = 3, # sliding_window
overlap: int = 1, # sliding_window (must be < window_size)
sentences_per_chunk: int = 3, # sentence
paragraphs_per_page: int = 15, # page_aware
list_images: bool = False,
) -> list[dict] | ChunksResult
stream_chunks(source, *, filename=None, mode="default", ...) -> Iterator[dict]
get_markdown(source, *, filename=None, list_images=False) -> str | MarkdownResult
Images
from py_chunks import get_chunks
result = get_chunks("report.docx", list_images=True) # -> ChunksResult
result.chunks # text chunks + content_type="image" chunks
result.images # {"7fdc906103e95537.png": b"...", ...} <16-hex content hash>.<ext>
get_markdown(..., list_images=True) returns a MarkdownResult with .markdown
(carrying  refs) and .images. Not available on stream_chunks.
Format-specific chunkers
For parameters the unified API doesn't expose (rows_per_chunk,
max_chunk_chars, sheet_names, delimiter, encoding) or for per-call
timing, import the format module directly. Each returns (chunks, timing) where
timing is {"rust_ms": …, "python_ms": …}:
from py_chunks.chunkers.xlsx import chunk_xlsx, stream_chunk_xlsx
from py_chunks.chunkers.csv import chunk_csv
chunks, timing = chunk_xlsx("data.xlsx", mode="row", rows_per_chunk=5)
chunks, timing = chunk_csv("data.csv", mode="row", delimiter="\t")
Modules: csv, doc, docx (the OOXML Word family), eml (also .mbox),
epub, html, ipynb, json (also .jsonl/.ndjson), md, msg, odf
(.odt/.odp), pdf, ppt, pptx (the OOXML PowerPoint family), rtf,
tsv, txt, xlsx (the whole spreadsheet family).
Errors
| Exception | When |
|---|---|
FileNotFoundError |
Path doesn't exist |
ValueError |
Unsupported extension, invalid mode/parameter, missing filename |
TypeError |
Unsupported source type, or an async upload.read() |
RuntimeError |
Engine-level failure (e.g. a PDF with no text layer) |
NotImplementedError |
Unsupported streaming format/mode combination |
📖 Error handling · FastAPI / Flask / Django / Litestar / aiohttp / Celery recipes
Develop
pip install maturin
maturin develop --release # rebuild the extension after any Rust change
python -m pytest -v
python -m pylint py_chunks # expected: 10.00/10
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 py_chunks-0.6.1.tar.gz.
File metadata
- Download URL: py_chunks-0.6.1.tar.gz
- Upload date:
- Size: 547.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9391d70ebb90ec15c7b6d8128cdc95d766eae3d6fbcf6fe9e32cbbde04b02483
|
|
| MD5 |
afebfcbe852d4e8f380cf3fc311061cc
|
|
| BLAKE2b-256 |
c8dc444be3ad248dfb649d3306e916cc29e446b7a21104e1130524ed7507dbcf
|
Provenance
The following attestation bundles were made for py_chunks-0.6.1.tar.gz:
Publisher:
release.yml on RanjanKudesia/py-chunks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_chunks-0.6.1.tar.gz -
Subject digest:
9391d70ebb90ec15c7b6d8128cdc95d766eae3d6fbcf6fe9e32cbbde04b02483 - Sigstore transparency entry: 2372786322
- Sigstore integration time:
-
Permalink:
RanjanKudesia/py-chunks@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/RanjanKudesia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_chunks-0.6.1-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: py_chunks-0.6.1-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 5.2 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da1efba0be00c436b82934fbc5407423d74c61537a1f21436e6d87bad1484a62
|
|
| MD5 |
ac74f633dac27415422f420d5f13e5ba
|
|
| BLAKE2b-256 |
ef5c9c41b41d26bd9400944672d51b97a4455efad7fc143fe92206b7a0928fe1
|
Provenance
The following attestation bundles were made for py_chunks-0.6.1-cp39-abi3-win_amd64.whl:
Publisher:
release.yml on RanjanKudesia/py-chunks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_chunks-0.6.1-cp39-abi3-win_amd64.whl -
Subject digest:
da1efba0be00c436b82934fbc5407423d74c61537a1f21436e6d87bad1484a62 - Sigstore transparency entry: 2372786413
- Sigstore integration time:
-
Permalink:
RanjanKudesia/py-chunks@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/RanjanKudesia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_chunks-0.6.1-cp39-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: py_chunks-0.6.1-cp39-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 5.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8e28eb4334e5ca9b64638b5646cd92ca701cbaa2519a0fcb086c1d28a9ea33e
|
|
| MD5 |
97f9fd22b0790b8e10993f6b670031f2
|
|
| BLAKE2b-256 |
93f39a65c7d193a4e699580543f342e6c7862509b6484eec911584082d58aff2
|
Provenance
The following attestation bundles were made for py_chunks-0.6.1-cp39-abi3-manylinux_2_28_x86_64.whl:
Publisher:
release.yml on RanjanKudesia/py-chunks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_chunks-0.6.1-cp39-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
a8e28eb4334e5ca9b64638b5646cd92ca701cbaa2519a0fcb086c1d28a9ea33e - Sigstore transparency entry: 2372786594
- Sigstore integration time:
-
Permalink:
RanjanKudesia/py-chunks@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/RanjanKudesia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_chunks-0.6.1-cp39-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: py_chunks-0.6.1-cp39-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afa3fef4ef583a6d8ce15c23a6e1f1faed712ebe71e9e84345f8b601b4eb301b
|
|
| MD5 |
882238e4cadaa6147f1d32c8774382ef
|
|
| BLAKE2b-256 |
9a1867ef862cb5d16de82c92eca3cf2bb04ed55410546b134055a6d2dee99105
|
Provenance
The following attestation bundles were made for py_chunks-0.6.1-cp39-abi3-manylinux_2_28_aarch64.whl:
Publisher:
release.yml on RanjanKudesia/py-chunks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_chunks-0.6.1-cp39-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
afa3fef4ef583a6d8ce15c23a6e1f1faed712ebe71e9e84345f8b601b4eb301b - Sigstore transparency entry: 2372786701
- Sigstore integration time:
-
Permalink:
RanjanKudesia/py-chunks@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/RanjanKudesia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_chunks-0.6.1-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: py_chunks-0.6.1-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.0 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71e875a9bfd7e6cc382f207dc33ce570da395753e6f108044e37a0688ac3d18a
|
|
| MD5 |
b62b6f2a1516a28340181f41f493009a
|
|
| BLAKE2b-256 |
56932725a930ebd824cb751f14aae538d540f8a94a1b65d74e398d6832f6a3c7
|
Provenance
The following attestation bundles were made for py_chunks-0.6.1-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on RanjanKudesia/py-chunks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_chunks-0.6.1-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
71e875a9bfd7e6cc382f207dc33ce570da395753e6f108044e37a0688ac3d18a - Sigstore transparency entry: 2372786502
- Sigstore integration time:
-
Permalink:
RanjanKudesia/py-chunks@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/RanjanKudesia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_chunks-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: py_chunks-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 5.2 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecbbb82aaf7a7513aeb6286349b2c4421730258ec34228874aa9beb733206e15
|
|
| MD5 |
f785041477387c4b4530e6336b28ab57
|
|
| BLAKE2b-256 |
2fa37cd4b39e012808c90e2e888a5fcc7cf96381960720de234a4e3178d7f497
|
Provenance
The following attestation bundles were made for py_chunks-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on RanjanKudesia/py-chunks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_chunks-0.6.1-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
ecbbb82aaf7a7513aeb6286349b2c4421730258ec34228874aa9beb733206e15 - Sigstore transparency entry: 2372786793
- Sigstore integration time:
-
Permalink:
RanjanKudesia/py-chunks@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/RanjanKudesia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5e1daeb46c80b7ab30713e812e59e8f8303aac03 -
Trigger Event:
push
-
Statement type: