Metadata-Version: 2.4
Name: ai2in
Version: 0.3.0
Summary: Python SDK for AI2IN — secure AI code sandboxes, hosted in India.
Project-URL: Homepage, https://ai2in.dev
Project-URL: Repository, https://github.com/AI2IN-DEV/AI2IN
Project-URL: Documentation, https://ai2in.dev
Author: AI2IN.dev
License: MIT
License-File: LICENSE
Keywords: agents,ai,code-interpreter,e2b,india,sandbox
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.3; extra == 'langchain'
Description-Content-Type: text/markdown

# ai2in — Python SDK

The developer client for [AI2IN.dev](https://ai2in.dev) — secure AI code
sandboxes, hosted in India. Spin up an isolated Linux sandbox, run untrusted /
AI‑generated Python in a stateful kernel, and get back rich, typed results
(text, HTML tables, charts, JSON) — the E2B code‑interpreter model, in‑region.

Stdlib‑only, zero dependencies.

## Install

```bash
pip install ai2in            # once published
# or, from this repo:
pip install -e sdk/python
```

## Quickstart

```python
from ai2in import Sandbox

with Sandbox(api_key="ai2in_live_…", base_url="https://api.ai2in.dev") as sbx:
    execution = sbx.run_code(
        "import pandas as pd; pd.DataFrame({'gst_lakh_cr': [1.87, 1.73, 1.95]})"
    )

    print(execution.text)            # the main result's plain text
    print(execution.logs.stdout)     # ['…']

    for r in execution.results:      # rich, typed outputs
        if r.html:                   # e.g. a DataFrame → HTML table
            save(r.html)
        if r.png:                    # e.g. a matplotlib figure → base64 PNG
            save_image(r.png)

    if execution.error:              # structured error for self-correction
        print(execution.error.name, execution.error.value)
```

State persists across `run_code` calls in the same sandbox (like a notebook):

```python
sbx.run_code("x = 41")
sbx.run_code("x + 1").text   # "42"
```

## Streaming

Pass callbacks to stream output **live** as the kernel produces it (long loops,
training logs, incremental prints). The events are still accumulated into the
returned `Execution`, so the return value is identical whether or not you stream:

```python
execution = sbx.run_code(
    "for i in range(5):\n    print('step', i)\n    import time; time.sleep(1)",
    on_stdout=lambda t: print(t, end="", flush=True),  # arrives chunk-by-chunk
    on_result=lambda r: render(r),                     # display() calls, figures, the value
    on_error=lambda e: print(e.value),
)
print(execution.execution_ms)                          # still get the full Execution
```

## Result model

`run_code()` returns an `Execution`:

| Field | Type | Notes |
|---|---|---|
| `results` | `list[Result]` | rich outputs; the cell's value has `is_main_result=True` |
| `logs` | `Logs` | `.stdout` / `.stderr` (lists of str) |
| `error` | `ExecutionError \| None` | `.name`, `.value`, `.traceback` |
| `text` | `str \| None` | convenience: the main result's text |

Each `Result` may carry any of: `text`, `html`, `markdown`, `svg`, `png`,
`jpeg`, `pdf`, `latex`, `json`, `javascript`. Call `r.formats()` for what's
present.

## Local dev

Point at a local engine (default `http://localhost:4000`):

```python
with Sandbox() as sbx:            # talks to localhost:4000
    print(sbx.run_code("print(1 + 1)").logs.stdout)
```

---

© 2026 AI2IN.dev — see the repository LICENSE.
