Metadata-Version: 2.5
Name: 100xprompt
Version: 0.1.180
Summary: Python SDK for 100XPrompt: a fully-typed sync and async client, and the 100xprompt engine it starts for you.
Project-URL: Homepage, https://100xprompt.com
Project-URL: Repository, https://github.com/nipurn123/100xprompt
Project-URL: Issues, https://github.com/nipurn123/100xprompt/issues
Author: 100XPrompt
License-File: LICENSE
Keywords: 100xprompt,agent,ai,client,coding-agent,llm,mcp,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx-sse<1,>=0.4
Requires-Dist: httpx<1,>=0.27
Requires-Dist: pydantic<3,>=2.8
Requires-Dist: typing-extensions>=4.7
Description-Content-Type: text/markdown

# 100xprompt (Python SDK)

Python SDK for [100XPrompt](https://100xprompt.com), the AI coding agent.

A fully-typed client for the 100XPrompt agent server, sync and async, and the engine that serves it, started for you. Use it to drive sessions, stream events, manage models, providers and MCP servers, and build your own tools, bots and CI jobs on top of 100XPrompt.

## Install

```bash
pip install 100xprompt
```

The distribution is `100xprompt`; the import is `hundredxprompt` (a Python module name cannot start with a digit). Python 3.9 or newer.

The engine comes with it: pip picks the wheel for your machine, which carries the 100xprompt engine at the package's own version (macOS 13+ on Apple silicon or Intel; Linux x64 or arm64 with glibc 2.17+ or musl; Windows x64). Nothing else to install, except on Alpine and other musl distributions, which need the C++ runtime the engine links against: `apk add libstdc++ libgcc`. Elsewhere pip installs the pure wheel, which runs a 100xprompt CLI you install yourself (`curl -fsSL https://100xprompt.com/install | bash`). So does an x64 CPU without AVX2 (most made before 2013) on Linux: the engine in those wheels needs AVX2, and the CLI's installer picks a build that does not.

## Sign in once

```bash
python -m hundredxprompt sign-in
```

It asks you to pick a provider (choose **100XPrompt**), then opens your browser. The sign-in belongs to the machine, so if you already use the 100XPrompt CLI or desktop app here, you are signed in already. From code: `hundredxprompt.sign_in()`.

## Quick start

```python
from hundredxprompt import Client
from hundredxprompt.types import TextPart, TextPartInput

with Client.start() as client:
    session = client.session.create(title="demo")
    reply = client.session.prompt(
        session.id,
        parts=[TextPartInput(text="Write unit tests for src/index.ts")],
    )
    print("".join(p.text for p in reply.parts if isinstance(p, TextPart)))
```

`Client.start()` starts the engine (`100xprompt serve`) on `127.0.0.1` and returns a client for it; leaving the `with` block (or `client.close()`) stops the server. The server takes port 4096 when it is free and any free port otherwise; pass `port=` to pin one, `cli=` to run your own 100xprompt CLI instead of the engine (a path, or a command such as `["bun", "run", "src/main.ts"]`), `config=` to layer config over the user's own, and `cwd=` for the project it starts in.

The server requires a token on every request, on loopback too. `start()` picks a random one (or takes `token=`), hands it to the server, and the client sends it.

## Stream events

`client.event.subscribe()` yields typed events and stays subscribed: when the connection drops it reconnects with `Last-Event-ID`, so the server replays what was missed (or sends `ServerReset` when it cannot). Heartbeats are skipped.

```python
from hundredxprompt import Client
from hundredxprompt.types import EventMessagePartUpdated, EventServerConnected, EventSessionIdle, TextPart, TextPartInput

with Client.start() as client:
    session = client.session.create()
    with client.event.subscribe() as events:
        for event in events:
            if isinstance(event, EventServerConnected):
                client.session.prompt_async(session.id, parts=[TextPartInput(text="Hello!")])
            elif isinstance(event, EventMessagePartUpdated) and isinstance(event.properties.part, TextPart):
                print(event.properties.part.text)
            elif isinstance(event, EventSessionIdle) and event.properties.session_id == session.id:
                break
```

An event type this SDK version does not know yet (a newer server's) arrives as `UnknownEvent`, so a long-lived subscription never fails on one. Tune reconnects with `retry_delay`, `max_retry_delay`, `max_retry_attempts`, `max_retry_duration`, `liveness_timeout` and `on_error`.

## Async

`AsyncClient` has the same methods, awaited:

```python
import asyncio

from hundredxprompt import AsyncClient
from hundredxprompt.types import TextPartInput


async def main() -> None:
    async with await AsyncClient.start() as client:
        session = await client.session.create()
        reply = await client.session.prompt(session.id, parts=[TextPartInput(text="Hi")])
        print(reply.info.tokens)
        async with client.event.subscribe() as events:
            async for event in events:
                print(event.type)
                break


asyncio.run(main())
```

## Server and client separately

```python
from hundredxprompt import Server

with Server.start(port=4096) as server:
    client = server.client()  # closing it leaves the server running
    print(client.global_.health().version)
```

The SDK has no terminal UI. To watch or steer a server your program started, run the 100XPrompt CLI against it: `100xprompt attach <server.url>` with `HUNDREDXPROMPT_SERVER_TOKEN` set to `server.token`.

## Connect to an existing server

If a `100xprompt serve` is already running, locally or remotely, point a client at it. `serve` prints the token it requires; set `HUNDREDXPROMPT_SERVER_TOKEN` before starting it to choose the token yourself.

```python
import os

from hundredxprompt import Client

client = Client("https://your-host.example.com", token=os.environ["HUNDREDXPROMPT_SERVER_TOKEN"])
```

Pass `directory=` to scope every call to a project folder (a call's own `directory=` wins).

> Authentication, rate limiting and access control are enforced by the **server**, not the SDK. Secure your hosted instance accordingly.

## Structured output

```python
from pydantic import BaseModel

from hundredxprompt.types import TextPartInput


class City(BaseModel):
    name: str
    population: int


result = client.session.prompt_structured(
    session.id, output_type=City, parts=[TextPartInput(text="The biggest city in France?")]
)
print(result.structured.population)  # a validated City
```

Pass `schema=` (a JSON Schema dict) instead of `output_type=` to get the value as plain JSON. When the model never delivers a valid value, it raises `StructuredOutputFailedError`.

## Every operation

Every operation of the API is a method named after its `operationId`: `session.prompt` is `client.session.prompt(...)`, `global.health` is `client.global_.health()` (a trailing `_` where the name is a Python keyword), and `session.revert.preview` is `client.session.revert_preview(...)`. Path parameters are positional; query parameters and body fields are keyword arguments in snake case (`message_id=`, sent as `messageID`). Every method also takes `extra_headers`, `extra_query`, `extra_body` and `timeout`.

`hundredxprompt.OPERATIONS` lists every operation with the method that calls it.

## Types

Every request and response model, and every event, is generated from the server's OpenAPI spec and lives in `hundredxprompt.types`:

```python
from hundredxprompt.types import AssistantMessage, Event, Part, Session, TextPartInput
```

Models are pydantic v2 models with snake-case attributes; `model.to_dict()` gives the server's JSON. Unions such as `Part`, `Message` and `Event` are discriminated by `type` (or `role`), so `isinstance` tells them apart. A value from a newer server that a model does not know is kept as sent, with a warning on the `hundredxprompt` logger, rather than failing the call.

## Errors

| Exception | When |
| --- | --- |
| `LicenseError` | 403: the engine refuses work because this machine's account is not licensed. `message` says why and what to do, in words for a person. A subclass of `PermissionDeniedError`. |
| `BadRequestError`, `AuthenticationError`, `PermissionDeniedError`, `NotFoundError`, `ConflictError`, `InternalServerError` | 400, 401, 403, 404, 409, 5xx; any other status is `APIStatusError`. All carry `status_code` and the server's `body`. |
| `NoReplyError` | `session.prompt` ended without an assistant message: aborted (`.aborted`) or failed before the model answered (`.error`). |
| `APIConnectionError`, `APITimeoutError` | The server could not be reached, or did not answer in time. |
| `EventStreamRejectedError` | The event stream was refused (401/403/404); it does not reconnect. |
| `ServerStartError`, `CLINotFoundError` | `start()` could not run `100xprompt serve` (`CLINotFoundError`: no engine for this machine and no CLI); `output` holds what it printed. |

All of them derive from `HundredXPromptError`. `is_license_error(value)` is the same guard as the JS SDK's `isLicenseError`: it recognises the licence refusal on any of these errors, or on an error object as the server writes it.

```python
from hundredxprompt import LicenseError

try:
    client.session.prompt(session.id, parts=[TextPartInput(text="hi")])
except LicenseError as refused:
    print(refused.message)  # for example "Sign in to use 100xprompt ..."
```

Reads (sessions, messages, the event stream), `abort`, deleting your own sessions and signing in still work while the licence refuses work.

## Examples

[`examples/`](examples/): `create_session.py`, `prompt.py`, `stream_events.py`, `async_client.py`.

## Development

The typed layer (`src/hundredxprompt/_generated/`, `_version.py`) is generated from `packages/sdk/openapi.json`, the spec the JS SDK is generated from, by `script/generate.py`. The repo's `script/generate.ts` runs it after regenerating the spec, and `script/build.ts` runs it before every build, so each CLI release regenerates the SDK at the CLI's version.

```bash
uv sync
uv run python script/generate.py           # regenerate; --check exits 1 when stale
uv run ruff check . && uv run ruff format --check . && uv run mypy
uv run pytest tests/unit                   # no CLI needed
uv run pytest tests/integration            # a real `100xprompt serve` with a scripted model
bun script/build.ts                        # regenerate, then build the wheel and sdist into dist/
```

The integration tests use the `100xprompt` on your `PATH` (or `HUNDREDXPROMPT_TEST_CLI`), isolated from your own data, with a local fake model provider. The licence test runs the CLI from this checkout's source with bun (a release build ignores the settings it needs), and is skipped without it.

## License

Proprietary. See [LICENSE](./LICENSE).
