Skip to main content

p2p connection over TCP made dead simple!

Project description

peerpy 1.0.0

Discover and connect every device running python on a local network via TCP!

This module provides a high-level API for discovering and connecting multiple devices on a local network, without the headache of implementing python's built-in socket module!

Installation

pip install peerpy

Quick tour

Connecting two devices running python is as easy, reliable and painless as 8 lines of code!

Start by importing the Peer class, which automatically detects your device's local IP and run a socket server, listening on a given port:

from peerpy import Peer

Start a peer object on the listening device:

with Peer(port=54865) as peer:
    # let the program run until CTRL+C
    while True:
        time.sleep(1.)

Connect your second device to your listening device:

with Peer(port=12152) as peer:
    connection = peer.connect("192.168.0.2:54865")

    if connection:
        connection.send(f"Hello world from {peer.address_name}!")

You can even add handlers which are executed on a separate thread on specific events, such as:

def set_connection_handler(connection):
    connection.set_handler("data", lambda data: print(data))

with Peer(handlers={
    # called when socket server is listening
    "listen": lambda peer: print(peer.address_name),
    # called when socket has established a connection
    "connection": set_connection_handler,
    # called when socket server has stopped
    "stop": lambda peer: print("Peer stopped!")
}) as peer:

For more details on handlers and connections, please consider reading the documentation.

Examples

To begin with this module, please consider reading the examples given on this repository.

Documentation

For further documentation, please Read The Docs!

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

peerpy-1.2.2.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

peerpy-1.2.2-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file peerpy-1.2.2.tar.gz.

File metadata

  • Download URL: peerpy-1.2.2.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for peerpy-1.2.2.tar.gz
Algorithm Hash digest
SHA256 a82834af41e38732ddf1541f3f1ef0936bdfd3ac99433c16df260947da06432a
MD5 b0dc22dec047ce821bca0d2c0dd37c79
BLAKE2b-256 6b6539cb310a2af9ef22496d20e12a05bb1dd9fb3ac6e28f0ce04b538960e283

See more details on using hashes here.

File details

Details for the file peerpy-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: peerpy-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for peerpy-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b8dac330e23391b2942da75c59e08db7ea20605cdb2f98724420baee7f22c700
MD5 dc6e954d8fb24ec985a6cfb0882c789a
BLAKE2b-256 e90476023d54f683086981513362f414ebbb75bd34c315cd995f73211c5c9efb

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