Skip to main content

Python binding for nil-xit: C++ bridge to frontend

Project description

nil-xit

Python binding for nil-xit – a C++ bridge that connects backends to frontend UIs with a tiny, explicit protocol.

Define frames, values, and signals in C++; interact with them from Python. The client can be web, desktop, or any runtime that speaks the protocol.

Features

  • Frames – Group values and signals displayed by a UI component
  • Two flavors – Unique (one instance) and tagged (keyed by a tag)
  • Values – Bidirectional data binding with buffer types (bytes)
  • Signals – Events from UI to backend with byte payloads
  • Options – Key/value preprocessing hints for the frontend

Installation

pip install nil-xit

Quick Start

import nil_xit
import nil_service

# Create HTTP server on 127.0.0.1:1101
http = nil_service.create_http_server("127.0.0.1", 1101, 100 * 1024 * 1024)

# Setup server with asset paths
nil_xit.setup_server(http, ["assets"])

# Create websocket event service
ws = http.use_ws("/ws")

# Create core from web service and websocket event
core = nil_xit.create_core(http, ws)

# Add a frame
frame = core.add_unique_frame(
    "index",
    nil_xit.FileInfo(group="base", path="gui/Demo.svelte"),
)
frame.add_option("index_mode", "demo")

# Add a value with getter and setter (buffer type)
def encode_value() -> bytes:
    return b"hello world"

def decode_value(data: bytes) -> None:
    print(f"value changed: {data.decode('utf-8')}")

value = frame.add_value("my_value", encode_value, decode_value)

# Add a signal handler (payload is bytes; you can ignore it if unused)
def on_button_click(payload: bytes) -> None:
    print(f"Button clicked! payload size: {len(payload)}")
    value.post(b"updated value")

frame.add_signal("click", on_button_click)

# Add preprocessing options for the frontend
frame.add_option("theme", "dark")

# Main loop
while True:
    http.poll()

For a complete example, see sandbox/main.py.

Supported Types

The Python binding supports buffer types only:

  • bytes – Binary data passed as buffer_type<T> in C++
    • Values use getter/setter functions that work with bytes
    • Signals pass byte payloads (handlers may ignore the payload argument)

Frames and FileInfo

Frame creation accepts an optional FileInfo that defines the asset group and relative path used by the frontend.

frame = core.add_unique_frame(
    "index",
    nil_xit.FileInfo(group="base", path="gui/Demo.svelte"),
)

Architecture

The Python binding wraps the C API (libnil-xit-c-api.so) which provides access to:

  • unique frames – Single-instance UI components
  • tagged frames – Multi-instance UI components (keyed by tag)
  • values – Bidirectional data binding with buffer types
  • signals – Events from UI to backend with byte payloads

Documentation

For detailed API documentation and more examples, visit:

License

CC BY-NC-ND 4.0

Support

For issues, questions, or contributions, visit the GitHub repository.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

nil_xit-0.3.17-py3-none-manylinux_2_39_x86_64.whl (1.6 MB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

nil_xit-0.3.17-py3-none-any.whl (1.6 MB view details)

Uploaded Python 3

File details

Details for the file nil_xit-0.3.17-py3-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for nil_xit-0.3.17-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 061aabb5f0f5e07bf035cb274db633f3f8644dc6a61b8045cf466a2aa915d925
MD5 e1df6c8f805561317bb1f85da92cd260
BLAKE2b-256 ac5927cdc05be4251d3b0dfe9c158da3553f3f58758dd7be0cfbd2352d13bcd7

See more details on using hashes here.

File details

Details for the file nil_xit-0.3.17-py3-none-any.whl.

File metadata

  • Download URL: nil_xit-0.3.17-py3-none-any.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for nil_xit-0.3.17-py3-none-any.whl
Algorithm Hash digest
SHA256 4e01fccc9e1e18030b4f859720e3af1c606c4acd48b66c646bc4b20a121bbc5d
MD5 9f662c9bd2ed659c247246423bff1c17
BLAKE2b-256 66649465364dfea29b08575040d46c08431778e029c5c563ae529f6c4e6f69b4

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