postkit SDK
Python client for postkit.
Installation
pip install postkit
Usage
import psycopg
from postkit.authz import AuthzClient
from postkit.authn import AuthnClient
conn = psycopg.connect("postgresql://...")
cursor = conn.cursor()
# Authorization
authz = AuthzClient(cursor, namespace="my-app")
authz.set_hierarchy("repo", "admin", "write", "read")
authz.grant("admin", resource=("repo", "api"), subject=("user", "alice"))
if authz.check(("user", "alice"), "read", ("repo", "api")):
print("Access granted")
# Authentication
authn = AuthnClient(cursor, namespace="my-app")
user_id = authn.create_user("alice@example.com", password_hash="argon2...")
session_id = authn.create_session(user_id, token_hash="sha256...")
Tenant Context and Transactions
Constructing a client calls {module}.set_tenant(namespace) immediately. The setting is transaction-scoped, so inside an open transaction the constructor taints that transaction's context for the module until commit or rollback; an unrelated client built mid-transaction can therefore change which rows a later raw SQL statement sees.
Every SDK call needs a transaction for that context. When the connection is idle, the SDK opens and commits a transaction for the call. When a non-autocommit connection already has an open transaction, the call joins it and is not durable until that transaction commits.
Queue workers pass the fence_token returned by pull() to every operation on that attempt. Database work, the pull, and ack() can share one transaction and roll back together. For external effects such as email, payments, or HTTP calls, commit the pull before processing, use a stable idempotency key, and acknowledge in a later transaction. If the pull commit outcome is unknown, do not process the returned job; reconnect and resume polling.
If a transaction containing pull() rolls back, the job is pending again and its attempt count is unchanged. Sequence values do not roll back, so discard the returned fence token and pull again; that token will never be issued to a later attempt.
In CI, call client.assert_rls_active() during setup. A suite connecting as a superuser or BYPASSRLS role (the docker default) bypasses every RLS policy and exercises none of the tenancy model.
Requirements
- PostgreSQL 14+
- The postkit SQL schema installed in your database
See the main repository for SQL installation instructions.
Release files for postkit 0.12.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| postkit-0.12.1.tar.gz | 284.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| postkit-0.12.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 347.9 kB
Release files / postkit-0.12.1.tar.gz
| Download URL | postkit-0.12.1.tar.gz |
|---|---|
| Size | 284.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
45d000cd1892d1c846cf95212472e4a9129d80f6dfa3418ae918c998f3bc8df4
|
|
BLAKE2b-256 checksum How to use checksums |
7ebe1034dc1c15d0f279abf9b3218a9aa923d242b8d4cf3a59a93c5b3125b47e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 12, 2026.
Transparency logRelease files / postkit-0.12.1-py3-none-any.whl
| Download URL | postkit-0.12.1-py3-none-any.whl |
|---|---|
| Size | 63.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da2ffae0097beffa9c7d2130b64b206ae17b3e18080861a92997d1259e2b8bec
|
|
BLAKE2b-256 checksum How to use checksums |
b0f1b96ab83c6628b3cc810a21c4206a656d3f7eaf3cbab3afbe2fa4603f5788
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 12, 2026.
Transparency log