Skip to main content

Python binding for nil-service: boost net library wrapper

Project description

nil-service

Python bindings for nil-service - a high-performance networking service toolkit for building client/server applications.

Features

  • Multiple Protocols: UDP, TCP, WebSocket, HTTP, and pipe support
  • Client & Server Modes: Flexible role-based service creation
  • Event-Driven API: Async-friendly event handlers
  • Lightweight: Minimal dependencies, built on C++ for performance
  • Cross-Platform: Support for POSIX systems

Installation

pip install nil-service

Quick Start

Basic Server

from nil_service import Service

# Create an HTTP server
server = Service.http_server(port=8000)

@server.on_ready
def on_ready():
    print("Server started")

@server.on_message
def on_message(connection_id, data):
    # data is bytes
    text = data.decode("utf-8", errors="replace")
    print(f"Received from {connection_id}: {text}")
    server.send(connection_id, b"Hello back!")

server.run()

WebSocket Server

from nil_service import Service

server = Service.http_server(port=8000)
ws = server.use_ws("/ws")

@ws.on_connect
def on_connect(connection_id):
    print(f"Client {connection_id} connected")

@ws.on_message
def on_message(connection_id, data):
    text = data.decode("utf-8", errors="replace")
    print(f"Received: {text}")
    ws.publish(data)  # Broadcast to all (data is bytes)

server.run()

TCP Client

from nil_service import Service

client = Service.tcp_client(host="localhost", port=9000)

@client.on_connect
def on_connect(connection_id):
    client.send(connection_id, b"Hello Server!")

@client.on_message
def on_message(connection_id, data):
    text = data.decode("utf-8", errors="replace")
    print(f"Received: {text}")

client.run()

Service Types

Protocol Mode Use Case
self standalone Loopback/echo service
udp client/server Connectionless messaging
tcp client/server Reliable stream transport
ws client/server WebSocket communication
http server Web server with routing
pipe standalone POSIX named pipes

API Reference

Service Methods

  • run() - Block and run the event loop
  • poll() - Process pending events (non-blocking)
  • stop() - Stop the service
  • send(connection_id, data) - Send to a specific connection
  • publish(data) - Broadcast to all connections

Event Handlers

  • @service.on_ready - Service initialized
  • @service.on_connect - New connection
  • @service.on_disconnect - Connection closed
  • @service.on_message - Data received (bytes)

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_service-1.0.20-py3-none-manylinux_2_39_x86_64.whl (750.8 kB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

nil_service-1.0.20-py3-none-any.whl (750.5 kB view details)

Uploaded Python 3

File details

Details for the file nil_service-1.0.20-py3-none-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for nil_service-1.0.20-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 e471819969355147615b1d6571caae07b97f9e9b3fa0268d0cb209b9fe2eea45
MD5 edd1303f2ffe4e2bd24f7735594e26f5
BLAKE2b-256 6d0dc616c55eed830f1e710873ace3ae223f0fc5b7540420a5f36f3d92534637

See more details on using hashes here.

File details

Details for the file nil_service-1.0.20-py3-none-any.whl.

File metadata

  • Download URL: nil_service-1.0.20-py3-none-any.whl
  • Upload date:
  • Size: 750.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for nil_service-1.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 b53866e1b6cdbb9d1dc743d6afe193e15b279b09ed30d8c42eea236d87b6817b
MD5 097913c20042a53808c4e84f034ecc6d
BLAKE2b-256 83f9016e5bccb37e26817ca7a72fc20c0706dca6703eb689566f87adebaa417d

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