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 looppoll()- Process pending events (non-blocking)stop()- Stop the servicesend(connection_id, data)- Send to a specific connectionpublish(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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nil_service-1.0.18-py3-none-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: nil_service-1.0.18-py3-none-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 750.9 kB
- Tags: Python 3, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
442dcba266e27ac41e84968cee1023367defa986e30dec24c6d8ae3304be96d5
|
|
| MD5 |
366d590a7922fac53ffca528d2e3ed05
|
|
| BLAKE2b-256 |
063f233b576e0c3abbd583f291851c376c8228041a0acf4f850446d415129b14
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52c6cfeccd5a944e44664f30ab822d636d89cc139e2b8edb7f9877b779895805
|
|
| MD5 |
46ed6247e5ec13b41f09a7cc6bef5b16
|
|
| BLAKE2b-256 |
cbf47840aae17cf8a0daa01d56703e1ba571439a9960195b0cb12e2df6f723a3
|