Skip to main content

Toxic Proxy

Toxic Proxy is an asyncio-based TCP proxy designed for network resilience testing. This allows you to simulate network conditions like latency, bandwidth limitations, and other issues to test how your application behaves under different scenarios. Whether you're working with microservices or just need to test your network reliability, Toxic Proxy provides a flexible way to introduce network anomalies for better resilience testing.

Features

  • Simulate network latency
  • Limit bandwidth
  • Easy to integrate with Python applications
  • Uses asyncio for high performance

Installation

Install Toxic Proxy using pip.

pip install --upgrade toxic_proxy

Quick Start

Using with Cassandra

Here's an example that shows how to use Toxic Proxy with a Cassandra cluster.

import asyncio
from aiocassandra import aiosession
from cassandra.cluster import Cluster
from toxic_proxy import toxic_proxy

# Create a proxy with latency
proxy = toxic_proxy(
    destination=('<cassandra-ip>', 9042),
    latency=5,
    port=9043
)

# Connect to Cassandra through the proxy
cluster = Cluster(['0.0.0.0:9043'])
session = cluster.connect()
# ... your code here ...

Simplified Example

This example demonstrates a simple use case to limit bandwidth when connecting to google.com.

import asyncio
from toxic_proxy import toxic_proxy

# Create a proxy with bandwidth limit
proxy = toxic_proxy(
    destination=('google.com', 80),
    bandwidth_rate_kb=0.5,
    port=8888
)

loop = asyncio.get_event_loop()
server = loop.run_until_complete(proxy)
print(f'Serving on {server.sockets[0].getsockname()}')

try:
    loop.run_forever()
except KeyboardInterrupt:
    pass

# Close the server
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()

Testing

To test, you can use curl to make a request through the proxy.

curl -v 0.0.0.0:8888

Contributing

We welcome contributions! If you find a bug or have a feature request, please open an issue. If you want to contribute code, feel free to open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for toxic-proxy 0.1.0

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

Source distribution (sdist)

Source distribution for toxic-proxy 0.1.0
File Size Uploaded
toxic_proxy-0.1.0.tar.gz 2.9 kB Details

Release files / toxic_proxy-0.1.0.tar.gz

Download URL toxic_proxy-0.1.0.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2fb07bc3fa734c87441f0c4883462129395a08a576ec75cfc08d8bb0a8287e31
BLAKE2b-256 checksum
How to use checksums
6ff04c69fd0122871ca946550bfa50b6e49af010d93ee46c39247fe2540c8747
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.16 Darwin/21.6.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

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