Skip to main content

Python SDK for nxusKit — pure-Python providers with optional SDK-bundle native engines

Project description

nxuskit-py: Python SDK for nxusKit

SDK bundle Python 3.11+ License: MIT OR Apache-2.0

Pure Python library for the nxusKit polyglot SDK. The public distribution package is nxuskit-py and imports as nxuskit. Pure-Python provider APIs work from the Python package; native/FFI engine APIs require an installed nxusKit SDK bundle. Z3 solver and ZEN decision table workflows require nxusKit SDK Pro.

Features

  • 11 LLM Providers — Claude, OpenAI, Ollama, xAI Grok, Groq, Mistral, Fireworks, Together, OpenRouter, Perplexity, LM Studio
  • Per-Request Model Override — Switch models on any chat() call: provider.chat(messages, model="gpt-4o-mini")
  • Tool Calling / Function Calling — Pass tool definitions, receive structured tool call responses
  • Streaming — Iterator-based streaming with is_final() completion detection
  • Vision / Multimodal — Image input via URL, base64, or file path with auto-detected MIME types
  • Model Discoverylist_models() with supports_vision(), modalities(), max_images() helpers
  • Typed Error HandlingTimeoutError, NetworkError, RateLimitError, AuthenticationError, ProviderError
  • Retry UtilitiesRetryConfig, retry_with_backoff, AdaptiveRateLimiter
  • CLIPS / BN / Solver / ZEN — FFI access to nxusKit reasoning engines (native library required; Solver and ZEN require Pro)

Dependencies: requests, cffi (FFI), keyring (credential storage), PyJWT[crypto] (license tokens)

Installation

Install the Python package from PyPI:

python -m pip install nxuskit-py==1.0.4
python -c "import nxuskit; print(nxuskit.__version__)"

nxuskit-py is the distribution package and nxuskit is the Python import package. The package-index wheel installs the pure-Python package only; it does not install native libnxuskit engines or Pro command modules.

The Python package is also shipped inside nxusKit SDK bundles for offline or bundle-local use:

export NXUSKIT_SDK_DIR="$HOME/.nxuskit/sdk/current"
export PYTHONPATH="$NXUSKIT_SDK_DIR/python/src:${PYTHONPATH:-}"
python -c "import nxuskit; print(nxuskit.__version__)"

For FFI features (CLIPS, BN, Solver, ZEN), install the nxusKit SDK and set NXUSKIT_SDK_DIR, NXUSKIT_LIB_DIR, or install the SDK at ~/.nxuskit/sdk/current/. CLIPS and Bayesian inference are Community Edition features where supported by the installed SDK; Solver and ZEN require Pro SDK features and Pro entitlement.

Quick Start

import nxuskit

# Create a provider (auto-discovers API key from environment)
provider = nxuskit.Provider.claude()

# Simple chat
response = provider.chat([nxuskit.Message.user("What is 2 + 2?")])
print(response.content)
print(f"Tokens: {response.usage.total_tokens}")

Capability Manifest Preview

The Python package exposes public capability manifest projection types. The public shape carries status values and reviewed-on metadata only; internal evidence records, model overrides, and provider-specific details stay private to the engine registry.

import nxuskit

manifest = nxuskit.PublicCapabilityManifest(
    schema_version="capability-manifest-v2-public-preview/1",
    posture=nxuskit.ManifestPublicationPosture.SPLIT,
    providers=[
        nxuskit.PublicProviderCapability(
            name="openai",
            display_name="OpenAI",
            last_reviewed_on="2026-05-09",
            provider_status="unknown",
            capabilities={
                "json_schema_strict": nxuskit.CapabilityStatus.SUPPORTED,
                "rerank": nxuskit.CapabilityStatus.FUTURE,
            },
        )
    ],
)

print(nxuskit.PUBLIC_CAPABILITY_FIELDS)
print(manifest.to_dict()["providers"][0]["capabilities"]["json_schema_strict"])

Per-Request Model Override

provider = nxuskit.Provider.openai()  # default: gpt-4o

# Override model for a single call
response = provider.chat(
    [nxuskit.Message.user("Hello")],
    model="gpt-4o-mini",
    temperature=0.5,
)

Streaming

for chunk in provider.chat_stream([nxuskit.Message.user("Tell me a story")]):
    print(chunk.delta, end="", flush=True)
    if chunk.is_final():
        print(f"\nTokens: {chunk.usage.total_tokens}")

Streaming Logprobs (v0.9.4+)

Per-chunk logprob deltas are now surfaced on streaming responses for providers that support them (OpenAI). Check the capability flag before issuing the call; non-supporting providers always emit chunk.logprobs is None on every chunk (FR-007 — no phantom data).

from nxuskit import Provider, ChatRequest, Role
import asyncio

