Skip to main content

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

Examples

Asynchronous Server

kcp.py features an implementation of an asynchronous server using the event loop protocol API.

from kcp.server import Connection
from kcp.server import KCPServerAsync

# Create the initial server instance.
server = KCPServerAsync(
    "127.0.0.1",
    9999,
    conv_id=1,
    no_delay=True,
)

# Ability to set performance options after initialisation.
server.set_performance_options(
    update_interval=10,
)


# Ran when the server starts.
@server.on_start
async def on_start() -> None:
    print("Server started!")


# Ran when a connection is made.
@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 client 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-0.1.4.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

kcp-0.1.4-cp39-cp39-win_amd64.whl (62.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

File details

Details for the file kcp-0.1.4.tar.gz.

File metadata

  • Download URL: kcp-0.1.4.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for kcp-0.1.4.tar.gz
Algorithm Hash digest
SHA256 eec536c27df89ed57e97436eefd2e3641f144444285cc629674bf3e2239cf46c
MD5 6bea57392e9ce1263c6fca82ad40fd0b
BLAKE2b-256 0fb802b682b99f690c6f3fb65290f96dec8e9cce3c2da14352e8711cec4a724c

See more details on using hashes here.

File details

Details for the file kcp-0.1.4-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: kcp-0.1.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 62.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for kcp-0.1.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f0cd79a9c5ebc7485f0b8be0909b8b496d62f1787e4cf008a6bb9ab6dfcb4dc7
MD5 abb8cd00c26a5045abbb4b1c4840d3c3
BLAKE2b-256 56719977aef5f3391029943949fb4092da1a57987568be6f48f7566a387e7597

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page