Skip to main content

No project description provided

Project description

opentdf-python-sdk

Unofficial OpenTDF SDK for Python

Tests

This project is powered by gopy, which generates (and compiles) a CPython extension module from a go package. The gopy tool unlocks performance, flexibility, and excellent Developer Experience to Python end-users. Read more about gopy on Github.

Adding features

If you wish to expand the functionality of otdf-python:

  1. Create a fork/branch
  2. Add new capabilities (e.g. in main.go)
  3. Add a test (e.g. in otdf_python_test.go)
  4. Commit your changes, push, and open a Pull Request via the Github project: https://github.com/b-long/opentdf-python-sdk

Installation

Install from the Python Package Index (PyPI):

# Install the latest from pypi.org
pip install otdf_python

# Install a pinned version
pip install otdf-python==0.0.9

# Install a pinned version, from test.pypi.org
pip install -i https://test.pypi.org/simple/ otdf-python==0.0.9

Usage

Simple usage examples are given below. In addition, we recommend you also:

  1. See the contents of main.go on Github. ✨ Note that all Upper-case functions are available in Python.
  2. See the contents of validate_otdf_python.py on Github.

Example: Configuration

Creating a helper function may simplify the usage of otdf-python.

For example:

def get_encrypt_config(data_attributes: list | None = None):
    """
    The config object returned here can only be used for encryption.

    While 'otdf_python.gotdf_python' internally can use golang interfaces,
     to normalize config objects, that pattern causes a panic
     when used from Python.

    """
    print("Preparing 'EncryptionConfig' object")
    from otdf_python.gotdf_python import EncryptionConfig
    from otdf_python.go import Slice_string

    if isinstance(data_attributes, list):
        # Create config using the attributes from the caller
        da = Slice_string(data_attributes)
        config: EncryptionConfig = EncryptionConfig(
            ClientId="opentdf-sdk",
            ClientSecret="secret",
            PlatformEndpoint=platformEndpoint,
            TokenEndpoint="http://localhost:8888/auth/realms/opentdf/protocol/openid-connect/token",
            KasUrl=f"http://{platformEndpoint}/kas",
            # FIXME: Be careful with binding the 'DataAttributes' field on this struct.
            #
            # In golang, this is initialized as []string , but passing
            # DataAttributes=None, or DataAttributes=[] from Python will fail.
            DataAttributes=da,
        )
    else:
        # Create config without attributes
        config: EncryptionConfig = EncryptionConfig(
            ClientId="opentdf-sdk",
            ClientSecret="secret",
            PlatformEndpoint=platformEndpoint,
            TokenEndpoint="http://localhost:8888/auth/realms/opentdf/protocol/openid-connect/token",
            KasUrl=f"http://{platformEndpoint}/kas",
        )

    # NOTE: Structs from golang can be printed, like below
    # print(config)
    print("Returning 'EncryptionConfig'")

    return config

Example: Encrypt a string

from otdf_python.gotdf_python import EncryptString

# Depends on the 'get_encrypt_config()' given
# in the README above
config: EncryptionConfig = get_encrypt_config()

tdf_manifest_json = EncryptString(inputText="Hello from Python", config=config)

Example: Encrypt a file

from otdf_python.gotdf_python import EncryptFile
from otdf_python.go import Slice_string

# Depends on the 'get_encrypt_config()' given
# in the README above
config: EncryptionConfig = get_encrypt_config()

with tempfile.TemporaryDirectory() as tmpDir:
    print("Created temporary directory", tmpDir)

    da = Slice_string(["https://example.com/attr/attr1/value/value1", "https://example.com/attr/attr1/value/value2"])

    encrypted_file = Path(tmpDir) / "some-file.tdf"

    if encrypted_file.exists():
        encrypted_file.unlink()

    if encrypted_file.exists():
        raise ValueError(
            "The output path should not exist before calling 'EncryptFile()'."
        )

    outputFilePath = EncryptFile(
        inputFilePath=str(SOME_PLAINTEXT_FILE),
        outputFilePath=str(encrypted_file),
        config=config,
    )

    print(f"The output file was written to destination path: {outputFilePath}")

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

otdf_python-0.1.10-py3-none-any.whl (5.4 MB view details)

Uploaded Python 3

otdf_python-0.1.10-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

otdf_python-0.1.10-cp312-cp312-macosx_13_0_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.12 macOS 13.0+ x86-64

otdf_python-0.1.10-cp312-cp312-macosx_13_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.12 macOS 13.0+ ARM64

otdf_python-0.1.10-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

otdf_python-0.1.10-cp311-cp311-macosx_13_0_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.11 macOS 13.0+ x86-64

otdf_python-0.1.10-cp311-cp311-macosx_13_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.11 macOS 13.0+ ARM64

File details

Details for the file otdf_python-0.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for otdf_python-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 12414b3243a25902ffbbcc29c91c785905c6b9c97f837c70c442f4d271a87f25
MD5 e41e86ff160d86f17a755b85e20b5fbe
BLAKE2b-256 0ff859e85382fff5efe3806a0d00969ea547df9ea0ff61882ef407fd161ff49b

See more details on using hashes here.

File details

Details for the file otdf_python-0.1.10-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for otdf_python-0.1.10-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34c98878b06826077fc4ca918a50cb5d81d7b8b07ad7e86901ae3a2a99d888ab
MD5 f331ddc661a610c51a412710f706a1b3
BLAKE2b-256 8c5411716a4022d2d2c0adbe46c4ec8907a4ad27f910db8fa0df75423732fdac

See more details on using hashes here.

File details

Details for the file otdf_python-0.1.10-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for otdf_python-0.1.10-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 732488b029fb9eb96786eee95d935473b774220bab37b39674e16848717bf674
MD5 bbbba125b111f0312efa9cebcac5fb56
BLAKE2b-256 8b63ecd3b54edcce3b4181c7c8cc2cc2ca2ff02c6d477c47cb3e9fdc211cefdf

See more details on using hashes here.

File details

Details for the file otdf_python-0.1.10-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for otdf_python-0.1.10-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 9cb73c7a6b8ccc5a207dd0810c3aa9a10d852826320b11d5e3cf77ba6011a4f6
MD5 7a15405c707a98b06f934be1cfa3113b
BLAKE2b-256 696401d83c3de1bd67cba0c8afeb0ebb795675cc1048088395c4d2e393a315b6

See more details on using hashes here.

File details

Details for the file otdf_python-0.1.10-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for otdf_python-0.1.10-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4440672c628e023a20e2d13d92f32c72cbdf112e1b033ca3098e5b587df1b26
MD5 beb9be0b62f2487ada4a978b1b0228e8
BLAKE2b-256 b6639f7cb30947bbd71f1b00398ade92ec6389bcf13f4f0e4ef21dd2ebfeb135

See more details on using hashes here.

File details

Details for the file otdf_python-0.1.10-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for otdf_python-0.1.10-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 01d446cb025c1a3edbf888ac3e0d5d71a77bed30676b8c8fd5566b558854c970
MD5 5947a2411dfb18354bd501ccadb2c1dd
BLAKE2b-256 357c0566be6d5de75c272afd7d1bc6adb2bbeebd8e318cdf20b67c173082b4ab

See more details on using hashes here.

File details

Details for the file otdf_python-0.1.10-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for otdf_python-0.1.10-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 27356da3c9af79df5fb14d5128b559b06b8d5328809bf6a71273254b212ccdc4
MD5 ad116988f8b69b0b422d871ce2402679
BLAKE2b-256 62f710f24ca2227dd71bb42dec44ba4ab7b567a226046e7dadad824de3a5da4b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page