finic-kairos
Python client for Kairos. Track financial events, then ask for a decision at the moment of action.
- Python 3.9 or later
- No dependencies: the standard library only
- Typed (
py.typed), and safe to use from several threads
This page is the short version. The full Python SDK guide covers every call, and the TypeScript guide explains actions, labels, links and how to get good decisions in depth.
Install
Install it from PyPI:
pip install finic-kairos
Use
import os
from kairos import Kairos
kairos = Kairos(os.environ["KAIROS_API_KEY"])
# Once, at startup: say what you want decided, in plain language.
kairos.define_action("bank_transfer", {
"subject": "user",
"hold": "Should the pending bank transfer be held because the account shows signs of fraud or account takeover?",
"reasons": {
"new_device": "The current session uses a device that the account did not use before",
"new_beneficiary": "The transfer goes to a beneficiary that was added recently",
},
})
# Anywhere: record what happens. Any event type, any properties.
# A key that ends in _id names an entity: user_id is the entity "user".
kairos.track("transaction", {
"user_id": "user_123",
"account_id": "account_456",
"recipient_id": "recipient_789",
"amount": 9500,
"currency": "USD",
})
# At the moment of action: ask.
decision = kairos.decide(
"bank_transfer",
{"user_id": "user_123", "recipient_id": "recipient_789", "amount": 9500},
fallback="review",
)
if decision.decision == "approve":
... # release the transfer
track returns at once and sends in the background. decide waits for the answer, sends what is queued first, and returns the fallback when Kairos cannot answer.
In a web framework
KairosASGI takes the user and the session from the request, for FastAPI, Starlette and any other ASGI framework. It can also send an event for a route that has no track call.
from kairos.middleware import KairosASGI
app.add_middleware(
KairosASGI,
client=kairos,
entities=lambda scope: {"user": scope["state"].get("user_id")},
session=lambda scope: scope["state"].get("session_id"),
routes={"PUT /account/password": "password_changed"},
)
kairos.track("transaction", {"amount": 900}) # the user and the session come from the request
See In a web framework.
With client_settings=True, the middleware also runs the routes set in Settings › Integrations › Client settings: it tracks them, or asks for a decision before your app runs. See Routes from the console.
Import history from files
python -m kairos import events transactions.csv --type transaction --ts created_at --id txn_id --dry-run
See Import your history.
Test
python3 -m unittest discover -s packages/sdk-python/tests # no network
python3 packages/sdk-python/examples/live_check.py # against a running server
Metadata
Release files for finic-kairos 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| finic_kairos-0.2.0.tar.gz | 62.3 kB | Without provenance | Details for finic_kairos-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| finic_kairos-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for finic_kairos-0.2.0-py3-none-any.whl |
Total release size: 105.9 kB
Release files / finic_kairos-0.2.0.tar.gz
| Download URL | finic_kairos-0.2.0.tar.gz |
|---|---|
| Size | 62.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a8ca45793598e76cb428e2274f0bc468c0e5c3db4ad71f9f1b8b0cc1a6b299a
|
|
BLAKE2b-256 checksum How to use checksums |
36a27b8bdf6fdc42285303b588ed78b47554c21eeb362f385ef9e51e6ae2cc5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.16
|
Release files / finic_kairos-0.2.0-py3-none-any.whl
| Download URL | finic_kairos-0.2.0-py3-none-any.whl |
|---|---|
| Size | 43.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2ed82a6a1a2290792a790dae10f9a2b5be02420c94c58c10f1585737e43d638
|
|
BLAKE2b-256 checksum How to use checksums |
2b0d506ee445488542192a175df7a64aded5367aebaf10b7c81c50f8bdf807b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.16
|
Security for finic-kairos 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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.