Skip to main content

Reusable backend components for JWT authentication and S3-compatible storage.

Project description

rgc-backend-kit

rgc-backend-kit is a reusable Python backend component library extracted from ai_recipes.

It currently provides:

  • rgc_backend_kit.security: framework-neutral JWT token lifecycle management.
  • rgc_backend_kit.storage: S3-compatible object storage clients, capability presets, and profile routing.

The package is designed for business services that need shared infrastructure without importing another application's settings, ORM models, response classes, or global factories.

Host applications still own business logic such as login, password verification, permissions, file records, upload policies, and response schemas. See Integration Boundary.

Requirements

  • Python >=3.10
  • pyjwt for JWT support
  • Optional redis for Redis-backed token storage
  • Optional fastapi for FastAPI dependency adapters
  • Optional boto3 / botocore for S3-compatible storage

Install

From PyPI:

pip install rgc-backend-kit

With optional features:

pip install "rgc-backend-kit[fastapi,redis,storage]"

Local development:

uv sync --extra dev

JWT Quick Start

from datetime import timedelta

from rgc_backend_kit.security import JWTConfig, JWTManager, RedisTokenStore

manager = JWTManager(
    config=JWTConfig(
        secret="replace-with-a-long-random-secret",
        issuer="my-service",
        audience="my-client",
        access_token_ttl=timedelta(minutes=60),
        refresh_token_ttl=timedelta(days=7),
    ),
    token_store=RedisTokenStore(redis),
)

token_pair = await manager.issue_pair(subject="user-id", claims={"role": "admin"})
payload = await manager.decode_access_token(token_pair.access_token)
rotated = await manager.rotate_refresh_token(token_pair.refresh_token)
await manager.revoke_access_token(rotated.access_token)

Storage Quick Start

from rgc_backend_kit.storage import (
    MINIO_CAPABILITIES,
    S3StorageConfig,
    StorageFactory,
    StorageProfileConfig,
)

factory = StorageFactory.from_configs(
    client_configs={
        "minio_public": S3StorageConfig(
            access_key="minio",
            secret_key="minio123",
            endpoint="127.0.0.1:9000",
            public_endpoint="img.example.com",
            bucket_name="public-assets",
            secure=False,
            secure_public=True,
            capabilities=MINIO_CAPABILITIES,
        )
    },
    profiles={
        "avatars": StorageProfileConfig(
            client="minio_public",
            base_path="avatars",
            public=True,
        )
    },
)

avatars = factory.get_profiled_storage("avatars")
url = avatars.build_public_url("demo.png")

Tests

Default tests do not require external services:

uv run --extra dev pytest -q

Redis integration tests require a real Redis instance:

REDIS_URL=redis://:password@127.0.0.1:6379/0 uv run --extra dev pytest -q -m integration

Build package artifacts:

uv build

Validate the built wheel in an isolated environment before publishing:

rm -rf /tmp/rgc-backend-kit-package-full-test
mkdir -p /tmp/rgc-backend-kit-package-full-test
cd /tmp/rgc-backend-kit-package-full-test
uv venv
uv pip install '/home/rgc318/Projects/rgc-backend-kit/dist/rgc_backend_kit-0.1.0-py3-none-any.whl[fastapi,redis,storage]' httpx

Documentation

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

rgc_backend_kit-0.1.0.tar.gz (56.6 kB view details)

Uploaded Source

Built Distribution

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

rgc_backend_kit-0.1.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rgc_backend_kit-0.1.0.tar.gz
  • Upload date:
  • Size: 56.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rgc_backend_kit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6dd95f732ce26d02742ff730435d29dc9db5fe2d6cd7bf5f04fa2f824f0fd264
MD5 666334ed636ba6b7da5becaf21be242c
BLAKE2b-256 9f48b8f47eb524a198d88aaeba46f3c78208a6cb315fd94138f90803946c96c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rgc_backend_kit-0.1.0.tar.gz:

Publisher: publish.yml on rgc318/rgc-backend-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: rgc_backend_kit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rgc_backend_kit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99b4db740877daf1605bfca492481bad1287559d647e70271759b91fcd52898c
MD5 38c9f0bf740134ad1b23f037f44033d9
BLAKE2b-256 cf5efc0fb044e13d3ce6f03488ee478fae0c8f696cb19e0d1a0dd3f486f3bcb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for rgc_backend_kit-0.1.0-py3-none-any.whl:

Publisher: publish.yml on rgc318/rgc-backend-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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