Skip to main content

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() extracts AuthenticatedUser from 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


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.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrx_auth_sdk-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file pyrx_auth_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: pyrx_auth_sdk-0.1.0.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

Hashes for pyrx_auth_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e86d444ce02b133f63d141bbaa2d943dcf3fed9ef9f19a15e85831fae40276fe
MD5 4d50974ab6c6b2d8d9b9044c7d7b3f53
BLAKE2b-256 b6d86175e4adaa1a9524ff7af11f6df18578a25a191e192ee61aa4b7bf014b1d

See more details on using hashes here.

File details

Details for the file pyrx_auth_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyrx_auth_sdk-0.1.0-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

Hashes for pyrx_auth_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa26f3b5ce603b41ed58f6727d0bd0f3710aef86a0f9ccc4d3aacea03e9ffcca
MD5 dcc4fb56c4aaaa8d80b0d304c44a3de1
BLAKE2b-256 66cb006ffb49d8cffe41f582ee365d8b830a400d212e11f7c81b374c147f6e7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page