chunkr-ai


Namechunkr-ai JSON
Version 0.0.40 PyPI version JSON
download
home_pageNone
SummaryPython client for Chunkr: open source document intelligence
upload_time2025-02-17 18:42:52
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT License Copyright (c) 2025 Lumina AI INC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Chunkr Python Client

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

## Getting Started

You can get an API key from [Chunkr](https://chunkr.ai) or deploy your own Chunkr instance. For self-hosted deployment options, check out our [deployment guide](https://github.com/lumina-ai-inc/chunkr/tree/main?tab=readme-ov-file#self-hosted-deployment-options).

For more information about the API and its capabilities, visit the [Chunkr API docs](https://docs.chunkr.ai).

## Installation

```bash
pip install chunkr-ai
```

## Usage

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

### Synchronous Usage

```python
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

```python
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:

```python
# 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:

```python
# 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:

```python
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**
  ```python
  from chunkr_ai.models import ChunkProcessing
  config = Configuration(
      chunk_processing=ChunkProcessing(target_length=1024)
  )
  ```
- **Expires In**
  ```python
  config = Configuration(expires_in=3600)
  ```

- **High Resolution**
  ```python
  config = Configuration(high_resolution=True)
  ```

- **JSON Schema**
  ```python
  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**
  ```python
  config = Configuration(ocr_strategy=OcrStrategy.AUTO)
  ```

- **Segment Processing**
  ```python
  from chunkr_ai.models import SegmentProcessing, GenerationConfig, GenerationStrategy
  config = Configuration(
      segment_processing=SegmentProcessing(
          page=GenerationConfig(
              html=GenerationStrategy.LLM,
              markdown=GenerationStrategy.LLM
          )
      )
  )
  ```

- **Segmentation Strategy**
  ```python
  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:
```python
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:

```python
# 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()
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "chunkr-ai",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Ishaan Kapoor <ishaan@lumina.sh>",
    "download_url": "https://files.pythonhosted.org/packages/83/30/d3f6b6ecbd232080079528f530a535d7cf55d4ef862bbcf8210c48b6efeb/chunkr_ai-0.0.40.tar.gz",
    "platform": null,
    "description": "# Chunkr Python Client\n\nThis provides a simple interface to interact with the Chunkr API.\n\n## Getting Started\n\nYou can get an API key from [Chunkr](https://chunkr.ai) or deploy your own Chunkr instance. For self-hosted deployment options, check out our [deployment guide](https://github.com/lumina-ai-inc/chunkr/tree/main?tab=readme-ov-file#self-hosted-deployment-options).\n\nFor more information about the API and its capabilities, visit the [Chunkr API docs](https://docs.chunkr.ai).\n\n## Installation\n\n```bash\npip install chunkr-ai\n```\n\n## Usage\n\nThe `Chunkr` client works seamlessly in both synchronous and asynchronous contexts.\n\n### Synchronous Usage\n\n```python\nfrom chunkr_ai import Chunkr\n\n# Initialize client\nchunkr = Chunkr()\n\n# Upload a file and wait for processing\ntask = chunkr.upload(\"document.pdf\")\nprint(task.task_id)\n\n# Create task without waiting\ntask = chunkr.create_task(\"document.pdf\")\nresult = task.poll()  # Check status when needed\n\n# Clean up when done\nchunkr.close()\n```\n\n### Asynchronous Usage\n\n```python\nfrom chunkr_ai import Chunkr\nimport asyncio\n\nasync def process_document():\n    # Initialize client\n    chunkr = Chunkr()\n\n    try:\n        # Upload a file and wait for processing\n        task = await chunkr.upload(\"document.pdf\")\n        print(task.task_id)\n\n        # Create task without waiting\n        task = await chunkr.create_task(\"document.pdf\")\n        result = await task.poll()  # Check status when needed\n    finally:\n        await chunkr.close()\n\n# Run the async function\nasyncio.run(process_document())\n```\n\n### Concurrent Processing\n\nThe client supports both async concurrency and multiprocessing:\n\n```python\n# Async concurrency\nasync def process_multiple():\n    chunkr = Chunkr()\n    try:\n        tasks = [\n            chunkr.upload(\"doc1.pdf\"),\n            chunkr.upload(\"doc2.pdf\"),\n            chunkr.upload(\"doc3.pdf\")\n        ]\n        results = await asyncio.gather(*tasks)\n    finally:\n        await chunkr.close()\n\n# Multiprocessing\nfrom multiprocessing import Pool\n\ndef process_file(path):\n    chunkr = Chunkr()\n    try:\n        return chunkr.upload(path)\n    finally:\n        chunkr.close()\n\nwith Pool(processes=3) as pool:\n    results = pool.map(process_file, [\"doc1.pdf\", \"doc2.pdf\", \"doc3.pdf\"])\n```\n\n### Input Types\n\nThe client supports various input types:\n\n```python\n# File path\nchunkr.upload(\"document.pdf\")\n\n# Opened file\nwith open(\"document.pdf\", \"rb\") as f:\n    chunkr.upload(f)\n\n# PIL Image\nfrom PIL import Image\nimg = Image.open(\"photo.jpg\")\nchunkr.upload(img)\n```\n\n### Configuration\n\nYou can customize the processing behavior by passing a `Configuration` object:\n\n```python\nfrom chunkr_ai.models import (\n    Configuration, \n    OcrStrategy, \n    SegmentationStrategy, \n    GenerationStrategy\n)\n\nconfig = Configuration(\n    ocr_strategy=OcrStrategy.AUTO,\n    segmentation_strategy=SegmentationStrategy.LAYOUT_ANALYSIS,\n    high_resolution=True,\n    expires_in=3600,  # seconds\n)\n\n# Works in both sync and async contexts\ntask = chunkr.upload(\"document.pdf\", config)  # sync\ntask = await chunkr.upload(\"document.pdf\", config)  # async\n```\n\n#### Available Configuration Examples\n\n- **Chunk Processing**\n  ```python\n  from chunkr_ai.models import ChunkProcessing\n  config = Configuration(\n      chunk_processing=ChunkProcessing(target_length=1024)\n  )\n  ```\n- **Expires In**\n  ```python\n  config = Configuration(expires_in=3600)\n  ```\n\n- **High Resolution**\n  ```python\n  config = Configuration(high_resolution=True)\n  ```\n\n- **JSON Schema**\n  ```python\n  config = Configuration(json_schema=JsonSchema(\n      title=\"Sales Data\",\n      properties=[\n          Property(name=\"Person with highest sales\", prop_type=\"string\", description=\"The person with the highest sales\"),\n          Property(name=\"Person with lowest sales\", prop_type=\"string\", description=\"The person with the lowest sales\"),\n      ]\n  ))\n  ```\n\n- **OCR Strategy**\n  ```python\n  config = Configuration(ocr_strategy=OcrStrategy.AUTO)\n  ```\n\n- **Segment Processing**\n  ```python\n  from chunkr_ai.models import SegmentProcessing, GenerationConfig, GenerationStrategy\n  config = Configuration(\n      segment_processing=SegmentProcessing(\n          page=GenerationConfig(\n              html=GenerationStrategy.LLM,\n              markdown=GenerationStrategy.LLM\n          )\n      )\n  )\n  ```\n\n- **Segmentation Strategy**\n  ```python\n  config = Configuration(\n      segmentation_strategy=SegmentationStrategy.LAYOUT_ANALYSIS  # or SegmentationStrategy.PAGE\n  )\n  ```\n\n## Environment Setup\n\nYou can provide your API key and URL in several ways:\n1. Environment variables: `CHUNKR_API_KEY` and `CHUNKR_URL`\n2. `.env` file\n3. Direct initialization:\n```python\nchunkr = Chunkr(\n    api_key=\"your-api-key\",\n    url=\"https://api.chunkr.ai\"\n)\n```\n\n## Resource Management\n\nIt's recommended to properly close the client when you're done:\n\n```python\n# Sync context\nchunkr = Chunkr()\ntry:\n    result = chunkr.upload(\"document.pdf\")\nfinally:\n    chunkr.close()\n\n# Async context\nasync def process():\n    chunkr = Chunkr()\n    try:\n        result = await chunkr.upload(\"document.pdf\")\n    finally:\n        await chunkr.close()\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2025 Lumina AI INC  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Python client for Chunkr: open source document intelligence",
    "version": "0.0.40",
    "project_urls": {
        "Homepage": "https://chunkr.ai"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "dc8b7289e1e00446093cf58a365c5542ed40bc132a3c123dc1857bf965418562",
                "md5": "81ba733f574931960e4739beefc36bb1",
                "sha256": "1d92a9298df4208587a25b7d5e95937edae99f1a1991d96c0b0b970d5749b30d"
            },
            "downloads": -1,
            "filename": "chunkr_ai-0.0.40-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "81ba733f574931960e4739beefc36bb1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 14492,
            "upload_time": "2025-02-17T18:42:50",
            "upload_time_iso_8601": "2025-02-17T18:42:50.386023Z",
            "url": "https://files.pythonhosted.org/packages/dc/8b/7289e1e00446093cf58a365c5542ed40bc132a3c123dc1857bf965418562/chunkr_ai-0.0.40-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8330d3f6b6ecbd232080079528f530a535d7cf55d4ef862bbcf8210c48b6efeb",
                "md5": "a6385bd2469c73eeeb27e930095c686c",
                "sha256": "f49b80612dcd03ad0b7fb35e944d18cf6ab461bf5435d0c310d379acd4694c3d"
            },
            "downloads": -1,
            "filename": "chunkr_ai-0.0.40.tar.gz",
            "has_sig": false,
            "md5_digest": "a6385bd2469c73eeeb27e930095c686c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14881,
            "upload_time": "2025-02-17T18:42:52",
            "upload_time_iso_8601": "2025-02-17T18:42:52.338292Z",
            "url": "https://files.pythonhosted.org/packages/83/30/d3f6b6ecbd232080079528f530a535d7cf55d4ef862bbcf8210c48b6efeb/chunkr_ai-0.0.40.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-17 18:42:52",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "chunkr-ai"
}
        
Elapsed time: 7.01984s