Skip to content

Playground

The simulator below is not a mock of smartratelimit. It runs the library's own simulation modules — copied verbatim from the source this site was built from — inside a Python runtime in your browser, driving the same TokenBucket that paces your production requests.

Nothing is sent anywhere. Everything runs on your machine.

??? note "Why it loads source files rather than installing the package" Two reasons, both worth knowing if you ever try this yourself.

`smartratelimit/__init__.py` eagerly imports the HTTP and storage stack, and
`storage.py` imports `sqlite3` — which Pyodide unvendors from the standard
library. Importing the installed package in a browser fails outright.

And PyPI serves the last *release*, which is not necessarily the code these
docs describe. A page demonstrating the docs should run the source the docs
were built from.

So the three modules the simulator needs — `_time`, `models`, `simulate` —
are published alongside this page and written straight into Pyodide's
filesystem. They import nothing but the standard library, so nothing has to
resolve. They are byte-identical to the package, and a test fails if they
ever drift. Only the package `__init__` is stubbed, because that is the file
that drags in sqlite3.
Starting Python in your browser…

Things worth trying

Drag Average tokens per request up. Watch the tokens ceiling collapse while the request ceiling sits untouched. At 2,000 tokens against 100,000 a minute you get 50 requests a minute — a tenth of a 500 RPM limit.

Then drag Concurrent workers. Nothing happens. Concurrency cannot buy tokens, and no amount of parallelism moves a budget-bound workload.

Now raise API keys. That does move it, because each key carries its own budgets — and it beats a straight multiple, since each also brings a full bucket to open with.

Set Response latency to something realistic. A concurrency row appears. If it comes out below every budget, your worker count is the constraint and raising a rate limit would change nothing.

The point

Every number here comes from smartratelimit.simulate, which drives the same TokenBucket the limiter uses against live traffic. If this page and the library ever disagreed, one of them would be wrong — and there is only one implementation for them to disagree about. The JavaScript here formats a result; it never computes one.

For scripting, scenarios beyond requests and tokens, and what this deliberately will not tell you about 429s, see Simulator.