Skip to main content

Akeyless SDK implementation for Python

Project description

The AKEYLESS SDK for Python enables Python developers to easily interface with the Akeyless encryption key protection system.

AKEYLESS innovative Key Management as-a Service solution enables Key Management, Data-at-rest Encryption, Client-side Encryption and Digital Signature where the key’s material never exists in one place throughout its lifecycle including creation, in-use and at-rest. It functions completely as a service, and there is no need for the customer to deploy secure virtual machines for storing the keys. For more information about the technology, please visit [our website](https://www.akeyless-security.com/).

Getting Started

Sign up for AKEYLESS

Before you begin, you need an AKEYLESS account. Please sign up here and receive your admin user access credentials.

Minimum requirements

  • Python 3.4+

  • cryptography >= 1.8.1

Installation

$ pip install akeyless

Documentation

You can find the AKEYLESS Python SDK full documentation at Read the Docs.

Usage

The following code sample demonstrates how to encrypt/decrypt data via the Akeyless system where the key fragments are stored in multiple locations and are never combined:

from akeyless import AkeylessClientConfig, AkeylessClient


def encrypt_decrypt_string(policy_id, api_key, key_name, plaintext):
    """Encrypts and then decrypts a string using an AES key from your Akeyless account.

    :param str policy_id: The user access policy id.
    :param str api_key: The user access key.
    :param str key_name: The name of the key to use in the encryption process
    :param str plaintext: Data to encrypt
    """

    # Akeyless playground environment.
    akeyless_server_dns = "playground-env.akeyless-security.com"

    conf = AkeylessClientConfig(akeyless_server_dns, policy_id, api_key, "http")
    client = AkeylessClient(conf)

    # Encrypt the plaintext source data
    ciphertext = client.encrypt_string(key_name, plaintext)

    # Decrypt the ciphertext
    decrypt_res = client.decrypt_string(key_name, ciphertext)

    # Verify that the decryption result is identical to the source plaintext
    assert decrypt_res == plaintext

The following code sample demonstrates how to create keys, users, roles, and associations between them

from akeyless import AkeylessClientConfig, AkeylessAdminClient, AkeylessClient
from akeyless.crypto import CryptoAlgorithm


def key_and_user_management(policy_id, api_key):
    """Create keys, users, roles, and associations between them.

    :param str policy_id: An admin user access policy id.
    :param str api_key: An admin user access key.
    """

    # Akeyless playground environment.
    akeyless_server_dns = "playground-env.akeyless-security.com"

    conf = AkeylessClientConfig(akeyless_server_dns, policy_id, api_key, "http")
    admin_client = AkeylessAdminClient(conf)

    # Create new AES-256-GCM key named "key1"
    admin_client.create_aes_key("key1", CryptoAlgorithm.AES_256_GCM, "testing", 2)

    # Get key details
    key_des = admin_client.describe_key("key1")
    print(key_des)

    # Create new user named "user1". The returned object contains the user policy id and api key.
    user1_access_api = admin_client.create_user("user1")
    print(user1_access_api)

    #  Replacing the access API key of "user1". The returned object contains the new api key.
    user1_new_api_key = admin_client.reset_user_access_key("user1")
    print(user1_new_api_key)

    # Get user details
    user_des = admin_client.get_user("user1")
    print(user_des)

    # Create new role named "role1"
    admin_client.create_role("role1")

    #  Create an association between the role "role1" and the key "key1".
    admin_client.create_role_item_assoc("role1", "key1")

    #  Create an association between the role "role1" and the user "user1".
    admin_client.create_role_user_assoc("role1", "user1")

    #  Now the user has access to the key and can encrypt/decrypt with it as follows:

    user1_config = AkeylessClientConfig(akeyless_server_dns, user1_access_api.policy_id,
                                        user1_new_api_key.get_key_seed_str(), "http")

    user1_client = AkeylessClient(user1_config)
    plaintext = "Encrypt Me!"
    ciphertext = user1_client.encrypt_string("key1", plaintext)
    decrypt_res = user1_client.decrypt_string("key1", ciphertext)

    assert decrypt_res == plaintext

    user1_client.close()

    # Delete an association between the role "role1" and the user "user1" So
    # that the user's "user1" access to the key is blocked.
    admin_client.delete_role_user_assoc("role1", "user1")

    # Delete an association between the role "role1" and the key "key1".
    admin_client.delete_role_item_assoc("role1", "key1")

    admin_client.delete_user("user1")
    admin_client.delete_role("role1")

    #  Warning! - After deleting a key, all data encrypted with that key will no longer be accessible.
    admin_client.delete_key("key1")

    admin_client.close()

You can find more examples in the examples directory

License

This SDK is distributed under the Apache License, Version 2.0 see LICENSE.txt for more information.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

akeyless-0.0.2.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

akeyless-0.0.2.1-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file akeyless-0.0.2.1.tar.gz.

File metadata

  • Download URL: akeyless-0.0.2.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for akeyless-0.0.2.1.tar.gz
Algorithm Hash digest
SHA256 6f995cb56dac2875f72702d3a945b5f9ec6e40d0989e53a1303b5f75b3a0ddd1
MD5 b31862c8f5702f951f0b74f1a744a360
BLAKE2b-256 9431212a09b706ea77d0ee476d0321d5e9cbb40f857f9211f4131a98a44f3e9b

See more details on using hashes here.

File details

Details for the file akeyless-0.0.2.1-py3-none-any.whl.

File metadata

  • Download URL: akeyless-0.0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for akeyless-0.0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 60e77aaf12c26a1c3e5a89fb9b674488c996a271739e5a8012694df074e47fb1
MD5 8b76e98c17791287f92debeafff675df
BLAKE2b-256 b047159fdb54ec78f7455f3bae8b3bde86a22f8351ace93c0d6660dd14e7ead4

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