socket-throttle


Namesocket-throttle JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/remram44/python-socket-throttle
SummaryWrapper for sockets letting you limit send/recv bandwidth
upload_time2024-06-09 03:21:26
maintainerNone
docs_urlNone
authorRemi Rampin
requires_python<4.0,>=3.10
licenseMIT
keywords socket throttle bandwidth limit
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Socket throttling for Python

This tiny library contains a wrapper for sockets that can be used to limit their send and/or receive rate to a specific value.

It can be used to limit the bandwidth use of any Python code that uses sockets.

Example:

```python
import socket
from socket_throttle import LeakyBucket
from socket_throttle.sockets import SocketWrapper


sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
sock.connect(('127.0.0.1', 5000))

# Short syntax, limit sending to 2kB/s and receiving to 100kB/s
sock = SocketWrapper(sock, send=2_000, recv=100_000)

# Longer syntax, create a bucket that can be shared by multiple sockets
# Receive speed is unlimited
send_bucket = LeakyBucket(100_000, 500_000)
sock = SocketWrapper(sock, send=send_bucket)

# It works with files too
from socket_throttle.files import FileWrapper

with open('data.bin', 'rb') as file:
    file = FileWrapper(file, read=100_000)
    file.read(...)
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/remram44/python-socket-throttle",
    "name": "socket-throttle",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "socket, throttle, bandwidth, limit",
    "author": "Remi Rampin",
    "author_email": "remi@rampin.org",
    "download_url": "https://files.pythonhosted.org/packages/de/76/1486215fb2c045e54d7ecbd8742a3cad285f90242f61bb90b0de766ed339/socket_throttle-0.2.1.tar.gz",
    "platform": null,
    "description": "# Socket throttling for Python\n\nThis tiny library contains a wrapper for sockets that can be used to limit their send and/or receive rate to a specific value.\n\nIt can be used to limit the bandwidth use of any Python code that uses sockets.\n\nExample:\n\n```python\nimport socket\nfrom socket_throttle import LeakyBucket\nfrom socket_throttle.sockets import SocketWrapper\n\n\nsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)\nsock.connect(('127.0.0.1', 5000))\n\n# Short syntax, limit sending to 2kB/s and receiving to 100kB/s\nsock = SocketWrapper(sock, send=2_000, recv=100_000)\n\n# Longer syntax, create a bucket that can be shared by multiple sockets\n# Receive speed is unlimited\nsend_bucket = LeakyBucket(100_000, 500_000)\nsock = SocketWrapper(sock, send=send_bucket)\n\n# It works with files too\nfrom socket_throttle.files import FileWrapper\n\nwith open('data.bin', 'rb') as file:\n    file = FileWrapper(file, read=100_000)\n    file.read(...)\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Wrapper for sockets letting you limit send/recv bandwidth",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/remram44/python-socket-throttle",
        "Repository": "https://github.com/remram44/python-socket-throttle"
    },
    "split_keywords": [
        "socket",
        " throttle",
        " bandwidth",
        " limit"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1216350d325897a8c46623da5fe941e7bd9ef968f6c15f40a6abf3a50cc654f5",
                "md5": "30d74f6563c2ee9797c76f1be5026b04",
                "sha256": "e61288f498c0f5b0028e0072f0aec71b72ff5bea4667a1c4860086c99d231eab"
            },
            "downloads": -1,
            "filename": "socket_throttle-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "30d74f6563c2ee9797c76f1be5026b04",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 5003,
            "upload_time": "2024-06-09T03:21:30",
            "upload_time_iso_8601": "2024-06-09T03:21:30.421010Z",
            "url": "https://files.pythonhosted.org/packages/12/16/350d325897a8c46623da5fe941e7bd9ef968f6c15f40a6abf3a50cc654f5/socket_throttle-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "de761486215fb2c045e54d7ecbd8742a3cad285f90242f61bb90b0de766ed339",
                "md5": "21e2809b20133d870b0a37eeb4e0d930",
                "sha256": "0c93a50433f15bc579aea1b559dc15f0e8e30599d87d38c099efb86076383ce8"
            },
            "downloads": -1,
            "filename": "socket_throttle-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "21e2809b20133d870b0a37eeb4e0d930",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 3660,
            "upload_time": "2024-06-09T03:21:26",
            "upload_time_iso_8601": "2024-06-09T03:21:26.741660Z",
            "url": "https://files.pythonhosted.org/packages/de/76/1486215fb2c045e54d7ecbd8742a3cad285f90242f61bb90b0de766ed339/socket_throttle-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-09 03:21:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "remram44",
    "github_project": "python-socket-throttle",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "socket-throttle"
}
        
Elapsed time: 9.08290s