Skip to main content

High-performance P2P Swarm implementation in C/Python

Project description

KadePy

High-Performance Kademlia DHT Implementation for Python

KadePy is a robust and efficient Distributed Hash Table (DHT) library implementing the Kademlia protocol. It combines a high-performance C extension core for network handling and routing with a user-friendly Python wrapper.

Features

  • High Performance: Core logic (UDP reactor, routing table, storage, protocol) implemented in C for minimal overhead and maximum throughput.
  • Cross-Platform: Fully compatible with Windows, Linux, and macOS.
  • Secure:
    • Uses ChaCha20 for optional packet encryption.
    • Implements secure random number generation (BCryptGenRandom on Windows, /dev/urandom on POSIX).
  • Concurrency: Thread-safe architecture with a dedicated network reactor thread, releasing the GIL whenever possible.
  • Easy to Use: Simple Python API for creating nodes, storing values, and finding peers.

Installation

From Source

git clone https://github.com/ON00dev/KadePy.git
cd KadePy
pip install .

Requirements

  • Python 3.10+
  • C Compiler (GCC/Clang on Linux/macOS, MSVC on Windows)

Quick Start

Basic Node

from kadepy import Swarm
import time

# Create a node on a random port
node = Swarm()
print(f"Node started on port {node.port}")

# Create another node to bootstrap
bootstrap_node = Swarm(port=8000)
print("Bootstrap node on port 8000")

# Bootstrap the first node
node.bootstrap("127.0.0.1", 8000)

# Announce a topic (hash)
topic_hash = b'\x00' * 32 # 32-byte hash
node.announce(topic_hash, node.port)

# Find peers for the topic
peers = node.get_peers(topic_hash)
print("Found peers:", peers)

# Keep alive
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("Stopping...")

Architecture

KadePy follows a hybrid architecture:

  1. C Extension (_core):

    • UDP Reactor: Handles non-blocking socket I/O using select (or platform specific polling).
    • Protocol: Implements Kademlia message serialization/deserialization.
    • Routing: Manages K-Buckets and node lookups.
    • Storage: In-memory key-value storage with expiration.
    • Crypto: ChaCha20 encryption and secure RNG.
  2. Python Wrapper (Swarm):

    • Provides a high-level API.
    • Manages the C reactor lifecycle.
    • Handles bootstrapping and iterative lookups.

Contributing

Contributions are welcome! Please check out the CONTRIBUTING.md guide for details.

  1. Fork the project.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

License

Distributed under the MIT License. See LICENSE for more information.

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

kadepy-0.1.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

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

kadepy-0.1.0-cp314-cp314-win_amd64.whl (19.3 kB view details)

Uploaded CPython 3.14Windows x86-64

File details

Details for the file kadepy-0.1.0.tar.gz.

File metadata

  • Download URL: kadepy-0.1.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for kadepy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a6cb534e7fa295101d8f8f129a3d75af241d149cfb6a8dc13dbc5d20b3ec8501
MD5 e6546b92a8a293a03700a25335de9ab5
BLAKE2b-256 a9168faebe23b8a6a958e9dac8032801e3bd876054f28dc53e1803e5cb2df0e7

See more details on using hashes here.

File details

Details for the file kadepy-0.1.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: kadepy-0.1.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for kadepy-0.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 22e286a14dcf60c75af7a33d1f244298d96c18fbc46836c948a0a8615399b196
MD5 8b04338e77cc98b5a2e69ddd11b3e9ef
BLAKE2b-256 f2e76bf48892fbac5d18af1eb72958287c6dee3e53c61ea7cf3280d53ece87cf

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