pynetmanager


Namepynetmanager JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/AdityaIyer2k7/pynetmanager
SummaryA FOSS library to simplify writing and handling sockets in Python. Includes INET and INET6 support, `bind`, `listen`, `accept`, `connect` API.
upload_time2023-12-22 18:21:27
maintainer
docs_urlNone
authorAdityaIyer2k7
requires_python>=3.6
license
keywords python python 3 socket sockets network networks networking
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pynetmanager
A FOSS library to simplify writing and handling sockets in Python. Includes INET and INET6 support, `bind`, `listen`, `accept`, `connect` API.

## Description
This repositiory contains the source code for the `pynetmanager` library. This is my second and (hopefully) better networking wrapper library, the first being [pyNetSocket](https://github.com/AdityaIyer2k7/pyNetSocket).

Improvements over `pyNetSocket`:
- Direct IPv6 support (through `AF_INET6`)
- Direct `SOCK_RAW` support
- Support functions to generate socket objects
- Use of threading to avoid blocking
- PEP8 compliance

## Installation
Install directly from `pip` using
```
pip install pynetmanager
```

or download the library from the [GitHub repo](https://github.com/AdityaIyer2k7/pynetmanager) using
```
git clone https://github.com/AdityaIyer2k7/pynetmanager
```

## Usage - Scripting

### Creating a Network Event Callback
Defining the function:
```py
def some_func(conn, addr, data, queues):
    '''
    This function will be called when a network event (binding or connection) occurs
    Parameters:
     - conn: The socket object linked to the event
     - addr: The other side's address
     - data: The miscellaneous data being passed to the function, either Iterable or None
     - queues: An iterable (list or dict) of queues between processes
    '''
    print(f"Address {addr} has connected")
```

Creating the callback:
```py
from pynetmanager import NetCallback
from multiprocessing import Queue

myQueues = [Queue(), Queue()]
callback = NetCallback(func=some_func, queues=myQueues)
```

Running the callback (using `someConn` and `someAddr`):
```py
callback.start(conn=someConn, addr=someAddr, data=None)
```
---

### Running a generic Server (AF_INET, SOCK_STREAM)
Setup the server:
```py
from pynetmanager import SvrManager, deafult_socket_inet_stream

server_socket = deafult_socket_inet_stream()
server_address = ("127.0.0.1", 5500)
server = SvrManager(server_socket, server_address)
```

Assign callbacks:
```py
# Bind Callbacks are called when the server binds to its address
myBindCallbacks = [bindCallback1, bindCallback2]

# Conn Callbacks are called when a client connects to the server
myConnCallbacks = [connCallback1, connCallback2, connCallback3]

# Always use '+=' to add two lists
# do NOT replace any server.xxxxCallbacks unless you know what you're doing
server.bindCallbacks += myBindCallbacks
server.connCallbacks += myConnCallbacks
```

Bind the server:
```py
# If `listenByDeault` is True, the server starts listening for and 
# accepting clients as soon as it binds to its address
server.bind(listenByDefault=False)
```

Listen for clients (Skip if you set `listenByDefault` as True):
```py
# This function does not require parameters
server.listen_and_accept(None, None, None, None)
```

To list connected clients:
```py
server.clients
# OUTPUT:
# [
#   (<socket.socket ...>, ('127.0.0.1', 65028)),
#   (<socket.socket ...>, ('127.0.0.1', 62157)),
#   ...
#   (conn, addr)
# ]
```

To access open queues
```py
server.recvQueues
# OUTPUT:
# {
#   (<socket.socket ...>, ('127.0.0.1', 65028)): <multiprocessing.queues.Queue ...>,
#   (<socket.socket ...>, ('127.0.0.1', 62157)): <multiprocessing.queues.Queue ...>,
#   ...
#   (conn, addr): <multiprocessing.queues.Queue ...>,
# }
```
---

### Running a generic Client (AF_INET, SOCK_STREAM)
Setup the client:
```py
from pynetmanager import CliManager, deafult_socket_inet_stream

client_socket = deafult_socket_inet_stream()
server_address = ("127.0.0.1", 5500) # Note that we use the server's address here since that is what we are connecting to
client = CliManager(client_socket, server_address)
```

Assign callbacks:
```py
# Conn Callbacks are called when the client connects to the server
myConnCallbacks = [connCallback1, connCallback2, connCallback3]

# Always use '+=' to add two lists
# do NOT replace any client.xxxxCallbacks unless you know what you're doing
client.connCallbacks += myConnCallbacks
```

Connect the client:
```py
client.bind()
```

To access the queue of received messages
```py
client.recvQueue
# OUTPUT:
# <multiprocessing.queues.Queue object at ...>
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AdityaIyer2k7/pynetmanager",
    "name": "pynetmanager",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "python,python 3,socket,sockets,network,networks,networking",
    "author": "AdityaIyer2k7",
    "author_email": "adityaiyer2007@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/39/81/c52febb676d34290ba97dc455471d31ec0ccb4564a554d278775d4c96128/pynetmanager-1.0.0.tar.gz",
    "platform": null,
    "description": "# pynetmanager\nA FOSS library to simplify writing and handling sockets in Python. Includes INET and INET6 support, `bind`, `listen`, `accept`, `connect` API.\n\n## Description\nThis repositiory contains the source code for the `pynetmanager` library. This is my second and (hopefully) better networking wrapper library, the first being [pyNetSocket](https://github.com/AdityaIyer2k7/pyNetSocket).\n\nImprovements over `pyNetSocket`:\n- Direct IPv6 support (through `AF_INET6`)\n- Direct `SOCK_RAW` support\n- Support functions to generate socket objects\n- Use of threading to avoid blocking\n- PEP8 compliance\n\n## Installation\nInstall directly from `pip` using\n```\npip install pynetmanager\n```\n\nor download the library from the [GitHub repo](https://github.com/AdityaIyer2k7/pynetmanager) using\n```\ngit clone https://github.com/AdityaIyer2k7/pynetmanager\n```\n\n## Usage - Scripting\n\n### Creating a Network Event Callback\nDefining the function:\n```py\ndef some_func(conn, addr, data, queues):\n    '''\n    This function will be called when a network event (binding or connection) occurs\n    Parameters:\n     - conn: The socket object linked to the event\n     - addr: The other side's address\n     - data: The miscellaneous data being passed to the function, either Iterable or None\n     - queues: An iterable (list or dict) of queues between processes\n    '''\n    print(f\"Address {addr} has connected\")\n```\n\nCreating the callback:\n```py\nfrom pynetmanager import NetCallback\nfrom multiprocessing import Queue\n\nmyQueues = [Queue(), Queue()]\ncallback = NetCallback(func=some_func, queues=myQueues)\n```\n\nRunning the callback (using `someConn` and `someAddr`):\n```py\ncallback.start(conn=someConn, addr=someAddr, data=None)\n```\n---\n\n### Running a generic Server (AF_INET, SOCK_STREAM)\nSetup the server:\n```py\nfrom pynetmanager import SvrManager, deafult_socket_inet_stream\n\nserver_socket = deafult_socket_inet_stream()\nserver_address = (\"127.0.0.1\", 5500)\nserver = SvrManager(server_socket, server_address)\n```\n\nAssign callbacks:\n```py\n# Bind Callbacks are called when the server binds to its address\nmyBindCallbacks = [bindCallback1, bindCallback2]\n\n# Conn Callbacks are called when a client connects to the server\nmyConnCallbacks = [connCallback1, connCallback2, connCallback3]\n\n# Always use '+=' to add two lists\n# do NOT replace any server.xxxxCallbacks unless you know what you're doing\nserver.bindCallbacks += myBindCallbacks\nserver.connCallbacks += myConnCallbacks\n```\n\nBind the server:\n```py\n# If `listenByDeault` is True, the server starts listening for and \n# accepting clients as soon as it binds to its address\nserver.bind(listenByDefault=False)\n```\n\nListen for clients (Skip if you set `listenByDefault` as True):\n```py\n# This function does not require parameters\nserver.listen_and_accept(None, None, None, None)\n```\n\nTo list connected clients:\n```py\nserver.clients\n# OUTPUT:\n# [\n#   (<socket.socket ...>, ('127.0.0.1', 65028)),\n#   (<socket.socket ...>, ('127.0.0.1', 62157)),\n#   ...\n#   (conn, addr)\n# ]\n```\n\nTo access open queues\n```py\nserver.recvQueues\n# OUTPUT:\n# {\n#   (<socket.socket ...>, ('127.0.0.1', 65028)): <multiprocessing.queues.Queue ...>,\n#   (<socket.socket ...>, ('127.0.0.1', 62157)): <multiprocessing.queues.Queue ...>,\n#   ...\n#   (conn, addr): <multiprocessing.queues.Queue ...>,\n# }\n```\n---\n\n### Running a generic Client (AF_INET, SOCK_STREAM)\nSetup the client:\n```py\nfrom pynetmanager import CliManager, deafult_socket_inet_stream\n\nclient_socket = deafult_socket_inet_stream()\nserver_address = (\"127.0.0.1\", 5500) # Note that we use the server's address here since that is what we are connecting to\nclient = CliManager(client_socket, server_address)\n```\n\nAssign callbacks:\n```py\n# Conn Callbacks are called when the client connects to the server\nmyConnCallbacks = [connCallback1, connCallback2, connCallback3]\n\n# Always use '+=' to add two lists\n# do NOT replace any client.xxxxCallbacks unless you know what you're doing\nclient.connCallbacks += myConnCallbacks\n```\n\nConnect the client:\n```py\nclient.bind()\n```\n\nTo access the queue of received messages\n```py\nclient.recvQueue\n# OUTPUT:\n# <multiprocessing.queues.Queue object at ...>\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A FOSS library to simplify writing and handling sockets in Python. Includes INET and INET6 support, `bind`, `listen`, `accept`, `connect` API.",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/AdityaIyer2k7/pynetmanager"
    },
    "split_keywords": [
        "python",
        "python 3",
        "socket",
        "sockets",
        "network",
        "networks",
        "networking"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "282e1f7d27f82e6cd3d9a849d3ce3f393edaf4dc86c08a1047f92f22cbc3782b",
                "md5": "f8a118d439975439f58ed9278d30994c",
                "sha256": "e200af5e2f568474d07584549585830517554b090b504284c1feb310c2c1b5b7"
            },
            "downloads": -1,
            "filename": "pynetmanager-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f8a118d439975439f58ed9278d30994c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7588,
            "upload_time": "2023-12-22T18:21:25",
            "upload_time_iso_8601": "2023-12-22T18:21:25.156350Z",
            "url": "https://files.pythonhosted.org/packages/28/2e/1f7d27f82e6cd3d9a849d3ce3f393edaf4dc86c08a1047f92f22cbc3782b/pynetmanager-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3981c52febb676d34290ba97dc455471d31ec0ccb4564a554d278775d4c96128",
                "md5": "9ea4f34866054b06183c4ad914d58736",
                "sha256": "e4069df13b183ecb5a9f83c62f55f46216628753adb43726e39a01e2a1a4daf8"
            },
            "downloads": -1,
            "filename": "pynetmanager-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9ea4f34866054b06183c4ad914d58736",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5964,
            "upload_time": "2023-12-22T18:21:27",
            "upload_time_iso_8601": "2023-12-22T18:21:27.015021Z",
            "url": "https://files.pythonhosted.org/packages/39/81/c52febb676d34290ba97dc455471d31ec0ccb4564a554d278775d4c96128/pynetmanager-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-22 18:21:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AdityaIyer2k7",
    "github_project": "pynetmanager",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pynetmanager"
}
        
Elapsed time: 0.16933s