SDK for PYRX ecosystem services to verify JWTs, consume user events, and call pyrx.auth internal API
Project description
pyrx-auth-sdk
SDK for PYRX ecosystem services to integrate with pyrx.auth centralized authentication.
Installation
pip install pyrx-auth-sdk
# With FastAPI dependency support
pip install pyrx-auth-sdk[fastapi]
Features
- JWT Verification: ES256 JWT verification with JWKS caching (no network per request)
- FastAPI Dependency:
get_current_user()extractsAuthenticatedUserfrom Bearer JWT - Event Consumer: Redis Stream consumer for user lifecycle events
- Internal API Client: Service-to-service user lookup API
Quick Start
FastAPI Integration
from pyrx_auth_sdk.config import AuthSDKConfig
from pyrx_auth_sdk.dependencies import init_auth, get_current_user
from pyrx_auth_sdk.schemas import AuthenticatedUser
# At app startup
config = AuthSDKConfig(
jwks_url="http://pyrx-auth:8001/api/v1/.well-known/jwks.json",
issuer="pyrx.auth",
audience="pyrx-mentor",
)
init_auth(config)
# In route handlers
@app.get("/protected")
async def protected(user: AuthenticatedUser = Depends(get_current_user)):
print(f"User {user.id} from tenant {user.tenant_id}")
Event Consumer
from pyrx_auth_sdk.events import UserEventConsumer
consumer = UserEventConsumer(
redis=redis_client,
group_name="my-service-group",
consumer_name="worker-1",
)
async def on_user_registered(payload):
print(f"New user: {payload['user_id']}")
consumer.on("user.registered", on_user_registered)
await consumer.run()
Internal API Client
from pyrx_auth_sdk import AuthInternalClient
from pyrx_auth_sdk.config import AuthSDKConfig
client = AuthInternalClient(AuthSDKConfig(
internal_api_url="http://pyrx-auth:8001",
internal_api_key="your-service-key",
))
user = await client.get_user(user_id)
users, not_found = await client.get_users_batch(["uuid-1", "uuid-2"])
Environment Variables
| Variable | Description |
|---|---|
PYRX_AUTH_JWKS_URL |
JWKS endpoint URL |
PYRX_AUTH_ISSUER |
JWT issuer (default: pyrx.auth) |
PYRX_AUTH_AUDIENCE |
JWT audience (your service slug) |
PYRX_AUTH_INTERNAL_API_URL |
pyrx.auth base URL |
PYRX_AUTH_INTERNAL_API_KEY |
Service-to-service API key |
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
pyrx_auth_sdk-0.1.1.tar.gz
(7.0 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 pyrx_auth_sdk-0.1.1.tar.gz.
File metadata
- Download URL: pyrx_auth_sdk-0.1.1.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfff5e25d39923b6bb4760b1b3fa3a109a1b1ea4ae92cdbcf91674931e178c01
|
|
| MD5 |
d7876781356768c583521c86b4af0213
|
|
| BLAKE2b-256 |
d106c483b1cd25c699a14b6b73c429ec81ea414675d4a76741ed19f386925acf
|
File details
Details for the file pyrx_auth_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyrx_auth_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90c4998ddf1d20adc3ebb79a878a20d9c8fb1e00a914f7682068f01944554133
|
|
| MD5 |
a7c0e11c85ccae0349c1e7f5370e4c94
|
|
| BLAKE2b-256 |
bc8fe47733ad4df93d75943be5176ec3721735443b99ec267d201223428fc9ce
|