Skip to main content

A multithreaded OCR API for document processing and chunking

Project description

Chunktopus

A powerful document processing and chunking API by Unsiloed AI, featuring multithreaded OCR and intelligent document chunking using OpenAI's Vision models.

Installation

pip install chunktopus

Features

  • Process PDF, DOCX, and PPTX documents
  • Multiple chunking strategies:
    • Fixed size chunks
    • Semantic chunks (using OpenAI)
    • Page-based chunks
    • Paragraph-based chunks
    • Heading-based chunks
  • Fast parallel processing
  • RESTful API with FastAPI

Configuration

OpenAI API Key

Important: This package requires your own OpenAI API key. You must provide your API key in one of the following ways:

  1. Set it as an environment variable:
export OPENAI_API_KEY="your-api-key"
  1. Create a .env file in your project directory:
OPENAI_API_KEY=your-api-key
  1. Set it programmatically:
import os
os.environ["OPENAI_API_KEY"] = "your-api-key"

Usage

Using as a Python Package

from chunktopus import chunktopus

# Process a document with your own OpenAI API key
result = chunktopus(
    file_path="path/to/document.pdf",
    credentials={"api_key": "your-openai-api-key"}
)

# Or process a document from a URL
result = chunktopus(
    file_path="https://example.com/document.pdf",
    credentials={"api_key": "your-openai-api-key"}
)

# Or process raw text
result = chunktopus(
    text="Your text content to chunk semantically...",
    credentials={"api_key": "your-openai-api-key"}
)

# Print the results
for i, chunk in enumerate(result):
    print(f"Chunk {i+1}: {chunk['text'][:100]}...")

Using from Command Line

After installation, you can use the chunktopus command:

# Process a file with your OpenAI API key
chunktopus path/to/document.pdf --api-key "your-openai-api-key"

# Output to a file
chunktopus path/to/document.pdf --api-key "your-openai-api-key" --output results.json

# Format as text instead of JSON
chunktopus path/to/document.pdf --api-key "your-openai-api-key" --format text

Running as a REST API

from chunktopus.server import run_server

# Start the server on port 8000
run_server(port=8000)

Using the document processing functions directly

from chunktopus.services import process_document_chunking
from chunktopus.utils.chunking import ChunkingStrategy

# Set your OpenAI API key
import os
os.environ["OPENAI_API_KEY"] = "your-api-key"

# Process a document with semantic chunking
result = process_document_chunking(
    file_path="path/to/document.pdf",
    file_type="pdf",
    strategy=ChunkingStrategy.SEMANTIC,
)

# Print the results
print(f"Number of chunks: {result['total_chunks']}")
for i, chunk in enumerate(result['chunks']):
    print(f"Chunk {i+1}: {chunk['text'][:100]}...")

API Endpoints

/chunking

POST endpoint that processes a document and returns chunks.

Parameters:

  • document_file: The document file (PDF, DOCX, PPTX)
  • strategy: Chunking strategy (semantic, fixed, page, paragraph, heading)
  • chunk_size: Size of chunks for fixed strategy (default: 1000)
  • overlap: Overlap size for fixed strategy (default: 100)

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chunktopus-0.1.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chunktopus-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file chunktopus-0.1.0.tar.gz.

File metadata

  • Download URL: chunktopus-0.1.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for chunktopus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 80fbeb409e60af59ceec161f6970485103701e05485b8394a154c7f4f9319a62
MD5 c1860bc66f41443e9b67bff6d07ea4d2
BLAKE2b-256 ac3eda01bef58619f6303a5193c0a136e90aa94acfa9956d9e6ae05405cd331b

See more details on using hashes here.

File details

Details for the file chunktopus-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: chunktopus-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for chunktopus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39376645e966466aa4de40fc9e2b1e2ea1eafff140de174d6756fd97cfe19261
MD5 7357f1d7533986299f32ed1bd50c904d
BLAKE2b-256 9f198fe67bc6c96029561c465b99caa1b63ed0a43912696e489a6c73f6ffceb9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page