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):
    print(f"Received from {connection_id}: {data}")
    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):
    ws.publish(data)  # Broadcast to all

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):
    print(f"Received: {data}")

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

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.17-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.17-py3-none-any.whl (750.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for nil_service-1.0.17-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 3999b954ab4a07bb66ff891d7d57cde3bbcd54ada07629685185255af8d744ea
MD5 de9c4c300b2055bdee0a76bd592917bc
BLAKE2b-256 a38bcb4fb1637a79aeaa2f6a4364766c15f2918461912ffe59ca98bfbfaa5dce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nil_service-1.0.17-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.17-py3-none-any.whl
Algorithm Hash digest
SHA256 21526f4f52a8f89665d5eb4f548a55a00e8648c87419830cb366bedd3e38d0c5
MD5 dda1ece50dbd8531484b434cc60b859f
BLAKE2b-256 12f525636170f90daac060b6ea7e13a614d171698c9852bf110b88069091e312

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