Python SDK for miniKMS
Project description
miniKMS Official Python SDK
The official Python client for miniKMS, a lightweight Key Management Service designed for demos, local development, and portfolio‑grade security engineering projects.
The SDK provides a clean, mechanical API for:
- Creating and managing customer master keys (CMKs)
- Encrypting and decrypting data
- Generating and decrypting data keys (envelope encryption)
- Rotating, enabling, and disabling keys
- Retrieving key metadata
Installation
pip install minikms
Quicksart
from minikms import MiniKMS, CreateKeyRequest, EncryptRequest, DecryptRequest
kms = MiniKMS("http://localhost:8080")
# Create a key
key = kms.create_key(CreateKeyRequest(
name="example",
algorithm="AES-256-GCM",
))
# Encrypt data
enc = kms.encrypt(key.keyId, EncryptRequest(
plaintext="hello world",
additionalData="",
))
# Decrypt data
dec = kms.decrypt(key.keyId, DecryptRequest(
ciphertext=enc.ciphertext,
additionalData="",
version=enc.version,
))
print(dec.plaintext) # "hello world"
Client
from minikms import MiniKMS
kms = MiniKMS(base_url="http://localhost:8080")
Example:
kms = MiniKMS("http://localhost:8080")
Key Lifecycle
Creating Keys
from minikms import CreateKeyRequest
key = kms.create_key(CreateKeyRequest(
name="my-key",
algorithm="AES-256-GCM",
))
Enable a key
kms.enable_key(key.keyId)
Disable a key
kms.disable_key(key.keyId)
Rotate a key
resp = kms.rotate_key(key.keyId)
print(resp.version)
Each returns updated metadata.
Encrypting Data
from minikms import EncryptRequest
enc = kms.encrypt(key.keyId, EncryptRequest(
plaintext="hello world",
additionalData="optional AAD",
))
Returns ciphertext and metadata:
{
"ciphertext": str, # base64
"additionalData": str,
"version": int,
"algorithm": str,
}
Decrypting Data
from minikms import DecryptRequest
dec = kms.decrypt(key.keyId, DecryptRequest(
ciphertext=enc.ciphertext,
additionalData="optional AAD",
version=enc.version,
))
Returns:
{
"plaintext": str # utf8 decoded
}
Data Keys (Envelope Encryption)
Generate a data key
dk = kms.generate_data_key(key.keyId)
Returns:
{
"plaintextKey": str, # utf8 decoded
"encryptedKey": str, # base64
"keyVersion": int,
}
Decrypt a data key
dk2 = kms.decrypt_data_key(key.keyId, dk.encryptedKey)
print(dk2.plaintextKey)
Error Handling
All errors raised by the SDK are httpx.HTTPStatusError or connection‑level exceptions.
Example:
try:
kms.encrypt("bad-id", EncryptRequest(plaintext="test", additionalData=""))
except Exception as err:
print("Error:", err)
Type Support
This SDK ships with full Python type hints via @dataclass models:
- request/response types
- key metadata
- encryption types
- data key types
Versioning
All SDK calls target:
/v1/...
When the API introduces /v2, the SDK will expose a new client or options without breaking existing code.
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
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 minikms-0.2.0.tar.gz.
File metadata
- Download URL: minikms-0.2.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ceadf066107189e2c6c69f61fa774a220150df7519a2a3b632b40cb54ec7377
|
|
| MD5 |
231debb266f47fbc19c8589ffba2e2cf
|
|
| BLAKE2b-256 |
2ba18f0960acd2e769eb3fa6a1de2dcb9f649289f7fd14dee9a0765b91d64139
|
File details
Details for the file minikms-0.2.0-py3-none-any.whl.
File metadata
- Download URL: minikms-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f68f300a3ab7620d6248e3ad14e0fb9456beaa8450a7f72b4b6815f990d4cc1f
|
|
| MD5 |
11281657ba9421ba3cab9645447dbad0
|
|
| BLAKE2b-256 |
a4a72a3d81792ced9ea871ccc72d426b41979a6eb23ae3ed13421b775ff93378
|