Skip to main content

In-memory key provider for development and testing

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_keyprovider_local

Swarmauri Local Key Provider

Provides a pure in-memory implementation of the KeyProviderBase suitable for local development, unit testing, and rapid prototyping without any external infrastructure.

Capabilities

  • Generate symmetric AES-256-GCM keys and several asymmetric algorithms (Ed25519, X25519, RSA-OAEP/PSS-SHA256, and ECDSA P-256-SHA256).
  • Import existing key material and rotate to new versions on demand.
  • Retrieve stored keys (optionally including the secret material) and list available versions.
  • Export public material as individual JWKs or aggregate JWKS documents.
  • Produce cryptographically secure random bytes or derive material using HKDF.
  • Destroy keys when they are no longer needed to keep local environments tidy.

Installation

Choose the tool that best matches your workflow:

# pip
pip install swarmauri_keyprovider_local

# Poetry
poetry add swarmauri_keyprovider_local

# uv
uv add swarmauri_keyprovider_local

Quickstart

The example below mirrors swarmauri_keyprovider_local.examples.basic_usage and demonstrates how to create, store, and retrieve a symmetric key.

import asyncio
from swarmauri_keyprovider_local import LocalKeyProvider
from swarmauri_core.key_providers.types import (
    ExportPolicy,
    KeyAlg,
    KeyClass,
    KeySpec,
)
from swarmauri_core.crypto.types import KeyUse


async def run_example() -> str:
    """Create and retrieve a symmetric key using LocalKeyProvider."""

    provider = LocalKeyProvider()
    spec = KeySpec(
        klass=KeyClass.symmetric,
        alg=KeyAlg.AES256_GCM,
        uses=(KeyUse.ENCRYPT,),
        export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
    )
    created = await provider.create_key(spec)
    fetched = await provider.get_key(created.kid, include_secret=True)
    assert fetched.material is not None
    return fetched.kid


if __name__ == "__main__":
    print(asyncio.run(run_example()))

Rotate, export, and derive

Once you have a provider instance, additional asynchronous helpers are available to manage keys and metadata:

# Rotate the current key in-place (keeps the same KID with a new version)
rotated = await provider.rotate_key(created.kid)

# List available versions for auditing or debugging
versions = await provider.list_versions(created.kid)

# Export public material
jwk = await provider.get_public_jwk(created.kid)
jwks = await provider.jwks()

# Destroy keys when finished
await provider.destroy_key(created.kid)

# Generate bytes or derive new material locally
random_bytes = await provider.random_bytes(32)
derived = await provider.hkdf(b"ikm", salt=b"salt", info=b"context", length=32)

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

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

swarmauri_keyprovider_local-0.2.1.dev24.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file swarmauri_keyprovider_local-0.2.1.dev24.tar.gz.

File metadata

  • Download URL: swarmauri_keyprovider_local-0.2.1.dev24.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_keyprovider_local-0.2.1.dev24.tar.gz
Algorithm Hash digest
SHA256 986f002a957f5584e5873193bc852d939708fea2547aa093db40ccbeb24b6a94
MD5 834b6df707e4cf340e051d7a99532be4
BLAKE2b-256 dfd5d61ef99ce09e8b9dc81d2bb8180422341dacf8d745d3399eb8439f742747

See more details on using hashes here.

File details

Details for the file swarmauri_keyprovider_local-0.2.1.dev24-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_keyprovider_local-0.2.1.dev24-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_keyprovider_local-0.2.1.dev24-py3-none-any.whl
Algorithm Hash digest
SHA256 c7cb0203180337ef83a402da2f099fd2303cac3bc1d455393ef4895278b9fa25
MD5 ad30c705bb5408d7258de49b7a648d31
BLAKE2b-256 4537e472a646624e7d335a4a2a05834954ebdd34dc80f4bd2f18457c4d29dda6

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