Skip to main content

Anticipatory rate-limit orchestration engine for multi-provider systems

Project description

grate-limiter (Python)

Anticipatory rate-limit orchestration engine for multi-provider systems.

Predict limits before providers enforce them.

This is the Python port of grate-limiter. For detailed documentation, see the main repository.

Installation

pip install grate-limiter

Quick Start

from grate_limiter import *

# Create the engine
engine = GrateLimiter(EngineConfig())

# Register providers with their quotas
engine.upsert_provider(ProviderConfig(
    name="openai",
    quotas=[QuotaConfig(dimension=Dimension.REQUESTS, limit=5000, window=Window.MINUTE)],
    priority=10,
    cooldown_seconds=30,
))

engine.upsert_provider(ProviderConfig(
    name="anthropic",
    quotas=[QuotaConfig(dimension=Dimension.REQUESTS, limit=3000, window=Window.MINUTE)],
    priority=8,
    cooldown_seconds=30,
))

# Register a capability
engine.upsert_capability(CapabilityConfig(
    name="chat-completion",
    providers=[
        CapabilityProvider(provider="openai", priority=10),
        CapabilityProvider(provider="anthropic", priority=8),
    ],
))

# Select the best provider
decision = engine.select("chat-completion")
print(f"Use: {decision.provider} (score: {decision.score:.2f})")

# Report what happened
engine.observe(Observation(
    provider="openai",
    capability="chat-completion",
    usage=Usage(requests=1, tokens=1200),
    outcome=Outcome(status=StatusClass.SUCCESS, latency_ms=830),
))

Deterministic Testing

from grate_limiter import GrateLimiter, EngineConfig, MockClock

clock = MockClock()
config = EngineConfig().with_clock(clock)
engine = GrateLimiter(config)

# Time only advances when you say so
clock.advance_ms(5000)
clock.advance_secs(60)

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grate_limiter-0.1.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grate_limiter-0.1.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file grate_limiter-0.1.0.tar.gz.

File metadata

  • Download URL: grate_limiter-0.1.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for grate_limiter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 92f944e0036d6a53055ffa1db55ff069748ca95035e4a69af3bc01be4c09b63b
MD5 d0c93c8ca6b3e696dcfb59c4453a670a
BLAKE2b-256 114c5e57a73be7a7a0c8187af64f0ab26940911a102eee4df1d14227e15251e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for grate_limiter-0.1.0.tar.gz:

Publisher: release.yml on dev-kasibhatla/grate-limiter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grate_limiter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: grate_limiter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for grate_limiter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 964fd9aa6db8ead00d4934be4927b1bf73e014721dee09a2b1c88143db97009d
MD5 7382ff2a0cbcf6995350b45aaf0c0776
BLAKE2b-256 7f8e72c60d490fb9edbaf38a05786603fe973c7a6fdcd59b435b1f8c48d59ad8

See more details on using hashes here.

Provenance

The following attestation bundles were made for grate_limiter-0.1.0-py3-none-any.whl:

Publisher: release.yml on dev-kasibhatla/grate-limiter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page