Skip to main content

Pyintercon is a python module to connect a server and clients allowing them to exchange information

When an instance of Client sends a request to an instance of Server, the value returned by the request handler function is the response sent to the client.
See below for how to set a request handler function and how it works

Installation

    pip install pyintercon

Example:

Server:

    >>> from pyintercon import Server

    >>> # initialize the server
    >>> sv = Server()

    >>> # run the server using hostname and port
        # the default hostname is "localhost"
    >>> sv.activate("", 8080)
    """Server is activated on localhost:8080...
    Tap CTRL + C to quit !!!!!"""

Client

    >>> from pyintercon import Client

    >>> # initialize the client
    >>> cl = Client()

    >>> # connect client to server by calling the connect method with $hostname and $port used as for server.activate
    >>> cl.connect("localhost", 8080)


    # you will get on server side a message like this
    >>> """ server output:
            ('127.0.0.1', 44042) is connected ...
        """

    >>> # You are ready to go with pyintercon
    >>> # You can send a request to server by calling the send method of the client instance
    >>> response = cl.send({ message: "Hello World !" })

    >>> print(response)
    {'status': 1, 'message': 'default'}
    >>> # use disconnect method to disconnect from the server
    >>> cl.disconnect()

    # you will get on server side a message like this
    >>> """ server output:
            ('127.0.0.1', 44042) is disconnected ...
        """

The server manage the request by executing the request handler function and sends its returned value as response

This function takes the request data (dict object) and returns the a value which will be used as response. The default handler returns {"status": 1, "message": "default"} for everything.
This can be edited by setting a custom handler using setRequestHandler method

   >>> sv = Server()
   >>> server.setRequestHandler(your_handler_function)

See example below

Example:

Server

from pyintercon import Server

def response_loader(request):
    """ Just reverse the message content.
        It takes dict object and returns dict object

    """

    res = {"message": request["message"][::-1]}

    return res

def main():
    sv = Server()

    # set the request handler function
    sv.setRequestHandler(response_loader)

    sv.activate("localhost", 8080)

if __name__ == "__main__":
    main()

Client

    >>> from pyintercon import Client
    >>> cl = Client()
    >>> cl.connect("localhost", 8080)
    >>> res = cl.send({"message": "Hello World !"})
    >>>
    >>> print(res)
    {"message": "! dlroW olleH"}

Features:

  • Add more events, possibility to emit events.
    client.emit("event_name", callback_function)
    
    at the moment sending the request is considered as the only event

Release files for pyintercon 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyintercon 2.1.2
File Size Uploaded
pyintercon-2.1.2.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyintercon 2.1.2
File Interpreter ABI Platform
pyintercon-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / pyintercon-2.1.2.tar.gz

Download URL pyintercon-2.1.2.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
785ad59f7d9c9fa98be1811a7647841099d06b153ccd71245bb2334ec2e8cbcd
BLAKE2b-256 checksum
How to use checksums
b806d1081c43385545c3c137c79ac34883b6d00cba44428888508efcda12d8d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release files / pyintercon-2.1.2-py3-none-any.whl

Download URL pyintercon-2.1.2-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9c3c9446dcf88a339fd151d1c5c123bdecdc9e66e310c5e62386e6e76536c39
BLAKE2b-256 checksum
How to use checksums
5e3e7d60d48d68977fcadc45e9580abc322fcf732129ee8fa0ff1f4b6b4054db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files

2.1.1

2 release files

2.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page