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
Release history Release notifications | RSS feed
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.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for socket_throttle-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5831d89fd5bdaa5a79ccfe07756238398f27746dc9be6e3ceb78d3941c0b17c9 |
|
MD5 | ecdfc357b4544b524f5187cbdae1c2cd |
|
BLAKE2b-256 | ba86681301f4c49d42d519a7742a38d52eafc921fa937c3895f9c1ce0c8e72ba |