Skip to main content

NIANSYS Python SDK

Monitoring & security for autonomous AI agents. Observe what your agents do, not what they say.

Tests License: MIT Python 3.10+

NIANSYS is the trust layer between your AI agents and the systems they touch — emails, databases, payments, files, APIs. Other tools watch what your agent says (prompts, tokens, latency). NIANSYS watches what your agent does, scores the risk, and — when you ask it to — blocks dangerous actions in real time.

This repository is the official Python SDK: open-source, minimal, async-friendly.


Install

pip install niansys

Requires Python 3.10+.

Quickstart

from niansys import Guardian

guardian = Guardian(agent_key="iag_...")  # get one from the NIANSYS dashboard

result = guardian.check(
    action="send_email",
    target="ceo@acme.com",
    metadata={"subject": "Q4 results", "body_length": 1240},
)

if result.allowed:
    send_email(...)
else:
    print(f"Blocked by NIANSYS: {result.reason}")

The recommended pattern is the context manager — it releases the underlying HTTP connection pool when you're done:

with Guardian(agent_key="iag_...") as guardian:
    result = guardian.check(action="run_sql", target="prod.users")

Async

Guardian ships with a native async API — same shape, just await-able:

async with Guardian(agent_key="iag_...") as guardian:
    result = await guardian.acheck(
        action="run_sql",
        target="prod.users",
        metadata={"query": "DELETE FROM users WHERE ..."},
    )

And the killer feature — validate many actions in parallel:

import asyncio

async with Guardian(agent_key="iag_...") as guardian:
    results = await asyncio.gather(*(
        guardian.acheck(action="send_email", target=addr)
        for addr in recipient_list
    ))

Modes

The same SDK supports two modes, switchable per-agent:

  • observe (default) — NIANSYS logs and scores every action, but result.allowed is always True. Zero friction, ideal to start.
  • control — NIANSYS can return result.allowed = False based on policies, baselines, or risk score. Honor the decision in your code.
guardian = Guardian(agent_key="iag_...", mode="control")

Fail-open vs fail-closed

What happens when the NIANSYS cloud is unreachable or returns a 5xx error? You decide:

# Default — fail-open: the agent keeps working. result.allowed = True, the call is dropped.
Guardian(agent_key="iag_...")

# High-security — fail-closed: NiansysNetworkError / NiansysServerError is raised, the agent aborts.
Guardian(agent_key="iag_...", fail_open=False)

The SDK retries network errors and 5xx responses 3 times with exponential backoff (0.5s → 1s → 2s) before applying this policy. 4xx errors (auth, validation, rate-limit) are never retried — they signal a real issue the developer must fix.

The right answer depends on your risk profile. Most production agents start with fail_open=True and tighten over time.

Exceptions

All SDK errors inherit from NiansysError:

from niansys import (
    NiansysError,            # catch-all base
    NiansysAuthError,        # 401 / 403 — invalid key, suspended agent
    NiansysValidationError,  # 400 / 422 — malformed payload
    NiansysRateLimitError,   # 429
    NiansysServerError,      # 5xx after retries (fail_open=False only)
    NiansysNetworkError,     # transport failure after retries (fail_open=False only)
)

Typed

niansys is fully typed (PEP 561). mypy and pyright pick up types automatically when you pip install niansys — no extra stubs needed.

Self-hosting / local dev

By default the SDK talks to the public NIANSYS cloud at https://api.niansys.com. Override base_url to point at your own deployment or a local backend:

guardian = Guardian(
    agent_key="iag_...",
    base_url="http://127.0.0.1:8000",  # local NIANSYS backend
)

Examples

Runnable scripts live in examples/:

  • openai_integration.py — Plug NIANSYS into an OpenAI tool-calling agent. Every tool call validated before execution.
  • concurrent_batch.py — Validate 50+ actions in parallel via asyncio.gather. Showcase of the async API.

See examples/README.md for details.

Why NIANSYS

Agents IA now run real actions in real systems. They send emails, execute SQL, move money, write to disk. The capabilities are progressing faster than the tools to govern them.

  • Langfuse / Helicone / LangSmith / Arize watch prompts and costs.
  • Lakera watches prompt-injection attacks.
  • Datadog watches the infrastructure.

None of them watch the action layer — what the agent actually does. That's where NIANSYS lives.

Status

v0.1.1 — early alpha. The public API (Guardian, check, acheck, CheckResult) is stable. Internals may move. Production deployments are coordinated case-by-case until v1.0.

Changelog

See CHANGELOG.md.

Contributing

Bug reports and pull requests welcome. See CONTRIBUTING.md.

License

MIT — use it, fork it, build on it.

Author

Built by Gildas Assande. Feedback, issues, and PRs welcome.

Metadata

Release files for niansys 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for niansys 0.1.1
File Size Uploaded Provenance Actions
niansys-0.1.1.tar.gz 19.5 kB Without provenance Details for niansys-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for niansys 0.1.1
File Interpreter ABI Platform Actions
niansys-0.1.1-py3-none-any.whl Python 3 none any Details for niansys-0.1.1-py3-none-any.whl

Total release size: 30.9 kB

Release files / niansys-0.1.1.tar.gz

Download URL niansys-0.1.1.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a617a847dd58fb545abc410237629b57ee5a097badea174bed67ded9748cfadb
BLAKE2b-256 checksum
How to use checksums
851bfe80e9a77f10095daaf6f82bfe9d08cc2b93a72c2e7fd50e802ba42ac3b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / niansys-0.1.1-py3-none-any.whl

Download URL niansys-0.1.1-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0d3c631b424138d435ada5cb3f4609dca433754b4212b5d3de3cabb3d85f0a7
BLAKE2b-256 checksum
How to use checksums
1ea2a01a9bbc9a4804222cc0082263dcc6547ef3637d750f300c57ab258ab9f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for niansys 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page