Pinned
Durable Objects for Python.
A PinnedAPI instance for a given id will exist exactly once in your fleet. It acts as a singleton webserver.
PinnedAPI
from pinned import PinnedAPI, route
class MyAPI(PinnedAPI):
async def lifespan(self):
# setup
yield
# teardown
@route.get("/hello")
async def hello(self):
return {"hello": self.id}
- Handlers must be
async def. - Ids are client-generated; the first request activates.
@route.get/post/websocketsee the path remainder after the id.self.create_task(coro)runs background work bound to the instance: it blocks idle eviction while running, teardown waits for it,abort()cancels it.
PinnedHost
from pinned import PinnedHost, PinnedWorker
app = FastAPI()
worker = PinnedWorker(
pinboard_url="https://pinboard.internal",
advertise_url="http://10.0.3.7:8000", # must uniquely address THIS process
token="the deployment token",
)
app.include_router(worker)
app.include_router(PinnedHost(MyAPI, worker=worker, namespace="/myapi"))
PinnedHostis an APIRouter carrying/{id}that dispatches to the instance.PinnedWorkerholds the pinboard registration; several hosts share one.- A host without a worker runs in local mode: an in-memory directory, same external API —
app.include_router(PinnedHost(MyAPI), prefix="/myapi").
Pinboard
A reverse proxy that routes each request to the backend holding the instance, placing instances on registered backends as needed. Requires Redis and a deployment token shared with the backends.
Protocol
All registry calls carry Authorization: Bearer <deployment token>.
POST /registry/registerat boot —{ clientId, secret, namespaces, advertiseUrl, headroom, draining, challenge, challengeValue }. Before accepting, pinboard callsGET <advertiseUrl>/_pinned/challenge?challenge=<challenge>(authenticated withx-pinned-proxy-secret) and requires the matching{ value }. Response:{ sessionId, expiresInMs }.POST /registry/heartbeatevery 3s —{ sessionId, headroom, draining, drainDeadline?, challenge?, challengeValue? }; this worker always sends a fresh challenge pair per heartbeat, re-proving the advertise URL via the same challenge callback (the pair is optional on the wire, both fields or neither — pairless legacy workers getreregister: truein the ack while unverified). Response: ack{ expiresInMs, messages? }—messagescarries queued drain/wind_down control messages; or a 409 NACK:reregister(unknown session — abort local instances, register fresh) orsuperseded.POST /registry/release—{ clientId, namespace, id }frees a placement when an instance closes.- Operator:
POST /registry/pushqueues a drain/wind_down for a worker (delivered on its next heartbeat ack);GET /registry/workersandGET /registry/overviewintrospect;GET /healthzis unauthenticated. clientIdandsecretare minted once at process start.sessionIdis the per-registration lease token: placements belong to the session, and the backend aborts all local instances before serving under a new one.- Data-plane requests go over plain HTTP to
<advertiseUrl>/<id><rest>. The proxy setsx-pinned-proxy-secretto the worker's secret; the backend rejects a mismatch with 403. - Placement is per
(namespace, id): first claim wins (RedisSET NX) among live, undrained backends, biased toward headroom. Redis keys and body shapes are documented in pinboard's source (packages/pinned/pinboard).
Lifecycle
- Activation on first request; deactivation by idle sweep. In-flight requests and open streams block eviction.
- A host holds at most
max_instancesids at once (default 10 000); activations beyond the cap answer 503 + Retry-After while existing instances keep serving. self.abort()force-ends an instance: cancels in-flight work and tears down.- Streams are pull-based: the response generator advances only as the client reads — a slow client backpressures its own stream and nothing else, with no per-connection buffer.
- Draining workers answer new activations with 503 + Retry-After while existing requests keep serving; freed ids activate on the new deployment.
- While an instance's close and
/registry/releaseare in flight, requests for that id answer 503 + Retry-After so the proxy re-resolves the placement instead of re-activating locally.
Instance memory is ephemeral. Idle eviction, deploys, lease loss, and crashes all discard it; a re-activation starts from lifespan with nothing. Anything that must survive belongs in the app's own store, written before the response that claims it.
Leases and fencing
- Each acked heartbeat anchors the lease at send time:
self.lease.expires_at= send time +expiresInMs(10s by default, pinboard-supplied) — the moment pinboard may re-place this worker's ids, matching the worker record's Redis TTL. - When
expires_at - bufferpasses without an ack, the worker quits: aborts every local instance and stops registering before the ids can move; the host app keeps running. The buffer (default 5s) is the worker's local safety margin;self.lease.configure(...)changes it and the handlers. - A frozen process (VM pause, long GC) that wakes after its lease lapsed fails its next heartbeat (unknown session) and aborts everything before serving again.
- Registration failures retry with exponential backoff (capped at 30s); only a
supersededNACK — another session took over this worker — stops the loop for good.host.readyis False while the worker is unregistered or past its lease; wire it to the app's readiness probe (pinned_registeredis the matching gauge). - Guarantee: at most one live instance per id outside a lease-bounded failure window.
Observability
Lifecycle events (activation, eviction/abort, drain, lease health, registration) log on the stdlib pinned.* logger hierarchy with instance/namespace fields; configure it like any library logger. When prometheus_client is importable, pinned.metrics registers pinned_* counters, gauges, and a per-namespace request duration histogram on the default registry — a host app exposing /metrics picks them up automatically. Without the package they are no-ops. No Sentry or OpenTelemetry wiring; that stays in the host app.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pinned-0.8.3.tar.gz.
File metadata
- Download URL: pinned-0.8.3.tar.gz
- Upload date:
- Size: 67.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08b8f842ed6d6bd101b511798d37752c9a456d444c3d1ca0d1e5145ef721be45
|
|
| MD5 |
c14d5a2110c1609c42922bdd1a13d645
|
|
| BLAKE2b-256 |
dfc18cca923cc94a9f49ece331bafc858c4a812868da549c6d7100196d4237e3
|
Provenance
The following attestation bundles were made for pinned-0.8.3.tar.gz:
Publisher:
pypi-publish.yaml on assistant-ui/harness-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pinned-0.8.3.tar.gz -
Subject digest:
08b8f842ed6d6bd101b511798d37752c9a456d444c3d1ca0d1e5145ef721be45 - Sigstore transparency entry: 2496376295
- Sigstore integration time:
-
Permalink:
assistant-ui/harness-sdk@172dabdd7c507ef6da7c915d1748160364a420dd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/assistant-ui
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yaml@172dabdd7c507ef6da7c915d1748160364a420dd -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pinned-0.8.3-py3-none-any.whl.
File metadata
- Download URL: pinned-0.8.3-py3-none-any.whl
- Upload date:
- Size: 43.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55b24c8e0f10aeae4d45626cb7b3ca8d84fd536a7cf380ae6df01f96662602fe
|
|
| MD5 |
f40b7594af40b000b28e31959ba2a219
|
|
| BLAKE2b-256 |
570b0e8d3066d6c437c1db7d01c692611d8098df2f47fd20db954c576d924a46
|
Provenance
The following attestation bundles were made for pinned-0.8.3-py3-none-any.whl:
Publisher:
pypi-publish.yaml on assistant-ui/harness-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pinned-0.8.3-py3-none-any.whl -
Subject digest:
55b24c8e0f10aeae4d45626cb7b3ca8d84fd536a7cf380ae6df01f96662602fe - Sigstore transparency entry: 2496376852
- Sigstore integration time:
-
Permalink:
assistant-ui/harness-sdk@172dabdd7c507ef6da7c915d1748160364a420dd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/assistant-ui
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yaml@172dabdd7c507ef6da7c915d1748160364a420dd -
Trigger Event:
workflow_dispatch
-
Statement type: