Slow down a Python script’s network on your Mac

Your script talks to an API that answers in 40 ms on your desk. In production it runs over a flaky connection, an overloaded upstream or a VPN on the other side of the world. Run it on 3G, with packet loss or with timeouts, without touching its code and without slowing anything else on your Mac.

One script, on 3G
lagsmith run --preset 3G -- python3 fetch.py

Why test a script on a bad network

Code that calls the network is usually written and tested on a fast, reliable connection, so the slow paths never run. A bad network is where these show up:

  • Missing timeouts. requests waits forever by default, so a script that never sets timeout= hangs instead of failing.
  • Retries that don’t retry, or retry so fast that they give up before the network comes back.
  • Timeouts that are too tight for a large upload on a slow link.
  • Half-finished work when a connection drops in the middle of a download or a batch of writes.

The usual ways, and their catches

  • Mocking in tests (responses, respx, unittest.mock) is fast and repeatable, but it fakes the library rather than the network, so real connection set-up, TLS and slow reads never happen.
  • A proxy like mitmproxy, Charles or Proxyman can throttle, but the script has to be pointed at it with HTTPS_PROXY, and HTTPS needs the proxy’s certificate in certifi, REQUESTS_CA_BUNDLE or SSL_CERT_FILE. Libraries that ignore proxy settings aren’t covered at all.
  • Toxiproxy is great between services you run yourself, but you change the address your code connects to, and it can’t sit in front of a third-party API over HTTPS without more set-up.
  • Network Link Conditioner slows down the real network, but for the whole Mac: pip, Jupyter, your editor and the AI agent running your tests crawl too. How it works.

One command, only that command

lagsmith run starts your command with its own network conditions. Lagsmith’s network extension sees which process opens each connection, so it slows down the command and the processes it starts, and nothing else.

Slow, lossy and far away
lagsmith run --down 256 --up 64 --latency 800 --loss 2 -- uv run sync.py
Only your API times out; everything else works
lagsmith run --failure timeout --hosts api.example.com -- pytest tests/test_client.py
Connections cut after 3 seconds, mid-download
lagsmith run --failure drop --after 3 -- python3 download.py
  • Any Python: Homebrew, python.org, uv, pyenv, conda and virtual environments, because it follows the process, not the interpreter.
  • Any library: requests, httpx, aiohttp, urllib, boto3 and gRPC all open ordinary connections, so there’s nothing to configure in code.
  • No proxy settings, no certificates. HTTPS stays end to end.
  • Back to normal when it ends. The rule is removed when the command exits, even after Ctrl-C, and the command’s exit code is passed through, so it fits test runs and CI.
  • See what happened: the run shows up in Lagsmith’s window, with each connection the script made.

Presets are Edge, 3G, DSL, LTE, WiFi, Very Bad Network and 100% Loss, or set --down and --up (kbps), --latency and --jitter (ms) and --loss (%). Failures are timeout, refuse (with --percent), drop (with --after) and outages (with --online and --offline). Every option.

How to slow down a Python script with Lagsmith

  1. Install Lagsmith and the command. Install Lagsmith and allow its network extension. Then turn on Allow Automation in its menu bar menu, and click Install Command Line Tool… in the Automation Guide.
  2. Put lagsmith run in front of the command. Run lagsmith run --preset 3G -- python3 your_script.py. Any command works: python3, uv run, poetry run, pytest or a shell script.
  3. Watch it cope. The script and everything it starts get the slow or broken network. Other Python processes, your terminal and the rest of your Mac stay at full speed.
  4. Done. When the command ends, its rule is removed and nothing stays throttled.

Processes that detach themselves to run in the background, like a daemon that forks away from the command, aren’t followed. For a long-running service, add its app or executable in Lagsmith’s window instead.

In pytest and CI

Wrap the whole run, or just the tests that talk to the network:

The network tests on a very bad network
lagsmith run --preset 'Very Bad Network' -- pytest -m network

Because only the command is affected, the test runner’s own downloads, your dev server and any coding agent driving the tests stay at full speed. Agents like Claude Code, Cursor and Codex can run lagsmith run themselves, or use Lagsmith’s MCP server.

Frequently asked questions

How do I simulate a slow network for a Python script on Mac?

Run it under lagsmith run, for example lagsmith run --preset 3G -- python3 fetch.py. Only that script and the processes it starts are slowed down, and the network goes back to normal when it ends.

Do I need to set HTTPS_PROXY or install a certificate?

No. Lagsmith slows down the script’s real connections with a macOS network extension, so there is no proxy to configure and nothing to add to certifi, REQUESTS_CA_BUNDLE or SSL_CERT_FILE. It works the same for requests, httpx, aiohttp, urllib and anything else that opens a socket.

Does it work with uv, pyenv, conda and virtual environments?

Yes. lagsmith run follows the process it starts and its children, not a particular Python, so it doesn’t matter which interpreter runs the script or where it’s installed.

Can I make only my API fail, or time out?

Yes. Add --hosts api.example.com to limit the rule to some hosts, and --failure timeout, refuse, drop or outages to break those connections instead of slowing them. Failure modes.

Will it slow down my AI coding agent or other Python tools?

No. Unlike Network Link Conditioner, which slows the whole Mac, only the command you run is affected. Jupyter, pip, language servers and the agent driving your tests keep their full speed.

Is it free?

lagsmith run is part of Lagsmith Pro, which the 14-day trial includes. After the trial, the free version still slows down Mac apps with the Edge preset. Pricing.

Download for Mac

Free download with a 14-day Pro trial. No account, no card. macOS 13 Ventura or later.