Metadata-Version: 2.4
Name: haltstate-sdk
Version: 0.6.0
Summary: HaltState Sentinel Python SDK - Compliance & Policy Checks for AI Agents
Author-email: Krystal Unity <support@krystalunity.com>
License: MIT License
        
        Copyright (c) 2025 Krystal Unity
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://haltstate.ai
Project-URL: Repository, https://github.com/StartKrystal/krystal-unity-core
Project-URL: Issues, https://github.com/StartKrystal/krystal-unity-core/issues
Project-URL: Documentation, https://haltstate.ai/docs
Keywords: haltstate,janus,sentinel,ai,compliance,policy,sdk,safety
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.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Security
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.24
Dynamic: license-file

# HaltState Sentinel SDK

[![PyPI](https://img.shields.io/pypi/v/haltstate-sdk.svg)](https://pypi.org/project/haltstate-sdk/)

Compliance & policy checks for AI agents. Perform pre-action checks, approvals, and post-action reporting with minimal code.

## Installation
```bash
pip install haltstate-sdk
```

## Quickstart (sync)
```python
from haltstate import HaltStateClient

client = HaltStateClient(tenant_id="your_tenant_id", api_key="janus_xyz", fail_open=False)

decision = client.check(
    action="payment.process",
    params={"amount": 5000, "currency": "USD"},
    agent_id="payment-bot-01",
)

if decision.allowed:
    process_payment(...)
    client.report(decision, status="success", result={"transaction_id": "tx_123"}, action="payment.process", agent_id="payment-bot-01")
elif decision.requires_approval:
    print(f"Approval required: {decision.reason}")
else:
    print(f"Action denied: {decision.reason}")
```

### Backward Compatibility

Existing code using `janus` imports continues to work:

```python
from janus import JanusClient  # Still works!
```

## Guard Pattern (SDK 0.5.0+)

For actions requiring human approval, use the idempotent guard pattern:

```python
from haltstate import AsyncHaltStateClient, ActionPending, ActionRejected

async def process_high_value_payment(invoice_id: str, amount: float):
    client = AsyncHaltStateClient(tenant_id="acme", api_key="janus_xxx")

    try:
        async with client.guard(
            action="payment.process",
            agent_id="payment-bot",
            params={"invoice_id": invoice_id, "amount": amount},
            idempotency_key=f"payment-{invoice_id}",  # Retry-safe
            timeout_seconds=300
        ) as permit:
            # Only executes after human approval
            result = await execute_payment(amount)
            print(f"Approved by {permit.approver} at {permit.approved_at}")
            return result

    except ActionPending:
        print("Awaiting human approval...")
        return {"status": "pending"}

    except ActionRejected as e:
        print(f"Rejected by {e.rejected_by}: {e.reason}")
        raise
```

Key features:
- **Idempotency keys**: Same key = same approval request, safe for retries
- **Process restart safety**: Approved actions can be executed after restart
- **Audit trail**: Full record of who approved and when

## Decorators
```python
from haltstate import HaltStateClient, haltstate_guard

client = HaltStateClient(tenant_id="acme", api_key="janus_xxx")

@haltstate_guard(client, action="email.send", agent_id="email-bot")
def send_email(to, subject, body):
    return mailer.send(to, subject, body)
```

## Async
```python
from haltstate import AsyncHaltStateClient

async def main():
    async with AsyncHaltStateClient(tenant_id="acme", api_key="janus_xxx") as client:
        res = await client.check("database.drop", params={"table": "users"})
        if res.allowed:
            await client.report(res, status="success", action="database.drop", agent_id="ops-bot")
```

## Exceptions

```python
from haltstate import (
    HaltStateError,           # Base error
    HaltStateAuthError,       # Invalid API key
    HaltStateConnectionError, # Network/timeout
    ActionPending,            # Awaiting approval (guard pattern)
    ActionRejected,           # Human rejected (guard pattern)
    ActionTimeout,            # Approval expired (guard pattern)
)
```

## Docs

Full documentation at [haltstate.ai/docs](https://haltstate.ai/docs):
- Quickstart - 5-minute setup
- Guard Pattern - HITL approval flow
- API Reference - All methods
- Error Handling - Exception handling
- SB-53 Compliance - Regulatory mapping

## Migration from janus-sdk

If upgrading from `janus-sdk`:

```python
# Old (still works)
from janus import JanusClient, janus_guard

# New
from haltstate import HaltStateClient, haltstate_guard
```

Both import styles work - no code changes required for existing users.

## License
MIT
