Skip to main content

High-performance networking service toolkit with support for TCP, UDP, WebSocket, HTTP, and pipes

Project description

nil-service Python Binding

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 Distribution

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

nil_service-1.0.16rc2-cp312-cp312-manylinux_2_39_x86_64.whl (750.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

File details

Details for the file nil_service-1.0.16rc2-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for nil_service-1.0.16rc2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 4ebb3e1f90bb6963e1e7e54588f8a5e5c77468beb18c6c6e49c00c2a0a0122d4
MD5 ec05e28aa75d1de50e2d853de57e317a
BLAKE2b-256 fca387a4f107fd5eb9c28f093b27bd1f564de0c661014702ac7ed17539a93478

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