Quickstart: Python
pylogu sends asks and waits for the decision, reports events and metrics. Sync (Logu) and
asyncio (AsyncLogu), with the same methods.
1. Install and connect#
pip install pylogu # or: uv add pylogu
npx -y @logu/cli login # connects this computer: approve the code in the app
pylogu reads the API key logu login saved. In CI and on servers, create an agent in the app
(Agents) and set LOGU_API_KEY=lg_… instead.
2. Ask and wait#
from pylogu import Logu, approved
logu = Logu() # LOGU_API_KEY, else the API key `logu login` saved
ask = logu.ask(
"my-app",
"Run the database migration in production?",
body="Adds the refunded_at column. No downtime expected.",
timeout_seconds=2 * 60 * 60,
default_option="decline",
)
if approved(ask):
migrate()
ask() blocks until the human decides, the ask expires or it's withdrawn. approved(ask) is true
only when a person (or an Owner's rule) decided with approve; a default option applied on timeout
is never an approval, and default_option can't be an approving one (use "decline").
3. Guard a function#
from pylogu import Logu, NotApproved
logu = Logu()
@logu.requires_approval("billing", title=lambda table: f"Drop table {table}?")
def drop_table(table: str) -> None: ...
drop_table("invoices_old") # raises NotApproved unless you approve
4. Events and metrics#
logu.event("my-app", "Nightly backup finished", icon="✅")
logu.metric("shop", "orders", 42)
Next#
- Images on asks (
upload_attachment): Attachments. - Verifying webhook deliveries in Python: Webhooks.
- Every option: pylogu on PyPI.