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

Just the raw connection

While kcp.py features a diverse set of pre-implemented uses of KCP (see below), it also allows you to directly manage your KCP connections. Here is an example using two independent connections locally.

from kcp import KCP

# Create two connections using the same conversation ID.
kcp1 = KCP(
    conv_id=1,
)

kcp2 = KCP(
    conv_id=1,
)

# Update their timing information.
kcp1.update()
kcp2.update()


# Set each connection to send data to the other one (usually this would go through some network layer, but
# for the purpose of the example we do this).
@kcp1.outbound_handler
def send_kcp1(_, data: bytes) -> None:
    kcp2.receive(data)


@kcp2.outbound_handler
def send_kcp2(_, data: bytes) -> None:
    kcp1.receive(data)

# Enqueue data to be sent and send it off.
kcp1.enqueue(b"Hello, world!")
kcp1.flush()

print(kcp2.get_received()) # b"Hello, world!"

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.6.tar.gz (22.5 kB view details)

Uploaded Source

Built Distributions

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

kcp-0.1.6-cp313-cp313-win_amd64.whl (74.5 kB view details)

Uploaded CPython 3.13Windows x86-64

kcp-0.1.6-cp313-cp313-manylinux_2_39_x86_64.whl (333.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

kcp-0.1.6-cp313-cp313-macosx_14_0_arm64.whl (133.8 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

kcp-0.1.6-cp312-cp312-win_amd64.whl (75.0 kB view details)

Uploaded CPython 3.12Windows x86-64

kcp-0.1.6-cp312-cp312-manylinux_2_39_x86_64.whl (331.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

kcp-0.1.6-cp312-cp312-macosx_14_0_arm64.whl (135.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

kcp-0.1.6-cp311-cp311-win_amd64.whl (76.1 kB view details)

Uploaded CPython 3.11Windows x86-64

kcp-0.1.6-cp311-cp311-manylinux_2_39_x86_64.whl (350.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.39+ x86-64

kcp-0.1.6-cp311-cp311-macosx_14_0_arm64.whl (137.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

kcp-0.1.6-cp310-cp310-win_amd64.whl (76.0 kB view details)

Uploaded CPython 3.10Windows x86-64

kcp-0.1.6-cp310-cp310-manylinux_2_39_x86_64.whl (327.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.39+ x86-64

kcp-0.1.6-cp310-cp310-macosx_14_0_arm64.whl (136.9 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

kcp-0.1.6-cp39-cp39-win_amd64.whl (76.1 kB view details)

Uploaded CPython 3.9Windows x86-64

kcp-0.1.6-cp39-cp39-manylinux_2_39_x86_64.whl (328.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.39+ x86-64

kcp-0.1.6-cp39-cp39-macosx_14_0_arm64.whl (137.4 kB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

kcp-0.1.6-cp38-cp38-win_amd64.whl (76.3 kB view details)

Uploaded CPython 3.8Windows x86-64

kcp-0.1.6-cp38-cp38-manylinux_2_39_x86_64.whl (333.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.39+ x86-64

kcp-0.1.6-cp38-cp38-macosx_14_0_arm64.whl (138.8 kB view details)

Uploaded CPython 3.8macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: kcp-0.1.6.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.8 Darwin/23.6.0

File hashes

Hashes for kcp-0.1.6.tar.gz
Algorithm Hash digest
SHA256 1e3632509119bd6a24599ee043e21ef6842675413a41720c526d14896357afc4
MD5 2d68f31ab7daa9f5248098015395c429
BLAKE2b-256 3c8218cff233d7a848788450ae2a4341d5f54bb19afb0d5dd3a06be76ebca953

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 74.5 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Windows/2022Server

File hashes

Hashes for kcp-0.1.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3c1b2f90f15e55ec76b929dd8d29bed4b4eadc234addefd2b8be5f0f3acf822d
MD5 f43cb0a625a16d8e83b0ea56b0b18a97
BLAKE2b-256 24bd17c07c4b142ad3a6c8d236ef5ff23951516ff766ee524ec675b5b5c34202

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp313-cp313-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 333.0 kB
  • Tags: CPython 3.13, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Linux/6.8.0-1017-azure

File hashes

Hashes for kcp-0.1.6-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 ee78627a02e908c225c669b7cc8654b825296fb8133f2a1556f633b72e9dad3e
MD5 011642315bb4b58dbc10d5a3a950a05e
BLAKE2b-256 eb5a0c06c2c7a4cdafe32ffa7bd7820959e30b1d8c5055f3dcf049118c693180

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp313-cp313-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 133.8 kB
  • Tags: CPython 3.13, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Darwin/23.6.0

File hashes

Hashes for kcp-0.1.6-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c2327d597628c4d654ff7d7663701f0de7587f4c840796eaff096fd31ae004e9
MD5 ac11b486f1fd227b450db4fdf11e9278
BLAKE2b-256 bcefb7f1663992ea73a92c67099c6d61bbfd72bcaee1499b80bb06dfa756a513

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 75.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.8 Windows/2022Server

File hashes

Hashes for kcp-0.1.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e742cbc3052f4f6b986371ad47e46e386093b7633228280c09180a0b56f40c74
MD5 e6ac42f9c95d394a697ccf7de9ce4dcf
BLAKE2b-256 1a02752dc922e2c75080918e1158a7747a27f64ad622c964b430c2d6e16c2039

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp312-cp312-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 331.1 kB
  • Tags: CPython 3.12, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.8 Linux/6.8.0-1017-azure

File hashes

Hashes for kcp-0.1.6-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 005a5960317762afdbddd701c334e2a1aaadc27be31cdfd8fc3d0827265f1b1b
MD5 05e739e6468989067727a2647ca2ba00
BLAKE2b-256 8a9fd978a36a026af425ee18b18d0997288c1148c3c90f888e8fed26c0829ad3

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp312-cp312-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 135.5 kB
  • Tags: CPython 3.12, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.8 Darwin/23.6.0

File hashes

Hashes for kcp-0.1.6-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 512a92d324a277b0b095a611a1e4d42680e9524e4136f97b105417f5f17799d7
MD5 70961c04fd2592ca043cea54fa99ec22
BLAKE2b-256 b6cefac912517be962a5bc5bc934e834d9691b85ee0b853c78dac585e7753a87

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 76.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.9 Windows/10

File hashes

Hashes for kcp-0.1.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6a481bfc1e595cb9e6c7c8b33673c032b455beccb9794ebc6dd62be841314b6e
MD5 4c6301a34ee863d30aef9dd9cdeac897
BLAKE2b-256 590af57e16ad03998c381015c50ebcac67e1a15e891bdaa06f2c6c62a81bcb1e

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp311-cp311-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 350.7 kB
  • Tags: CPython 3.11, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.11 Linux/6.8.0-1017-azure

File hashes

Hashes for kcp-0.1.6-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 da4aa6acbdfdfd25a64841b7b13e8063098cd0b613d8475ccf3b7f22dfd22d64
MD5 0552ef236f75e7094e73427707728f32
BLAKE2b-256 eac6a25c139498666adb8b09968492ffe9e6b4f914e2db79164dca572c81550e

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp311-cp311-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 137.4 kB
  • Tags: CPython 3.11, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.9 Darwin/23.6.0

File hashes

Hashes for kcp-0.1.6-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d5f95fe061a6b611e74a43bc0b038403a5c4e60e3fd8f321e089916a8f82f3e5
MD5 5c814da724b4d0edc7f46704b749cfac
BLAKE2b-256 f305d21d2ebd0daf76893727f4afd68423e11c05f01809307d15059724c0ca28

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 76.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.11 Windows/10

File hashes

Hashes for kcp-0.1.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d2c973b58504a43a1569d4ce9a7acd7a61fbb78aaef8ba735f00d497e53bda28
MD5 a9c5d1ebdc99dba82180b56d7fbd55fc
BLAKE2b-256 8b0e8b214f98fafc1bdda953c4c3f3197c0e5495eece64ddf97dce6c1a0205c8

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp310-cp310-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp310-cp310-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 327.2 kB
  • Tags: CPython 3.10, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.15 Linux/6.8.0-1017-azure

File hashes

Hashes for kcp-0.1.6-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 a9e974a11014043486b05ab88ea4b460820f17ae6f8f5ea1223cd74603e6ddd7
MD5 6f6c3515be7b5e69e794d4e5df77937c
BLAKE2b-256 c1b894e2e1fb4eacce717af0a891156627a905da393d7d235148da1c86ed9340

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp310-cp310-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 136.9 kB
  • Tags: CPython 3.10, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.11 Darwin/23.6.0

File hashes

Hashes for kcp-0.1.6-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7a7d49e22f19ab7fedaa1d2f6790865fd79172ce5623c385e32c39b0e6fd9d9d
MD5 15ac9b0539eae694d4d5721835e6f31e
BLAKE2b-256 583e70c8fd49739f388c9a0453264bc915d8a7e0bb5be146686d240ad2bd9a00

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kcp-0.1.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 76.1 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.9.13 Windows/10

File hashes

Hashes for kcp-0.1.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 70abddc571eee49e20b30a88139e2abc3202edd59b6d36cd6f29127004bdedf1
MD5 b249b67aac249a5410dca7860edc011b
BLAKE2b-256 8cb16d2d2a232b4ce7ffdb297f5404a4204baafcdefda0dfe168fdc19dba3ce6

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp39-cp39-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp39-cp39-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 328.8 kB
  • Tags: CPython 3.9, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.9.20 Linux/6.8.0-1017-azure

File hashes

Hashes for kcp-0.1.6-cp39-cp39-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 d8aa34931521ebc791e662b9a538c1c5f82c81c8b3a73c4b4bb7f72b11fde4c4
MD5 baeba87ad9932ab0f29f9fb9fe9ec97f
BLAKE2b-256 3a9de150f9bf2dfb010fec60aef501c27cc60107f8627fceefb6c7270c42f38b

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp39-cp39-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 137.4 kB
  • Tags: CPython 3.9, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.9.13 Darwin/23.6.0

File hashes

Hashes for kcp-0.1.6-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6e8cf8ef2e8094c5e4791540352aba0802bc65d8fb2f565659d86e53939b8689
MD5 489be451cbffaad5494a9f9df0eb8919
BLAKE2b-256 984b3eac0c8bf7c59086a5d44144446fe163c6ec59e615c63de2a502164ea7b1

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 76.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.10 Windows/10

File hashes

Hashes for kcp-0.1.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9c568788168f95f746137aaab2e4c576906b11ce622543a4b2b6fca3ff92bfd1
MD5 12794bdc7c09f580ef94a6f79a055b02
BLAKE2b-256 1797e7e34073914d9e703bf58e890016ffbc0b90e887d86c4918dd8c24e80014

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp38-cp38-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp38-cp38-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 333.8 kB
  • Tags: CPython 3.8, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.18 Linux/6.8.0-1017-azure

File hashes

Hashes for kcp-0.1.6-cp38-cp38-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 f0c69b253f02614d8aeff2e3826370b38046a3a9af9fdce33a7114fbe977ec74
MD5 6a171993532fb260909197a3b0c123db
BLAKE2b-256 c9271ccf1ac497c7845dee827a996a5c658ec0506c6c72342b9f79675b7c5cca

See more details on using hashes here.

File details

Details for the file kcp-0.1.6-cp38-cp38-macosx_14_0_arm64.whl.

File metadata

  • Download URL: kcp-0.1.6-cp38-cp38-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 138.8 kB
  • Tags: CPython 3.8, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.10 Darwin/23.6.0

File hashes

Hashes for kcp-0.1.6-cp38-cp38-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0a46d42de2161893a6aece95417ac01cef8a87e1b5ee0619151797654ad6a0ca
MD5 b9cd92d87b853709421597889db153df
BLAKE2b-256 90477d9fdf2f1536300f3513778577e1b7fd673924b4d11b174ac69fd1b66b6c

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