Skip to main content

hibira-approvals

Human approvals for AI agents over Hibira realtime channels, for Python. When a LangGraph node needs a person's OK, the call waits in a live inbox; reviewers approve, edit or reject it, and the graph resumes with their answer.

It speaks the same protocol as the npm package @hibira-io/approvals, so its React and Vue inbox components work against a Python backend unchanged.

The inbox: requests on the left, the open one on the right

Install

pip install "hibira-approvals[pusher,fastapi]"

Use with LangGraph

import pusher
from langgraph.types import Command, interrupt

from hibira_approvals import Approvals
from hibira_approvals.langgraph import approval, approval_calls, resume_value

client = pusher.Pusher(app_id=..., key=..., secret=..., host="ws.hibira.io", ssl=True)


def refund_node(state):
    answer = interrupt(approval("refund_order", {"order": state["order"]}))
    if not answer["approved"]:
        return {"log": [f"skipped: {answer['reason']}"]}
    return {"log": [refund(answer["input"])]}  # the edited input when the reviewer changed it


async def resume(request):
    config = {"configurable": {"thread_id": request["metadata"]["thread_id"]}}
    await graph.ainvoke(Command(resume=resume_value(request)), config)


approvals = Approvals(client, scope="support", resume=resume)

paused = await graph.ainvoke({"order": 1042}, config)
calls, title = approval_calls(paused)  # parallel interrupts become one request
if calls:
    await approvals.request(calls, agent="Support agent", title=title, metadata={"thread_id": "t1"})

approvals.wait(id) polls until a request is decided, for workers that keep the graph waiting in place.

Gate database writes

hibira_approvals.sql matches @hibira-io/approvals/sql: reads run at once, writes wait for a reviewer who sees the exact statement, the estimated rows and its SHA-256. classify_sql treats several statements, data-modifying CTEs, EXPLAIN ANALYZE and anything unclear as writes; run reads on a read-only connection anyway, so a misjudged statement fails instead of writing. With psycopg 3 and PostgreSQL:

import psycopg
from langgraph.types import interrupt

from hibira_approvals.langgraph import approval
from hibira_approvals.sql import assert_approved_sql, classify_sql, sql_fingerprint, sql_preview

DSN = "postgresql://..."


def read_only(sql: str) -> list:
    with psycopg.connect(DSN) as db:
        db.read_only = True
        return db.execute(sql).fetchmany(200)


def estimate_rows(sql: str) -> int:
    # A dry run: runs the statement and rolls it back. EXPLAIN avoids running it.
    with psycopg.connect(DSN) as db:
        with db.transaction(force_rollback=True):
            db.execute("SET LOCAL statement_timeout = '5s'")
            return db.execute(sql).rowcount


def sql_node(state):
    sql = state["sql"]
    if classify_sql(sql) == "read":
        return {"result": read_only(sql)}
    while True:
        fingerprint = sql_fingerprint(sql)
        preview = sql_preview(sql, rows=estimate_rows(sql), fingerprint=fingerprint)
        answer = interrupt(approval("run_sql", {"sql": sql}, title="Database change", preview=preview))
        if not answer["approved"]:
            return {"result": f"not run: {answer['reason'] or 'rejected'}"}
        edited = (answer["input"] or {}).get("sql")
        if edited and edited != sql:
            sql = edited  # preview and ask again
            continue
        assert_approved_sql(sql, fingerprint)
        with psycopg.connect(DSN) as db:
            return {"result": db.execute(sql).rowcount}

approval_calls() carries each call's preview into the request, and the React and Vue inbox show it under the statement. LangGraph replays the node on resume, so estimate_rows must not change anything (the dry run rolls back; EXPLAIN never runs the statement).

Routes for the inbox components

from fastapi import FastAPI
from hibira_approvals.fastapi import approvals_router

app = FastAPI()
app.include_router(
    approvals_router(approvals, get_user=current_user, can_review=lambda user, request: user["role"] == "admin"),
    prefix="/api/approvals",
)

get_user(request) returns {"id", "name", "avatar"} or None. The router also serves POST /auth for the Pusher channel authorization.

Requests live in memory by default; pass store= with async create, get, list and an atomic update(id, fn) over your database.

License

MIT

Metadata

Release files for hibira-approvals 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hibira-approvals 0.2.0
File Size Uploaded Provenance Actions
hibira_approvals-0.2.0.tar.gz 14.7 kB With provenance Details for hibira_approvals-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hibira-approvals 0.2.0
File Interpreter ABI Platform Actions
hibira_approvals-0.2.0-py3-none-any.whl Python 3 none any Details for hibira_approvals-0.2.0-py3-none-any.whl

Total release size: 28.9 kB

Release files / hibira_approvals-0.2.0.tar.gz

Download URL hibira_approvals-0.2.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d7bbcdd8179df22d7bb345829b4ab0eb6d96d196be8ed01596c701dbde95ad6b
BLAKE2b-256 checksum
How to use checksums
bc73f28d8e9b2dc8bfe8d07ae780aeedb396e3d4ae6b53edb6293eba75b1dd0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / hibira_approvals-0.2.0-py3-none-any.whl

Download URL hibira_approvals-0.2.0-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67d1d50f6132b01d07a6cd81c76e622f76910565d477567313d37c4457655488
BLAKE2b-256 checksum
How to use checksums
d1d263dbc0cf42dc954ea9983735e9e86687b8895366e99d87043d5de4bc4fcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for hibira-approvals 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hibira_approvals-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page