# Installation

Install chunk-engine for Python (pip), JavaScript (npm), or Rust (cargo).

Pick your language — the install command follows the switcher at the top of the
page.

<InstallTabs />

## Python — py-chunks

- **Python 3.9+**. The Rust engine ships compiled inside the wheel.
- One runtime dependency: [`pypdfium2`](https://pypi.org/project/pypdfium2/)
  (installed automatically; bundles PDFium for PDF support).

```bash
pip install py-chunks
```

## JavaScript — js-chunks

- **Node 18+**, Bun, Deno, and browsers/bundlers. The engine is compiled to
  **WASM** and instantiated lazily on first call.
- Filesystem-path sources are Node/Bun only — elsewhere pass bytes with a
  `filename`.

```bash
npm install js-chunks
```

  PDF parsing uses the optional peer dependency
  [`@llamaindex/liteparse-wasm`](https://www.npmjs.com/package/@llamaindex/liteparse-wasm)
  (the same liteparse version as the Rust engine, so output is byte-identical).
  Install it to enable `.pdf` sources:

  ```bash
  npm install @llamaindex/liteparse-wasm
  ```

  If you already have PDF markdown from another parser, chunk it directly with
  `chunkPdfMarkdown(markdown, totalPages, opts?)` — no peer dependency needed.

## Rust — rs-chunks

The reference engine. Published to crates.io as `rs-chunks`; the library import
name is `chunks_rs`.

```bash
cargo add rs-chunks
```

```rust
use chunks_rs::{get_chunks, get_markdown};
```

  Native PDF (via the `liteparse` crate / PDFium) is on by default through the
  `pdf-native` feature. Disable default features for `wasm32` targets, where PDF
  markdown is produced host-side and fed to `pdf::chunk_pdf_markdown`.

## Verify

```python
from py_chunks import get_chunks, stream_chunks, get_markdown

# Batch — works for every supported format
chunks = get_chunks("document.pdf")
chunks = get_chunks("notes.md",  mode="semantic")
chunks = get_chunks("deck.pptx", mode="sliding_window", window_size=3, overlap=1)

for chunk in chunks:
    print(chunk["content"], chunk["content_type"], chunk["metadata"])

# Streaming — constant memory over huge files
for chunk in stream_chunks("large.pdf", mode="section"):
    handle(chunk)

# Markdown conversion
md = get_markdown("report.docx")
```

```ts
import { getChunks, streamChunks, getMarkdown } from "js-chunks";

// Batch — works for every supported format
let chunks = await getChunks("./document.pdf");
chunks = await getChunks("./notes.md",  { mode: "semantic" });
chunks = await getChunks("./deck.pptx", { mode: "sliding_window", windowSize: 3, overlap: 1 });

for (const c of chunks) {
  console.log(c.content, c.contentType, c.metadata);
}

// Streaming — constant memory over huge files
for await (const chunk of streamChunks("./large.pdf", { mode: "section" })) {
  handle(chunk);
}

// Markdown conversion
const md = await getMarkdown("./report.docx");
```

```rust
use chunks_rs::{get_chunks, get_markdown};

// Batch — dispatch by extension. Positional args:
// get_chunks(path, mode, window_size, overlap, sentences_per_chunk, paragraphs_per_page)
let chunks = get_chunks("document.pdf", "default", 3, 1, 3, 15)?;
let chunks = get_chunks("notes.md",     "semantic", 3, 1, 3, 15)?;

for c in &chunks {
    println!("[{}] {}", c.content_type, c.content);
    // c.metadata is a serde_json::Value with format-specific provenance
}

// Streaming yields the same chunks, one at a time
use chunks_rs::formats::csv;
for c in csv::stream("data.csv", "row", 10, 5, 1, true, None, "utf-8", true)? {
    let c = c?;
}

// One-shot Markdown conversion
let md = get_markdown("report.docx")?;
```
