Metadata-Version: 2.4
Name: forktex-intelligence
Version: 0.2.3
Summary: Standalone Python SDK for the ForkTex Intelligence API — chat, agent runs, embeddings, retrieval, ecosystem indexing
License-Expression: AGPL-3.0-only
License-File: LICENSE
License-File: NOTICE
Author: FORKTEX
Author-email: info@forktex.com
Requires-Python: >=3.12
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Dist: httpx (>=0.27.0,<1.0.0)
Requires-Dist: httpx-sse (>=0.4.0,<1.0.0)
Requires-Dist: pydantic (>=2.11.10,<3.0.0)
Project-URL: Bug Tracker, https://github.com/forktex/intelligence/issues
Project-URL: Homepage, https://intelligence.forktex.com
Project-URL: Repository, https://github.com/forktex/intelligence
Description-Content-Type: text/markdown

# forktex-intelligence

[![PyPI](https://img.shields.io/pypi/v/forktex-intelligence.svg)](https://pypi.org/project/forktex-intelligence/)
[![Python](https://img.shields.io/pypi/pyversions/forktex-intelligence.svg)](https://pypi.org/project/forktex-intelligence/)
[![License](https://img.shields.io/pypi/l/forktex-intelligence.svg)](https://github.com/forktex/intelligence/blob/master/sdk-py/LICENSE)

Standalone Python SDK for the [ForkTex Intelligence](https://intelligence.forktex.com) API.

`forktex-intelligence` is the high-level Python client for the ForkTex Intelligence platform: multi-provider LLM chat (streaming + structured), embeddings, vector search, content extraction (PDF / DOCX / HTML), and image / audio generation. It backs the `forktex intelligence ask / run / scrape` CLI commands and is also usable directly from any Python application.

## Install

```bash
pip install forktex-intelligence
```

**Requires Python 3.12+.** Tested on 3.12, 3.13, 3.14.

## Quick Start

### Single-shot prompt

```python
from forktex_intelligence import Intelligence

async with Intelligence(endpoint="https://intelligence.forktex.com/api", api_key="sk-...") as ai:
    response = await ai.chat("Summarize the ForkTex stack in one sentence.")
    print(response.text)
```

### Structured response (Pydantic schema)

```python
from pydantic import BaseModel
from forktex_intelligence import Intelligence

class Summary(BaseModel):
    title: str
    bullets: list[str]

async with Intelligence(endpoint="...", api_key="...") as ai:
    result = await ai.extract_structured(
        prompt="Summarize the ForkTex stack.",
        schema=Summary,
    )
    print(result.parsed.title, result.parsed.bullets)
```

### Streaming

```python
from forktex_intelligence import Intelligence

async with Intelligence(endpoint="...", api_key="...") as ai:
    async for chunk in ai.stream("Tell me a story."):
        print(chunk, end="", flush=True)
```

## Configuration

Pass endpoint and API key explicitly:

```python
Intelligence(endpoint="https://intelligence.forktex.com/api", api_key="sk-...")
```

Or via an `IntelligenceSettings` object:

```python
from forktex_intelligence import IntelligenceSettings, Intelligence

settings = IntelligenceSettings(endpoint="...", api_key="...")
async with Intelligence(settings=settings) as ai:
    ...
```

When used via the `forktex` CLI, settings are loaded from environment variables and `.forktex/` config files automatically.

| Variable | Description | Default |
|----------|-------------|---------|
| `FORKTEX_INTELLIGENCE_ENDPOINT` | Intelligence API endpoint | `https://intelligence.forktex.com/api` |
| `FORKTEX_INTELLIGENCE_API_KEY` | Intelligence API key | *(required)* |

### Local dev (point at your `make local` stack)

```bash
export FORKTEX_INTELLIGENCE_ENDPOINT=http://localhost:8001/api
export FORKTEX_INTELLIGENCE_API_KEY=dev-key
```

Or programmatically:

```python
from forktex_intelligence import Intelligence
intel = Intelligence(endpoint="http://localhost:8001/api", api_key="dev-key")
```

## What's in the package

| Module | Purpose |
|--------|---------|
| `forktex_intelligence.api` | High-level `Intelligence` client (chat, structured, stream) |
| `forktex_intelligence.client` | Low-level `ForktexIntelligenceClient` (raw HTTP, advanced use) |
| `forktex_intelligence.client.generated` | Wire-level Pydantic models (`ChatMessage`, `ChatResponse`, …) generated from the OpenAPI spec |
| `forktex_intelligence.streams` | SSE event types and parser |
| `forktex_intelligence.config` | `IntelligenceSettings` — endpoint, API key |

All response models come from the OpenAPI codegen pipeline — one source of truth shared between the server and every consumer.

## Repository

This SDK lives inside the [`forktex/intelligence`](https://github.com/forktex/intelligence) monorepo alongside the API server (`api/`). The SDK package is independently versioned and published to PyPI.

## Development

The [`Makefile`](Makefile) is generated by `forktex fsd makefile sync` from [`forktex.json`](forktex.json) — do not hand-edit.

```bash
make help              # list every available target
make deps              # editable install with the dev group
make format            # ruff format
make lint              # ruff check
make test              # pytest tests/
make codegen-check     # verify the generated client imports cleanly
make build             # python3 -m build → dist/
make ci                # format-check + lint + license-check + audit + test + build
make clean             # remove caches and dist/
```

`make ci` is the single command that gates a publish: format-check, lint, dual-license header check, dependency CVE audit, full test suite, and `python -m build` + `twine check`.

### License headers

Every source file carries the AGPL-3.0 + Commercial dual-license SPDX header, applied idempotently via:

```bash
make license-check    # CI gate — fails if any source file is missing the header
make license-fix      # add or refresh headers across src/, tests/, scripts/
make license-strip    # remove headers (used before license-model changes)
```

## License

Dual-licensed — **AGPL-3.0-or-later** for open-source use, **commercial** for everything else (proprietary products, SaaS without source release, redistribution in closed-source form). See [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE) for the full terms.

Commercial licensing inquiries: info@forktex.com.

The 1.0.0 release on PyPI remains under MIT; from **0.2.3** onwards the package ships AGPL-3.0+Commercial.

