Skip to main content

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. On autocommit connections each call runs in its own transaction and commits immediately. On non-autocommit connections each call joins the connection's open transaction: nothing is durable until you commit, and a rollback takes it all with it, including a queue claim from pull(). That is the intended model for transactional consumers; nack/fail accept the pending job a rollback leaves behind.

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.8.1

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

Source distribution (sdist)

Source distribution for postkit 0.8.1
File Size Uploaded
postkit-0.8.1.tar.gz 245.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for postkit 0.8.1
File Interpreter ABI Platform
postkit-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 302.6 kB

Release files / postkit-0.8.1.tar.gz

Download URL postkit-0.8.1.tar.gz
Size 245.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cc90c856539ef3df8870402356f260ecad9626a4898ddc7db1e184c28bb9d364
BLAKE2b-256 checksum
How to use checksums
5120f58b4f5144e684ed52a5938011a72bdcb2357cf4f1f4134b3cde51cd9c50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Jul 11, 2026.

Transparency log

Release files / postkit-0.8.1-py3-none-any.whl

Download URL postkit-0.8.1-py3-none-any.whl
Size 56.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbe2696793ef14f2d51d130334ae54185aceac43b9b8e685559fc2c7574c59bc
BLAKE2b-256 checksum
How to use checksums
4832c166131b621eb8867aeebe2778c36d1d62b847e3670e59b3f87951f7ec15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Jul 11, 2026.

Transparency log

Release history Release notifications | RSS feed

0.12.1

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

This release

0.8.1 This release

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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