Skip to main content

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

Release files for socket-throttle 0.2.1

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

Source distribution (sdist)

Source distribution for socket-throttle 0.2.1
File Size Uploaded
socket_throttle-0.2.1.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for socket-throttle 0.2.1
File Interpreter ABI Platform
socket_throttle-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / socket_throttle-0.2.1.tar.gz

Download URL socket_throttle-0.2.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0c93a50433f15bc579aea1b559dc15f0e8e30599d87d38c099efb86076383ce8
BLAKE2b-256 checksum
How to use checksums
de761486215fb2c045e54d7ecbd8742a3cad285f90242f61bb90b0de766ed339
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / socket_throttle-0.2.1-py3-none-any.whl

Download URL socket_throttle-0.2.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e61288f498c0f5b0028e0072f0aec71b72ff5bea4667a1c4860086c99d231eab
BLAKE2b-256 checksum
How to use checksums
1216350d325897a8c46623da5fe941e7bd9ef968f6c15f40a6abf3a50cc654f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

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