Skip to main content

nz-sdk (Python)

Wire-compatible native Python SDK and drop-in CLI implementation of nezhahq/agent for Nezha Monitoring.

  • Full gRPC protocol parity across all 6 proto.NezhaService RPCs (ReportSystemInfo2, ReportSystemInfo, ReportSystemState, RequestTask, IOStream, ReportGeoIP)
  • Stealth Transport (Default-On): RFC 8484 binary DNS-over-HTTPS (doh=True with IP-based resolvers) and Hidden SNI (hide_sni=True omitting TLS ClientHello extension 0x0000, optional decoy sni, full CA + RFC 6125 real-host verification, and opt-in sni_fallback)
  • All 20 TaskTypes: HTTP/ICMP/TCP probes, shell commands, remote config reload & server transfer, MCP RPCs (Exec, FsList, FsRead, FsWrite, FsDelete, FsTransfer), and IOStream sub-protocols (TerminalGRPC, NAT, File Manager v1+v2)
  • Async-first SDK (asyncio + grpc.aio) with a thread-backed synchronous wrapper (SyncNezhaAgent), custom collector hooks, task handler overrides, and lifecycle callbacks
  • Drop-in CLI (nz-agent / python -m nz_sdk) compatible with config.yml and NZ_* environment variables

Installation

pip install nz-sdk

Quickstart (Async SDK)

import asyncio
from nz_sdk import AgentConfig, NezhaAgent


async def main() -> None:
    config = AgentConfig(
        server="dashboard.example.com:443",
        client_secret="your-agent-secret",
        tls=True,
    )
    async with NezhaAgent(
        config,
        on_connected=lambda boot_time: print(f"Connected! Dashboard boot: {boot_time}"),
        on_state_reported=lambda state: print(f"CPU: {state.cpu:.1f}%"),
    ) as agent:
        await asyncio.sleep(60)


asyncio.run(main())

Quickstart (Synchronous / Blocking)

from nz_sdk import AgentConfig, NezhaAgent

config = AgentConfig.from_yaml("config.yml")
agent = NezhaAgent(config)
agent.run_sync()

Or run in a background thread via SyncNezhaAgent:

from nz_sdk import AgentConfig, SyncNezhaAgent

with SyncNezhaAgent(AgentConfig.from_env()) as agent:
    ...

Custom Collector & Task Hooks

from nz_sdk import (
    AgentConfig,
    HostInfo,
    HostState,
    NezhaAgent,
    PsutilCollector,
    TaskRequest,
    TaskResponse,
    TaskType,
)


class CustomCollector(PsutilCollector):
    async def collect_host(self, config: AgentConfig) -> HostInfo:
        info = await super().collect_host(config)
        info.platform = "custom-embedded-linux"
        return info


async def handle_upgrade(task: TaskRequest) -> TaskResponse:
    return TaskResponse(id=task.id, type=task.type, successful=True, data="handled")


agent = NezhaAgent(
    AgentConfig(server="127.0.0.1:8008", client_secret="secret"),
    collector=CustomCollector(),
    task_handlers={TaskType.UPGRADE: handle_upgrade},
)

CLI Usage

# Load from config.yml (with NZ_* env var overrides)
nz-agent -c /etc/nezha/config.yml

# Or configure purely via flags / environment variables
nz-agent --server dashboard.example.com:443 --secret YOUR_SECRET --tls

# Equivalent module invocation
python -m nz_sdk --server 127.0.0.1:8008 --secret YOUR_SECRET

License

MIT License. See the repository root LICENSE for details and upstream attributions (nezhahq/agent WTFPL v2, Telegraf GPU parsers MIT).

Metadata

Release files for nz-sdk 0.2.0

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

Source distribution (sdist)

Source distribution for nz-sdk 0.2.0
File Size Uploaded Provenance Actions
nz_sdk-0.2.0.tar.gz 96.6 kB Without provenance Details for nz_sdk-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nz-sdk 0.2.0
File Interpreter ABI Platform Actions
nz_sdk-0.2.0-py3-none-any.whl Python 3 none any Details for nz_sdk-0.2.0-py3-none-any.whl

Total release size: 181.7 kB

Release files / nz_sdk-0.2.0.tar.gz

Download URL nz_sdk-0.2.0.tar.gz
Size 96.6 kB
Tags Source
SHA-256 checksum
How to use checksums
083ab232e6cc26721c2788d419c6eaee3c4470743a34dcefc4244f6df8a9bb30
BLAKE2b-256 checksum
How to use checksums
33e5e40f39312638dd3593201f89f8cd4fe94f5d3e1b2088cc416bb232a15123
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / nz_sdk-0.2.0-py3-none-any.whl

Download URL nz_sdk-0.2.0-py3-none-any.whl
Size 85.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6f09d2c898cdae3fe56aeeebde9d7ea2f35e5a5e44d5235a430bf7b3e16b591
BLAKE2b-256 checksum
How to use checksums
fe7c30eb27002e933891048f27ef73b6cd81f5624e009d1903483edd182c1a7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for nz-sdk 0.2.0

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.

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