async def main():
    provider = Provider.openai()

    if not provider.capabilities().supports_streaming_logprobs:
        print("Provider does not support streaming logprobs.")

    req = ChatRequest(
        model="gpt-5.4",
        messages=[{"role": Role.USER, "content": "Say hello."}],
        logprobs=True,
        top_logprobs=3,
    )

    async for chunk in provider.chat_stream(req):
        print(chunk.delta, end="")
        if chunk.logprobs is not None:
            for tok in chunk.logprobs.content:
                print(f"  token={tok.token!r} logprob={tok.logprob:.4f}")

asyncio.run(main())

Tool Calling

weather_tool = nxuskit.ToolDefinition.create(
    name="get_weather",
    description="Get weather for a location",
    parameters={
        "type": "object",
        "properties": {"location": {"type": "string"}},
        "required": ["location"],
    },
)

response = provider.chat(
    [nxuskit.Message.user("What's the weather in Tokyo?")],
    tools=[weather_tool],
    tool_choice=nxuskit.tool_choice_auto(),
)

if response.tool_calls:
    for call in response.tool_calls:
        print(f"Call: {call.function.name}({call.function.arguments})")

Vision

msg = nxuskit.Message.user("What's in this image?").with_image_file("photo.png")
response = provider.chat([msg], model="gpt-4o")

Error Handling

try:
    response = provider.chat([nxuskit.Message.user("Hello")])
except nxuskit.TimeoutError:
    print("Request timed out — try a faster model")
except nxuskit.NetworkError:
    print("Network issue — check connection")
except nxuskit.RateLimitError as e:
    print(f"Rate limited — retry after {e.retry_after}s")
except nxuskit.AuthenticationError:
    print("Check your API key")

Model Discovery

models = provider.list_models()
for m in models:
    vision = "vision" if m.supports_vision() else "text-only"
    print(f"  {m.name}: {vision}")

Providers

Provider Factory Environment Variable
Claude Provider.claude() ANTHROPIC_API_KEY
OpenAI Provider.openai() OPENAI_API_KEY
Ollama Provider.ollama() None (local)
xAI Grok Provider.xai() XAI_API_KEY
Groq Provider.groq() GROQ_API_KEY
Mistral Provider.mistral() MISTRAL_API_KEY
Fireworks Provider.fireworks() FIREWORKS_API_KEY
Together Provider.together() TOGETHER_API_KEY
OpenRouter Provider.openrouter() OPENROUTER_API_KEY
Perplexity Provider.perplexity() PERPLEXITY_API_KEY
LM Studio Provider.lmstudio() None (local)

CLIPS Session API

For direct CLIPS rule engine access (requires native library):

from nxuskit.clips import ClipsSession

with ClipsSession() as s:
    s.load_json(rules_json)
    s.reset()
    s.fact_assert_string('(sensor (name "temp") (value 200))')
    fired = s.run()

FFI Provider Note

When using FFI-backed features, always use context managers (with statement) for reliable cleanup:

from nxuskit._ffi_provider import create_ffi_provider

with create_ffi_provider({"provider_type": "openai", "api_key": "sk-..."}) as p:
    response = p.chat({"model": "gpt-4o", "messages": [...]})

Development

pip install -e ".[dev]"
pytest tests/
ruff check src/ && ruff format --check .

License

Dual-licensed under MIT and Apache 2.0. See the MIT and Apache 2.0 license texts.

See also: nxusKit-examples for runnable examples.

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

nxuskit_py-1.0.4.tar.gz (59.1 kB view details)

Uploaded Source

Built Distribution

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

nxuskit_py-1.0.4-py3-none-any.whl (82.0 kB view details)

Uploaded Python 3

File details

Details for the file nxuskit_py-1.0.4.tar.gz.

File metadata

  • Download URL: nxuskit_py-1.0.4.tar.gz
  • Upload date:
  • Size: 59.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nxuskit_py-1.0.4.tar.gz
Algorithm Hash digest
SHA256 cc5bb2ef526f284e16b3e1d22ac5ac0bcb88a48cd0fba57e0f8cbac141700c82
MD5 05819d7217ed3cfcda3cffbf734241b5
BLAKE2b-256 7153e49e41448737dc34b0b70b02031e4534a9d78178d280a47bac53b7f4c913

See more details on using hashes here.

Provenance

The following attestation bundles were made for nxuskit_py-1.0.4.tar.gz:

Publisher: publish-nxuskit-py-pypi.yml on nxus-SYSTEMS/nxusKit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nxuskit_py-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: nxuskit_py-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nxuskit_py-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c402f196344ae064c75ca276f60daf30805f842cd9f61f88d83cb5d7bb8a9c46
MD5 f57ea78dd55a63a3a4ffdc18bc385eeb
BLAKE2b-256 ef3acc7b801f83253d304c83a7a24e50669a5d09cd9ac7943b18967293a091d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for nxuskit_py-1.0.4-py3-none-any.whl:

Publisher: publish-nxuskit-py-pypi.yml on nxus-SYSTEMS/nxusKit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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