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.0.15-py3-none-any.whl (5.4 MB view details)

Uploaded Python 3

otdf_python-0.0.15-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.9 MB view details)

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

otdf_python-0.0.15-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.0.15-cp312-cp312-macosx_13_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.12 macOS 13.0+ ARM64

otdf_python-0.0.15-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.9 MB view details)

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

otdf_python-0.0.15-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.0.15-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.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for otdf_python-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 51a8f465d8d120a516e9f24cd0a6dbd144a831811c757e1ecbed692818d36960
MD5 21ebbe332b1e4b3cd0d549d1e7bfd986
BLAKE2b-256 d631fde0bc1bd7e35e0db813c809e3a193e17084656f5625e32d4c1700184575

See more details on using hashes here.

File details

Details for the file otdf_python-0.0.15-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.0.15-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b5d016ce89f4066a3a7ae5215857ba0839f123ae9e2766ac02c943870856e92
MD5 1f6f6fd6a41a0ab917ab736e6849f11d
BLAKE2b-256 4418ea79fc38bf224cf3f66f8c30f868593b5506b6bde093a4847a8b8905f137

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for otdf_python-0.0.15-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 7e140b27564bbf39a35c37553579e44ef5e5ebf07eb803b2289ba137be07a85c
MD5 ebad9a14e18f8b6f9b9cb85a6fbbe56e
BLAKE2b-256 20f126bc72376250fa02e0a247b9c3d5e0b9dfb959891205bc822a467cf5e678

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for otdf_python-0.0.15-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 0d28825c1713042b64129b776ab0b01bb4c13d5c2918a8ca4efdc255249ed61d
MD5 4d01c350f45c5b708ebeef0ac4b41803
BLAKE2b-256 86cf6d3be74da53648cf21ad330ebd76a71a7213b08bab2d62993de77ef484bd

See more details on using hashes here.

File details

Details for the file otdf_python-0.0.15-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.0.15-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94cb35f950cf9787663d0d5ee96c07aded253ee4b3a241d54ba0a0f3913ff5ee
MD5 14c30b0a3dd3acf65cb09680d95fdaf5
BLAKE2b-256 2ed0bbe9593ff88f82486ccd47840a622abf6df11668ee4680ab3b476949d037

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for otdf_python-0.0.15-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 c5a46711aa71af9025ba1ea6f2553519280af2c84f08072466db0f3ef02d3c1e
MD5 58ffb16d1f9175d213ebbde11315af90
BLAKE2b-256 4d1a8aa57a663482595518b3b03e76a6498458a3ab60a3c704828afacce29d7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for otdf_python-0.0.15-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 3cae1eb726a4a9bdbfb543bc845c794e45871608a26a6b2508e749ed7f029e2a
MD5 5013a54a0400aca3614aa9ea7e863253
BLAKE2b-256 0519986d9a14a5cf16bd0319c8f7e7e8a742edf97523ce25a3c6b2658a4e3699

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