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.18-py3-none-manylinux_2_39_x86_64.whl (750.9 kB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

nil_service-1.0.18-py3-none-any.whl (750.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for nil_service-1.0.18-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 442dcba266e27ac41e84968cee1023367defa986e30dec24c6d8ae3304be96d5
MD5 366d590a7922fac53ffca528d2e3ed05
BLAKE2b-256 063f233b576e0c3abbd583f291851c376c8228041a0acf4f850446d415129b14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nil_service-1.0.18-py3-none-any.whl
  • Upload date:
  • Size: 750.6 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.18-py3-none-any.whl
Algorithm Hash digest
SHA256 52c6cfeccd5a944e44664f30ab822d636d89cc139e2b8edb7f9877b779895805
MD5 46ed6247e5ec13b41f09a7cc6bef5b16
BLAKE2b-256 cbf47840aae17cf8a0daa01d56703e1ba571439a9960195b0cb12e2df6f723a3

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