Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/remram44/python-socket-throttle
Wrapper for sockets letting you limit send/recv bandwidth
https://github.com/remram44/python-socket-throttle
bandwidth limit socket throttle
Last synced: 20 days ago
JSON representation
Wrapper for sockets letting you limit send/recv bandwidth
- Host: GitHub
- URL: https://github.com/remram44/python-socket-throttle
- Owner: remram44
- Created: 2024-06-07T03:31:01.000Z (5 months ago)
- Default Branch: trunk
- Last Pushed: 2024-06-09T03:21:07.000Z (5 months ago)
- Last Synced: 2024-10-11T07:44:21.350Z (about 1 month ago)
- Topics: bandwidth, limit, socket, throttle
- Language: Python
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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 SocketWrappersock = 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 FileWrapperwith open('data.bin', 'rb') as file:
file = FileWrapper(file, read=100_000)
file.read(...)
```