Install & Compatibility
Where this runs
tested against v0.10.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 67.1MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 6.0s · import 0.000s · 65MB
66MB installed
● package 66MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
KmipClient
✓ from kmip.pie.client import KmipClient
✗ from kmip.pie.client import KmipClient
This quickstart demonstrates how to connect to a KMIP server using `KmipClient`, create a new symmetric key, and then destroy it. It emphasizes secure handling of sensitive information via environment variables and includes basic error handling for common connection and file issues. Ensure you have client and CA certificates (e.g., `client.pem`, `client.key`, `ca.pem`) configured for TLS.
import os
from kmip.pie.client import KmipClient
from kmip.pie import enums, objects
# Configure KMIP server details from environment variables for security
KMIP_HOST = os.environ.get("KMIP_HOST", "localhost")
KMIP_PORT = int(os.environ.get("KMIP_PORT", "5696"))
CLIENT_CERT_PATH = os.environ.get("CLIENT_CERT_PATH", "./client.pem")
CLIENT_KEY_PATH = os.environ.get("CLIENT_KEY_PATH", "./client.key")
CA_CERT_PATH = os.environ.get("CA_CERT_PATH", "./ca.pem")
try:
# Initialize the KMIP client with TLS configuration
with KmipClient(
host=KMIP_HOST,
port=KMIP_PORT,
cert=CLIENT_CERT_PATH,
key=CLIENT_KEY_PATH,
ca=CA_CERT_PATH,
ssl_version="PROTOCOL_TLSv1_2" # Explicit TLSv1.2, or let system negotiate (PROTOCOL_TLS)
) as client:
client.open()
print(f"Successfully connected to KMIP server at {KMIP_HOST}:{KMIP_PORT}")
# Example 1: Create a new symmetric key
print("\nCreating a 256-bit AES symmetric key...")
create_result = client.create(
enums.ObjectType.SYMMETRIC_KEY,
enums.CryptographicAlgorithm.AES,
256,
enums.CryptographicUsageMask.ENCRYPT
)
if create_result.result_status == enums.ResultStatus.SUCCESS:
key_uuid = create_result.uuid
print(f"Key created successfully. UUID: {key_uuid}")
# Example 2: Destroy the created key
print(f"\nDestroying key with UUID: {key_uuid}...")
destroy_result = client.destroy(key_uuid)
if destroy_result.result_status == enums.ResultStatus.SUCCESS:
print(f"Key {key_uuid} destroyed successfully.")
else:
print(f"Failed to destroy key: {destroy_result.result_reason.name}")
else:
print(f"Failed to create key: {create_result.result_reason.name} ({create_result.result_status.name})")
except ConnectionRefusedError:
print(f"Error: Connection refused. Is the KMIP server running on {KMIP_HOST}:{KMIP_PORT}?")
except FileNotFoundError as e:
print(f"Error: Certificate or key file not found: {e}. Check paths: {CLIENT_CERT_PATH}, {CLIENT_KEY_PATH}, {CA_CERT_PATH}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
finally:
# The 'with' statement handles client closing automatically
print("\nKMIP client operations completed.")
Upgrade
Version history
0.10.0latest on PyPI · released Feb 25, 2020
Audit
Dependencies
cryptographyrequiredCore dependency for cryptographic operations and TLS functionality.
pyyamloptionalUsed for parsing YAML configuration files, optional if not using config files.