Skip to main content

Wrapper for sockets letting you limit send/recv bandwidth

Project description

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:

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(...)

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

socket_throttle-0.2.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

socket_throttle-0.2.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file socket_throttle-0.2.1.tar.gz.

File metadata

  • Download URL: socket_throttle-0.2.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for socket_throttle-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0c93a50433f15bc579aea1b559dc15f0e8e30599d87d38c099efb86076383ce8
MD5 21e2809b20133d870b0a37eeb4e0d930
BLAKE2b-256 de761486215fb2c045e54d7ecbd8742a3cad285f90242f61bb90b0de766ed339

See more details on using hashes here.

File details

Details for the file socket_throttle-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for socket_throttle-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e61288f498c0f5b0028e0072f0aec71b72ff5bea4667a1c4860086c99d231eab
MD5 30d74f6563c2ee9797c76f1be5026b04
BLAKE2b-256 1216350d325897a8c46623da5fe941e7bd9ef968f6c15f40a6abf3a50cc654f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page