Metadata-Version: 2.5
Name: nocville
Version: 0.5.9
Summary: Nocville Status Pusher SDK for Python
Project-URL: Homepage, https://nocville.com
Author: Nocville Team
License-Expression: MIT
License-File: LICENSE
Keywords: monitoring,noc,nocville,status
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
Requires-Python: >=3.9
Requires-Dist: httpx>=0.24.0
Provides-Extra: async
Requires-Dist: aiohttp>=3.8.0; extra == 'async'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.20.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Description-Content-Type: text/markdown

# nocville

Put your Python programs in your team's [Nocville](https://nocville.com) office. Each
program becomes an NPC that walks in, shows its status and leaves when it stops.

Updates are end-to-end encrypted before they leave your computer. Python publishes
through a small local bridge that does the encryption, so you set up the bridge once
and then use this package.

## Quick start

1. **Connect this computer to your office.** You need Node.js 18.19 or later.

   ```bash
   npx @nocville/npc@latest setup
   ```

   This opens your browser to approve the connection.

2. **Start the bridge** and leave it running:

   ```bash
   npx @nocville/npc@latest bridge
   ```

   It listens only on `127.0.0.1`. Run it as a background service if your program
   runs all the time.

3. **Install the package and publish:**

   ```bash
   pip install nocville
   ```

   ```python
   from nocville import NocvilleClient

   client = NocvilleClient.from_bridge(service_id="backup-bot")
   try:
       client.push_status("healthy", message="Last backup 2h ago",
                          name="Backup Bot", kind="backup-bot")
   finally:
       client.shutdown()  # the NPC leaves the office
   ```

Your NPC appears in the office straight away. Click it there to choose which room it
works in.

## Status

`push_status(status, ...)` takes:

| Field     | Meaning                                                                     |
| --------- | --------------------------------------------------------------------------- |
| `status`  | `"healthy"`, `"warning"`, `"critical"` or `"unknown"` (or `Status.HEALTHY`) |
| `mood`    | `"happy"`, `"concerned"`, `"stressed"` or `"idle"` (derived when omitted)   |
| `message` | One short line for its speech bubble                                        |
| `name`    | The name above the NPC                                                      |
| `kind`    | Its type, so your team can send every NPC of that type to one room          |
| `metrics` | A flat dictionary of numbers or strings shown on its card                   |
| `offline` | `True` removes the NPC immediately                                          |

Shortcuts: `client.healthy("All good")`, `client.warning("Disk 85%")`,
`client.critical("Backup failed!")`.

Send one update per check (every 15–60 seconds is typical), not one per event. To keep
the NPC in the office between changes, call `client.start_heartbeat(30)`.

## Async

```bash
pip install "nocville[async]"
```

```python
import asyncio
from nocville import AsyncNocvilleClient

async def main():
    client = AsyncNocvilleClient.from_bridge(service_id="backup-bot")
    try:
        await client.push_status("healthy", message="All systems operational")
    finally:
        await client.shutdown()

asyncio.run(main())
```

## Screens, devices and behavior

NPCs can have a screen or device beside them and hints for how they move:

```python
from nocville import BehaviorHints, CompanionSpec

behavior: BehaviorHints = {"activity": "busy", "busy": "seek-desk"}
companion: CompanionSpec = {
    "screenType": "desk-sign",
    "placement": "on-desk",
    "size": {"w": 3, "h": 1},
    "label": "checkout-api",
}
client.push_status("healthy", name="Build Agent", message="Running tests",
                   behavior=behavior, companion=companion)
```

- `behavior["activity"]` is optional; it is derived from status and mood. `busy` and
  `critical` send the NPC to its desk, its own device (`"busy": "seek-companion"`) or
  equipment. `idle` follows the `idle` hint.
- `waiting` freezes the NPC where it stands with a raised hand. Use it only for
  "blocked on a person", not for a degraded service; send `busy` for warnings so it stays
  at its device.
- Dictionaries use the API's camelCase keys.

The [Build your own NPC](https://nocville.com/npcs/build) guide covers screen types and
drawing your own pixel-art devices.

## Office characters

Built-in characters with their own routines and dialogue: `receptionist`, `security`,
`janitor`, `barista`, `office-cat`, `office-dog`, `plant-caretaker`, `it-technician`,
`out-of-touch-executive` and `slightly-inappropriate-hr`. Use the same value for `kind`
and `behavior["role"]`, and keep sending heartbeats while it should stay:

```python
client.push_status("healthy", kind="office-cat",
                   behavior={"role": "office-cat", "activity": "idle"})
```

To run them without writing code, use `npx @nocville/npc@latest office-cat` (see the
[NPC Library](https://nocville.com/npcs)).

## Shutting down

`shutdown()` stops heartbeats and tells the office the NPC has left (use
`await client.shutdown()` for the async client). Call it in a `finally` block.
`auto_offline=True` also tries at interpreter exit, but that can't run after a crash or
`SIGKILL`.

## Options

`from_bridge(path=None, service_id=..., **options)`. `path` defaults to the bridge's
client file in `~/.config/nocville`.

| Option        | Default | Description                           |
| ------------- | ------- | ------------------------------------- |
| `timeout`     | 5.0     | Request timeout in seconds            |
| `retries`     | 3       | Retry attempts on failure             |
| `retry_delay` | 1.0     | Base delay between retries in seconds |
| `debug`       | False   | Enable debug logging                  |

## Security

- The bridge's client file holds a local token, not your Nocville key. Your key and
  signing keys stay in `~/.config/nocville`; keep that folder private.
- Status is unencrypted only on the loopback connection to the bridge, which encrypts it
  before anything leaves the computer. Run the bridge on the same machine as your programs.
- Passing a Nocville key directly to `NocvilleClient` is refused, so status can't be sent
  unencrypted by mistake.

Requires Python 3.9 or later. MIT licensed.
