Registry / auth-security / pykmip

pykmip

JSON →
library0.10.0pypypiunverified

PyKMIP (Python Key Management Interoperability Protocol) is a client library for interacting with KMIP servers, enabling operations such as creating, retrieving, deleting, and managing cryptographic keys and objects. The current version is 0.10.0, and it follows a somewhat irregular but active release cadence, typically with bug fixes and minor features between major functional updates.

pip install pykmip
INSTALL
IMPORT
SIG · PYKMIP
P
pykmip
auth-securitypythonv0.10.0
Install
6.0s avg
Import
—
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
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
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 67.1MB
glibc
py 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.")
Debug
Known issues
breakingMajor internal refactoring of the `KmipClient` and TLS context management in v0.8.0. Direct access to internal methods like `_build_tls_context` will break.
fix
Avoid accessing private (`_`) methods of `KmipClient`. Rely on the public API for configuration and operations. Use the `KmipClient` constructor for TLS setup.
affects: >=0.8.0
gotchaPyKMIP's package structure uses the `kmip.pie` namespace for its core components (client, enums, objects), not `pykmip` directly. This is a common source of `ModuleNotFoundError`.
fix
Always import from `kmip.pie.client`, `kmip.pie`, etc., instead of `pykmip.client` or `pykmip`.
affects: All versions
gotchaTLS configuration is critical and often misconfigured. Incorrect certificate paths, formats, or hostname mismatches can lead to `SSLError` or `ConnectionRefusedError`.
fix
Verify that `cert`, `key`, and `ca` paths are correct and accessible. Ensure certificates are in PEM format. Check that the server's certificate matches the hostname you are connecting to. Consult server logs for more detailed TLS errors.
affects: All versions
gotchaExplicitly setting `ssl_version` (e.g., `PROTOCOL_TLSv1_2`) can limit compatibility. While common in PyKMIP examples, Python's `ssl` module generally recommends `PROTOCOL_TLS` for negotiation.
fix
For broader compatibility, consider omitting `ssl_version` or using `ssl.PROTOCOL_TLS` (imported from `ssl` module) to allow the underlying `ssl` library to negotiate the highest secure protocol version supported by both client and server. Only specify `PROTOCOL_TLSv1_2` if strict enforcement for older servers is required.
affects: All versions
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.
Agent activity
25 hits · last 30 days
node
24
OpenAI (training)
1
Resources
pykmip — pip install pykmip · libregistry