Skip to main content

Python SDK for the Neural Protocol Suite (NPS)

Project description

English | 中文版

NPS Python SDK (nps-lib)

Python client library for the Neural Protocol Suite (NPS) — a complete internet protocol stack designed for AI agents and models.

PyPI package: nps-lib | Python namespace: nps_sdk

Status

v1.0.0-alpha.2 — Phase 1 / Phase 2 synchronized alpha release

Covers all five protocols — NCP + NWP + NIP + NDP + NOP — frame definitions, async client, and Ed25519 identity management.

Requirements

  • Python 3.11+
  • Dependencies: msgpack, httpx, cryptography

Installation

pip install nps-lib

For development:

pip install "nps-lib[dev]"

Modules

Module Description
nps_sdk.core Frame header, codec (Tier-1 JSON / Tier-2 MsgPack), anchor cache, exceptions
nps_sdk.ncp NCP frames: AnchorFrame, DiffFrame, StreamFrame, CapsFrame, HelloFrame, ErrorFrame
nps_sdk.nwp NWP frames: QueryFrame, ActionFrame; async NwpClient
nps_sdk.nip NIP frames: IdentFrame, TrustFrame, RevokeFrame; NipIdentity (Ed25519 key management)
nps_sdk.ndp NDP frames: AnnounceFrame, ResolveFrame, GraphFrame; in-memory registry + validator
nps_sdk.nop NOP frames: TaskFrame, DelegateFrame, SyncFrame, AlignStreamFrame; async NopClient

Quick Start

Encoding / Decoding NCP Frames

from nps_sdk.core.codec import NpsFrameCodec
from nps_sdk.core.registry import FrameRegistry
from nps_sdk.ncp.frames import AnchorFrame, FrameSchema, SchemaField

registry = FrameRegistry.create_default()
codec    = NpsFrameCodec(registry)

schema = FrameSchema(fields=(
    SchemaField(name="id",    type="uint64"),
    SchemaField(name="price", type="decimal", semantic="commerce.price.usd"),
))
frame  = AnchorFrame(anchor_id="sha256:...", schema=schema)

wire   = codec.encode(frame)           # bytes — Tier-2 MsgPack by default
result = codec.decode(wire)            # → AnchorFrame

Anchor Cache (Schema Deduplication)

from nps_sdk.core.cache import AnchorFrameCache

cache     = AnchorFrameCache()
anchor_id = cache.set(frame)           # stores; returns canonical sha256 anchor_id
frame     = cache.get_required(anchor_id)

Querying a Memory Node (async)

import asyncio
from nps_sdk.nwp import NwpClient, QueryFrame

async def main():
    async with NwpClient("https://node.example.com") as client:
        caps = await client.query(
            QueryFrame(anchor_ref="sha256:...", limit=50)
        )
        print(caps.count, caps.data)

asyncio.run(main())

Invoking an Action Node (async)

from nps_sdk.nwp import NwpClient, ActionFrame

async with NwpClient("https://node.example.com") as client:
    result = await client.invoke(
        ActionFrame(action_id="orders.create", params={"sku": "X-101", "qty": 1})
    )

NIP Identity Management

from nps_sdk.nip.identity import NipIdentity

# Generate and save an encrypted Ed25519 keypair
identity = NipIdentity.generate("ca.key", passphrase="my-secret")

# Load from file
identity = NipIdentity()
identity.load("ca.key", passphrase="my-secret")

# Sign a NIP frame payload (canonical JSON, no 'signature' field)
sig = identity.sign(ident_frame.unsigned_dict())

# Verify
ok = NipIdentity.verify_signature(identity.pub_key_string, payload, sig)

Architecture

nps_sdk/
├── core/          # Wire primitives (FrameHeader, codec, cache, exceptions)
├── ncp/           # NCP frames (0x01–0x0F)
├── nwp/           # NWP frames (0x10–0x1F) + async HTTP client
└── nip/           # NIP frames (0x20–0x2F) + Ed25519 identity

Frame Encoding Tiers

Tier Value Description
Tier-1 JSON 0x00 UTF-8 JSON. Development / compatibility.
Tier-2 MsgPack 0x01 MessagePack binary. ~60% smaller. Production default.

NWP HTTP Overlay Mode

NwpClient communicates via HTTP with Content-Type: application/x-nps-frame. Sub-paths per operation:

Operation Path Request Frame Response Frame
Schema anchor POST /anchor AnchorFrame 204
Structured query POST /query QueryFrame CapsFrame
Streaming query POST /stream QueryFrame StreamFrame chunks
Action invocation POST /invoke ActionFrame raw result or AsyncActionResponse

Running Tests

pytest                 # all tests + coverage report
pytest -k test_nip     # NIP tests only

Coverage target: ≥ 90 %.

License

Apache 2.0 — see LICENSE.

Copyright 2026 INNO LOTUS PTY LTD

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nps_lib-1.0.0a2.tar.gz (85.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nps_lib-1.0.0a2-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file nps_lib-1.0.0a2.tar.gz.

File metadata

  • Download URL: nps_lib-1.0.0a2.tar.gz
  • Upload date:
  • Size: 85.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for nps_lib-1.0.0a2.tar.gz
Algorithm Hash digest
SHA256 c40439f8a08e14136a2747cac1693e1e484e2be1a5a9ffa5da7239d475a422cc
MD5 b909b4b1b0ca58ae1ea9b415b6af7469
BLAKE2b-256 ce9cc337db3d0c7f44963c523006544eac8a59871acbb0abe6765f2531879e02

See more details on using hashes here.

File details

Details for the file nps_lib-1.0.0a2-py3-none-any.whl.

File metadata

  • Download URL: nps_lib-1.0.0a2-py3-none-any.whl
  • Upload date:
  • Size: 43.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for nps_lib-1.0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0042d31582a13fcfabe82610eff55e739f9cf4c99c5bb3ef3d9fa619e33f246
MD5 d591a5268bd726155006291eb8718852
BLAKE2b-256 10127acea535a9dc7376d1dfa8ebbacaddc8d74e44c2d23a0dd8ef64b20b18e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page