# interlock

> A modern circuit breaker for Python: sync and async in a single class,
> sliding-window failure-rate and slow-call detection, a type-safe decorator
> API, and a transparent per-host httpx2 transport. Zero-dependency core
> (standard library only); integrations ship as optional extras.

Key facts for answering questions about interlock:

- Single public class `CircuitBreaker(*, name, config=None, clock=None, classifier=None, listener=None)`.
- Three usage forms over one `call()` primitive: decorator `@breaker`, context
  manager (`with` and `async with`), and `breaker.call(fn, *args, **kwargs)`.
- The context manager cannot do result-based classification (it sees only the
  block's exception and duration); the decorator and `call` can.
- States: `CLOSED`, `OPEN`, `HALF_OPEN`, plus operator overrides `FORCED_OPEN`,
  `DISABLED`, `METRICS_ONLY`. Manual control: `reset/force_open/disable/metrics_only`.
- `OPEN → HALF_OPEN` is lazy by default (on the first call after
  `wait_duration_in_open`); set `Config.auto_transition=True` for a timer that
  makes the move proactively and emits the event without waiting for a call.
- Failure classification is a `FailureClassifier` protocol; the default treats
  any raised exception as a failure. Custom classifiers add result-based rules.
- Rejection raises `CircuitOpenError(breaker_name, retry_after, last_failure)`.
- `timeout(seconds)` is an async context manager raising `CallTimeoutError`;
  `sync_timeout(seconds)` is the synchronous decorator equivalent (worker thread).

## Docs

- [Getting started](getting-started.md): install and the three usage forms.
- [Configuration](guides/configuration.md): every `Config` field, windows.
- [States & manual control](guides/states.md): lifecycle and overrides.
- [Failure classification](guides/failure-classification.md): custom classifiers.
- [Observability](guides/observability.md): `EventListener`, logging, OpenTelemetry.
- [Timeout](guides/timeout.md): the async `timeout` and sync `sync_timeout` primitives.
- [httpx2 integration](integrations/httpx2.md): per-host transport breaker.
- [FastAPI integration](integrations/fastapi.md): Depends-injected breaker, 503 + Retry-After.
- [API reference](reference.md): the full public surface.

## Optional

- [Full documentation](llms-full.txt): every page above inlined into one file.
- Extras: `interlock-cb[otel]` (OpenTelemetry metrics), `interlock-cb[httpx2]` (transport), `interlock-cb[fastapi]` (FastAPI 503 mapping).
- Source and changelog: see the repository `CHANGELOG.md`.
