JWT authentication and permission-based authorization for Python services
Project description
kaappu-sdk
JWT authentication and permission-based authorization for Python services. Works with Flask, FastAPI, or any Python HTTP framework.
Install
pip install kaappu-sdk
# With Flask support
pip install kaappu-sdk[flask]
# With FastAPI support
pip install kaappu-sdk[fastapi]
Quick Start
Permission Checking
from kaappu import check_permission, check_all_permissions, check_any_permission
user_perms = ["users:read", "roles:read", "gateway:*"]
check_permission(user_perms, "users:read") # True
check_permission(user_perms, "users:delete") # False
check_permission(user_perms, "gateway:view") # True (wildcard)
check_all_permissions(user_perms, ["users:read", "roles:read"]) # True
check_any_permission(user_perms, ["users:delete", "roles:read"]) # True
Wildcard support:
*-- super wildcard, matches any permissionresource:*-- matches any action on that resource
Flask Route Protection
from flask import Flask
from kaappu.decorators import require_permission
app = Flask(__name__)
@app.route("/api/users")
@require_permission("users:read")
def list_users():
return {"users": []}
Security Context
from kaappu import SecurityContext
from kaappu.context import set_context, get_context
# Set context (typically in middleware)
ctx = SecurityContext(
user_id="u_123",
account_id="acc_456",
email="user@example.com",
permissions=["users:read", "roles:read"],
)
set_context(ctx)
# Read context anywhere in the same thread
current = get_context()
print(current.email)
API Client
from kaappu import KaappuClient
client = KaappuClient(
base_url="https://your-kaappu-instance",
publishable_key="pk_live_...",
)
# Sign in
result = client.sign_in("user@example.com", "password")
access_token = result["accessToken"]
# Get current user
user = client.get_me(access_token)
# Refresh token
new_tokens = client.refresh_token(result["refreshToken"])
API
| Function / Class | Description |
|---|---|
check_permission(perms, required) |
Check a single permission with wildcard support |
check_all_permissions(perms, required) |
Check that ALL permissions are satisfied |
check_any_permission(perms, required) |
Check that ANY permission is satisfied |
SecurityContext |
Dataclass holding user identity and permissions |
set_context(ctx) / get_context() |
Thread-local security context storage |
require_permission(perm) |
Flask route decorator for permission enforcement |
KaappuClient |
API client for sign-in, sign-up, refresh, and user fetch |
Requirements
- Python 3.9+
- PyJWT 2.8+
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kaappu_sdk-0.1.0.tar.gz
(5.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kaappu_sdk-0.1.0.tar.gz.
File metadata
- Download URL: kaappu_sdk-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d835f2441a6f06549e4a2851fb8395630a8f2e76e83d3a010ebbf996deba89f
|
|
| MD5 |
cd087a77b816bfb0bae5850ee6ba86e5
|
|
| BLAKE2b-256 |
6ae5ef93c176853e8273edab78ce46b4f26425d36287b6be9876b07896c3365c
|
File details
Details for the file kaappu_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kaappu_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19f5845138c71d121f3632f6cfc93b8044c508706760cd8af70ad5abf12f4633
|
|
| MD5 |
5ce19cfb177f5ece76571846a9047fcc
|
|
| BLAKE2b-256 |
a5d780274dff909f0fa353ba384845d36c749884056e09a1f309119cda4ef51d
|