Metadata-Version: 2.5
Name: humanless
Version: 0.1.1
Summary: Verification inbox for E2E tests and AI agents testing apps you own: disposable email inboxes, TOTP codes and parsed OTPs/magic links over a push-based wait.
Project-URL: Homepage, https://usehumanless.com
Project-URL: Documentation, https://usehumanless.com/docs
Project-URL: Source, https://github.com/usehumanless/humanless-python
Project-URL: Issues, https://github.com/usehumanless/humanless-python/issues
Author-email: Ninety Nine Oranges <hello@usehumanless.com>
License-Expression: MIT
License-File: LICENSE
Keywords: 2fa,ai-agent,e2e,email-testing,humanless,magic-link,mcp,otp,playwright,pytest,qa,totp,verification
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Pytest
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.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: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx<1,>=0.24
Provides-Extra: pytest
Requires-Dist: pytest>=7; extra == 'pytest'
Description-Content-Type: text/markdown

# humanless

**Humanless is a verification inbox API for E2E tests and AI agents: it gives each test a disposable email inbox (and TOTP secret) and returns the parsed OTP code or magic link the moment it arrives.**

> Use Humanless only for apps you own or are authorized to test. Never use it to bypass verification on third-party services or to create accounts in bulk.

The official Python SDK. Python 3.9+, one dependency (`httpx`). Sync and async clients, plus pytest fixtures.

```bash
pip install humanless            # or: pip install "humanless[pytest]"
```

Get an API key at https://api.usehumanless.com/app (credits from $20, no subscription; see [pricing](https://usehumanless.com/#pricing)) and set `HUMANLESS_API_KEY`.

## Quickstart

```python
from humanless import Humanless, now_ms

hl = Humanless()  # reads HUMANLESS_API_KEY

with hl.with_identity(channels=["email"]) as idn:
    since = now_ms()  # just before your app sends the code
    # ...make your app send a code to idn["email"]...
    msg = hl.wait_for_code(idn["identity_id"], since=since)
    print(msg["code"])
# the identity is deleted here, pass or fail
```

## Playwright example (your app on localhost)

```python
from playwright.sync_api import Page, expect
from humanless import Humanless, now_ms

hl = Humanless()

def test_sign_up_with_an_email_code(page: Page):
    with hl.with_identity(channels=["email"]) as idn:
        page.goto("http://localhost:3000/signup")
        page.get_by_label("Email").fill(idn["email"])
        since = now_ms()  # just before the app sends the code
        page.get_by_role("button", name="Send code").click()
        code = hl.wait_for_code(idn["identity_id"], since=since)["code"]
        page.get_by_label("Code").fill(code)
        expect(page.get_by_text("Welcome")).to_be_visible()
```

### pytest fixtures

Installing `humanless` registers pytest fixtures (`pip install "humanless[pytest]"` pulls in pytest). `humanless_identity` is a fresh identity for each test, deleted after it, pass or fail:

```python
from humanless import now_ms

def test_sign_up(page, humanless_identity):
    page.goto("http://localhost:3000/signup")
    page.get_by_label("Email").fill(humanless_identity["email"])
    since = now_ms()
    page.get_by_role("button", name="Send code").click()
    page.get_by_label("Code").fill(humanless_identity.wait_for_code(since=since)["code"])
```

| Fixture | What it gives you |
| --- | --- |
| `humanless` | A configured `Humanless` client. |
| `humanless_identity` | A fresh identity with `wait_for_code()`, `wait_for_link()`, `wait_for_message()`, `totp()` and `delete()` bound to it. |
| `new_humanless_identity` | A factory for extra identities (for example inviter and invitee); every one is deleted after the test. |
| `humanless_identity_options` | Override in a `conftest.py` to change what `humanless_identity` creates. Default `{"channels": ["email"]}`. |

`totp()` waits for the next code when 3 s or less remain in the 30 s window, so the code is still valid when your app checks it.

## Async

```python
from humanless import AsyncHumanless, now_ms

async with AsyncHumanless() as hl:
    async with hl.with_identity(channels=["email", "totp"]) as idn:
        since = now_ms()
        # ...
        msg = await hl.wait_for_link(idn["identity_id"], since=since)
        totp = await hl.get_totp(idn["identity_id"])
```

## API

| Method | What it does |
| --- | --- |
| `Humanless(api_key=None, *, base_url=None, http_client=None)` | Client. `api_key` defaults to `HUMANLESS_API_KEY`; `base_url` defaults to `HUMANLESS_BASE_URL` or `https://api.usehumanless.com`. `AsyncHumanless` takes the same arguments. |
| `create_identity(channels=None, *, domain=None, ttl_seconds=None)` | `POST /v1/identities`. `channels` defaults to `["email"]`; add `"totp"` for 2FA. Lifetime defaults to 1 hour. |
| `wait_for_code(identity_id, *, since=None, timeout=60, channel="any")` | Next message with an OTP `code`. Long-polls (push-based); re-polls on 408 until `timeout` seconds. |
| `wait_for_link(...)` | Next message with a magic-link `url`. |
| `wait_for_message(...)` | Next message of any `type` (`otp`, `magic_link`, `raw`). Read `raw_snippet` when nothing was parsed. |
| `get_totp(identity_id)` | `{"code", "seconds_remaining"}` for the identity's TOTP secret (30 s period). |
| `get_identity(identity_id)` / `delete_identity(identity_id)` | Read / delete (idempotent). |
| `with_identity(channels=None, ...)` | Context manager: create, yield, always delete. Also `humanless.with_identity(hl, ...)`. |
| `list_identities(*, status=None, limit=None, cursor=None)` | `GET /v1/identities`: the identities this key can use, newest first. |
| `create_key(*, agent_name=None, scope=None, identity_ids=None, permissions=None, expires_at=None)` / `list_keys()` / `revoke_key(key_id)` | Scoped keys for agents: limit a key to specific identities and to `read` + `totp`. Needs your full account key. The new `key` is shown once. |
| `audit(*, identity_id=None, action=None, since=None, until=None, limit=None, cursor=None)` | `GET /v1/audit`: who read which code, when, over REST/MCP/dashboard. Codes and bodies are never logged. |

Responses are plain dicts, typed with `TypedDict` (`Identity`, `Message`, `TotpCode`).

Errors raise `HumanlessError` with `status`, `code` (for example `unauthorized`, `credits_exhausted`, `rate_limited`, `identity_ended`), `message`, `retry_after_seconds` and `details`. `is_credits_exhausted` and `is_sms_quota_exceeded` check the two 402 cases; `is_forbidden` is true when the key lacks a permission (don't retry with the same key). A wait that runs out of time raises `HumanlessTimeoutError` (status 408).

Pass `since` (Unix ms from `now_ms()`, or a `datetime`, taken just before you trigger the send) so the wait is race-free and repeatable.

## MCP (for agents driving a browser)

Remote MCP server: `https://api.usehumanless.com/mcp` (streamable HTTP, `Authorization: Bearer $HUMANLESS_API_KEY`). Tools: `create_verification_identity`, `wait_for_verification_code`, `get_totp_code`, `delete_verification_identity`.

```bash
claude mcp add --transport http humanless https://api.usehumanless.com/mcp --header "Authorization: Bearer $HUMANLESS_API_KEY"
```

`npx humanless init` (from the npm package) writes the equivalent config for Cursor, VS Code, Codex and Windsurf.

SMS (dedicated US numbers) is coming soon; email and TOTP work today.

Docs: https://usehumanless.com/docs · LLM-readable docs: https://usehumanless.com/llms.txt · License: MIT
