Skip to main content

Chunkr Python Client

This provides a simple interface to interact with the Chunkr API.

Getting Started

You can get an API key from Chunkr or deploy your own Chunkr instance. For self-hosted deployment options, check out our deployment guide.

For more information about the API and its capabilities, visit the Chunkr API docs.

Installation

pip install chunkr-ai

Usage

The Chunkr client works seamlessly in both synchronous and asynchronous contexts.

Synchronous Usage

from chunkr_ai import Chunkr

# Initialize client
chunkr = Chunkr()

# Upload a file and wait for processing
task = chunkr.upload("document.pdf")
print(task.task_id)

# Create task without waiting
task = chunkr.create_task("document.pdf")
result = task.poll()  # Check status when needed

# Clean up when done
chunkr.close()

Asynchronous Usage

from chunkr_ai import Chunkr
import asyncio

async def process_document():
    # Initialize client
    chunkr = Chunkr()

    try:
        # Upload a file and wait for processing
        task = await chunkr.upload("document.pdf")
        print(task.task_id)

        # Create task without waiting
        task = await chunkr.create_task("document.pdf")
        result = await task.poll()  # Check status when needed
    finally:
        await chunkr.close()

# Run the async function
asyncio.run(process_document())

Concurrent Processing

The client supports both async concurrency and multiprocessing:

# Async concurrency
async def process_multiple():
    chunkr = Chunkr()
    try:
        tasks = [
            chunkr.upload("doc1.pdf"),
            chunkr.upload("doc2.pdf"),
            chunkr.upload("doc3.pdf")
        ]
        results = await asyncio.gather(*tasks)
    finally:
        await chunkr.close()

# Multiprocessing
from multiprocessing import Pool

def process_file(path):
    chunkr = Chunkr()
    try:
        return chunkr.upload(path)
    finally:
        chunkr.close()

with Pool(processes=3) as pool:
    results = pool.map(process_file, ["doc1.pdf", "doc2.pdf", "doc3.pdf"])

Input Types

The client supports various input types:

# File path
chunkr.upload("document.pdf")

# Opened file
with open("document.pdf", "rb") as f:
    chunkr.upload(f)

# PIL Image
from PIL import Image
img = Image.open("photo.jpg")
chunkr.upload(img)

Configuration

You can customize the processing behavior by passing a Configuration object:

from chunkr_ai.models import (
    Configuration, 
    OcrStrategy, 
    SegmentationStrategy, 
    GenerationStrategy
)

config = Configuration(
    ocr_strategy=OcrStrategy.AUTO,
    segmentation_strategy=SegmentationStrategy.LAYOUT_ANALYSIS,
    high_resolution=True,
    expires_in=3600,  # seconds
)

# Works in both sync and async contexts
task = chunkr.upload("document.pdf", config)  # sync
task = await chunkr.upload("document.pdf", config)  # async

Available Configuration Examples

  • Chunk Processing

    from chunkr_ai.models import ChunkProcessing
    config = Configuration(
        chunk_processing=ChunkProcessing(target_length=1024)
    )
    
  • Expires In

    config = Configuration(expires_in=3600)
    
  • High Resolution

    config = Configuration(high_resolution=True)
    
  • JSON Schema

    config = Configuration(json_schema=JsonSchema(
        title="Sales Data",
        properties=[
            Property(name="Person with highest sales", prop_type="string", description="The person with the highest sales"),
            Property(name="Person with lowest sales", prop_type="string", description="The person with the lowest sales"),
        ]
    ))
    
  • OCR Strategy

    config = Configuration(ocr_strategy=OcrStrategy.AUTO)
    
  • Segment Processing

    from chunkr_ai.models import SegmentProcessing, GenerationConfig, GenerationStrategy
    config = Configuration(
        segment_processing=SegmentProcessing(
            page=GenerationConfig(
                html=GenerationStrategy.LLM,
                markdown=GenerationStrategy.LLM
            )
        )
    )
    
  • Segmentation Strategy

    config = Configuration(
        segmentation_strategy=SegmentationStrategy.LAYOUT_ANALYSIS  # or SegmentationStrategy.PAGE
    )
    

Environment Setup

You can provide your API key and URL in several ways:

  1. Environment variables: CHUNKR_API_KEY and CHUNKR_URL
  2. .env file
  3. Direct initialization:
chunkr = Chunkr(
    api_key="your-api-key",
    url="https://api.chunkr.ai"
)

Resource Management

It's recommended to properly close the client when you're done:

# Sync context
chunkr = Chunkr()
try:
    result = chunkr.upload("document.pdf")
finally:
    chunkr.close()

# Async context
async def process():
    chunkr = Chunkr()
    try:
        result = await chunkr.upload("document.pdf")
    finally:
        await chunkr.close()

Metadata

Release files for chunkr-ai 0.3.7

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

Source distribution (sdist)

Source distribution for chunkr-ai 0.3.7
File Size Uploaded Provenance Actions
chunkr_ai-0.3.7.tar.gz 27.2 kB Without provenance Details for chunkr_ai-0.3.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chunkr-ai 0.3.7
File Interpreter ABI Platform Actions
chunkr_ai-0.3.7-py3-none-any.whl Python 3 none any Details for chunkr_ai-0.3.7-py3-none-any.whl

Total release size: 44.7 kB

Release files / chunkr_ai-0.3.7.tar.gz

Download URL chunkr_ai-0.3.7.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
89eb4c218fb910ee758a72eaeaf73da28f828a143c8f35f2c30e86bc823463e0
BLAKE2b-256 checksum
How to use checksums
df3b5281d8eeb216f5ea96e4672b83b75a9a71a80228b54e820ed585e91d7b4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.5

Release files / chunkr_ai-0.3.7-py3-none-any.whl

Download URL chunkr_ai-0.3.7-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78e4a384b043ea7a8d587ca53db433323e158cc197d9e65e660cbab200cf6d23
BLAKE2b-256 checksum
How to use checksums
706b6f50079b946cffcd25acd0af3a21c36dbf3c3f99b5e4a217ef211baed8b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.5

Security for chunkr-ai 0.3.7

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.3.7 This release

2 release files No 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