Metadata-Version: 2.4
Name: contractkit
Version: 0.2.0
Summary: A Python library for contract analysis using LLMs
Author-email: Shubham Kaushik <eskaykaushik2@gmail.com>
Project-URL: Homepage, https://github.com/Eskaykaushik/contractKit
Project-URL: Repository, https://github.com/Eskaykaushik/contractKit
Keywords: contracts,legal,ai,llm,openai,pdf
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openai
Requires-Dist: pypdf
Requires-Dist: python-dotenv
Provides-Extra: ocr
Requires-Dist: pypdfium2; extra == "ocr"
Requires-Dist: pytesseract; extra == "ocr"
Requires-Dist: Pillow; extra == "ocr"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Dynamic: license-file

# contractkit

A simple Python library for contract intelligence using LLMs.

[![PyPI](https://img.shields.io/pypi/v/contractkit.svg)](https://pypi.org/project/contractkit/)
[![Python Versions](https://img.shields.io/pypi/pyversions/contractkit.svg)](https://pypi.org/project/contractkit/)
[![License: MIT](https://img.shields.io/pypi/l/contractkit.svg)](https://opensource.org/licenses/MIT)

## Features

- Extract text from PDF contracts, with an OCR fallback for scanned documents
- Parse and clean contract text into clauses
- Extract structured clauses using OpenAI
- Summarize contracts for business understanding

## Installation

Requires Python 3.8 or later.

```bash
pip install contractkit            # core
pip install contractkit[ocr]       # + OCR fallback for scanned PDFs
```

## Usage

```python
from contractkit import ContractClient, read_pdf

client = ContractClient()  # uses OPENAI_API_KEY

text = read_pdf("contract.pdf")
clauses = client.extract_clauses(text)
summary = client.summarize_contract(text)

# Or run the whole pipeline in one call:
result = client.analyze(text)
result.clauses  # list[Clause] with .type, .text, .summary
result.summary  # list[str] bullet points
```

The module-level functions also work directly:

```python
from contractkit import extract_clauses, summarize_contract

clauses = extract_clauses(text, api_key="sk-...")  # or rely on OPENAI_API_KEY
```

### Configuration

```python
client = ContractClient(
    model="gpt-4o-mini",      # default
    temperature=0.3,          # default
    max_text_chars=100_000,   # contracts are truncated to this budget
)
```

## API

| Function | Description |
| --- | --- |
| `read_pdf(pdf_path, use_ocr=True)` | Extract raw text from a PDF file |
| `split_into_clauses(text)` | Split text into clauses by blank lines or bullets |
| `extract_clauses(text, api_key=None)` | Extract structured clauses via OpenAI |
| `summarize_contract(text, api_key=None)` | Summarize into business-friendly bullets |

## Errors

All failures raise subclasses of `ContractKitError` (`InvalidApiKeyError`,
`ContextLengthError`, `MalformedModelOutputError`, `PdfReadError`), so you can
handle them predictably.

## Security

Set your key as the `OPENAI_API_KEY` environment variable or pass it explicitly.
Never commit API keys to source control.

## License

[MIT](LICENSE)
