Python bindings and networking for the KCP protocol.
Project description
kcp.py
Python bindings and networking for the KCP protocol.
What is KCP?
KCP is a protocol focusing on low latency data delivery with a guarantee of data delivery. It serves as an alternative to the TCP protocol.
How to install?
kcp.py is available on PyPi, meaning installing is as simple as running
pip install kcp.py
Examples
Asynchronous Server
kcp.py features an implementation of an asynchronous servers using the event loop protocol API.
from kcp.server import Connection
from kcp.server import KCPServerAsync
server = KCPServerAsync(
"127.0.0.1",
9999,
conv_id=1,
)
@server.on_start
async def on_start() -> None:
print("Server started!")
@server.on_data
async def on_data(connection: Connection, data: bytes) -> None:
print(f"Received data from {connection.address}: {data}")
server.start()
Client
kcp.py also implements a KCP clients using Python's sockets and threads.
from kcp import KCPClientSync
client = KCPClientSync(
"127.0.0.1",
9999,
conv_id=1,
)
@client.on_data
def handle_data(data: bytes) -> None:
print(data)
@client.on_start
def on_start() -> None:
print("Connected to server!")
while True:
client.send(b"Data!")
client.start()
You may find more examples in the examples
directory within the repo.
Features
- Bindings to the C implementation of KCP
- Pythonic API over said C bindings
- Asynchronous KCP Client
- Synchronous KCP Client
- Asynchronous KCP Server
- Full support for installation through pip
Credit
kcp.py uses the official KCP implementation behind the scenes.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kcp_py-0.1.3.tar.gz
(20.8 kB
view hashes)
Built Distribution
Close
Hashes for kcp_py-0.1.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfd33d2d39969d130b47eb0982cc815f708fa4bc42bd6bde8b48c1360f1bf394 |
|
MD5 | cce712968291b21f9aeed343079ccb0f |
|
BLAKE2b-256 | 7ae3eaf13c5e15b53ec9cf699215fa900eb7691451ce5bdf47bcb714c30d4547 |