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=testing_credentials.TDF_NPE_CLIENT,
            ClientSecret=testing_credentials.TDF_NPE_CLIENT_SECRET,
            PlatformEndpoint=testing_credentials.PLATFORM_ENDPOINT,
            TokenEndpoint=testing_credentials.OIDC_AUTH_URL,
            KasUrl=testing_credentials.KAS_URL,
        )

    # 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.12-py3-none-any.whl (5.2 MB view details)

Uploaded Python 3

otdf_python-0.0.12-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.5 MB view details)

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

otdf_python-0.0.12-cp312-cp312-macosx_13_0_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.12 macOS 13.0+ x86-64

otdf_python-0.0.12-cp312-cp312-macosx_13_0_arm64.whl (5.0 MB view details)

Uploaded CPython 3.12 macOS 13.0+ ARM64

otdf_python-0.0.12-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.5 MB view details)

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

otdf_python-0.0.12-cp311-cp311-macosx_13_0_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.11 macOS 13.0+ x86-64

otdf_python-0.0.12-cp311-cp311-macosx_13_0_arm64.whl (5.0 MB view details)

Uploaded CPython 3.11 macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for otdf_python-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 60073a71e1e701d1b3d461804d774b7b3059dd0216d0e5f0d9faa9771ccdba40
MD5 eb87afa20dbe4b3fa126c940751b5bc8
BLAKE2b-256 fda6ec0910cefab46ee04f20c59fdc4892bfbda280d9ce0bf61545c27daf86fb

See more details on using hashes here.

File details

Details for the file otdf_python-0.0.12-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.12-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b5d50abdb7ca66a59571c3e9ebe808b20c4ed6a0f7dcb62c6eeba36548f95787
MD5 e12315adf81b64aa5c3ab743816f6def
BLAKE2b-256 49764c05967204083527c18f0a2688e10745e184a4877d420e2f9aec74f729bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for otdf_python-0.0.12-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 b712933667a538506fa173231dfc1b120b394d304733a75699558bf9b1e0b553
MD5 5aa59fbde2930ba030eb42b9e546d58a
BLAKE2b-256 dc5fd666780b766e1c2fd281b14db8de7449947bf47d298d345fd014f841309f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for otdf_python-0.0.12-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 85df4a85792f467620982a7a3685391afaa46c6d3081df465fc29f6eb5d161c7
MD5 78b83407328cbc00405175e423e966e5
BLAKE2b-256 0e5a3135adfd6923211e464738d42da00348e61d25dbaa05c49fd73cc892974f

See more details on using hashes here.

File details

Details for the file otdf_python-0.0.12-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.12-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b3ef57fe47639235a4cc776dfa853a6118bf679b4f65cb44827fb329b36d39d
MD5 5278fd1c8085132f6cad310998ca714e
BLAKE2b-256 bd901ed0c98e92cc9582d82763a5f03c3ce70c7e07237e57dc1e01048f3b8165

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for otdf_python-0.0.12-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 de1216894218aa1706e51b28009ee95648fd9025727c8c9e2a576b1792f915c4
MD5 b1e538b96ce692f1d08971a2c97aae28
BLAKE2b-256 143f1d4584e876b0b426141cb2ea1823051001b33e564baf28ed04d0af71e584

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for otdf_python-0.0.12-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 ee063f91a27414782f80aac7da5cdbfc72a61627634cc65d85dc0dc59bfe1ff7
MD5 fc1902e81f54606153b4c0480c0e693a
BLAKE2b-256 71de9ea0f1e975155094893d03586ebcd026226252fcf61ce40ba1568a5a44a9

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