No project description provided
Project description
opentdf-python-sdk
Unofficial OpenTDF SDK for Python
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
:
- Create a fork/branch
- Add new capabilities (e.g. in
main.go
) - Add a test (e.g. in
otdf_python_test.go
) - 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:
- See the contents of
main.go
on Github. ✨ Note that all Upper-case functions are available in Python. - 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
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 Distributions
Built Distributions
File details
Details for the file otdf_python-0.0.13-py3-none-any.whl
.
File metadata
- Download URL: otdf_python-0.0.13-py3-none-any.whl
- Upload date:
- Size: 5.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 184996f5edb1cfc71fd5a08c12e039fdb428589162c30a814a780a972fdbac8c |
|
MD5 | 523d7f19120c3117c55fa4060a7ed6dc |
|
BLAKE2b-256 | 34b253ebc5287ca874134746503338c5cf4cb848826259e23a79c893920d7406 |
File details
Details for the file otdf_python-0.0.13-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: otdf_python-0.0.13-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 9.9 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dd1d9474677902ae5c561fc7cb32f9a08bf3ef43c606354acaf21a51deb1814 |
|
MD5 | db03ec8e2680af563187125e6ddc0a0c |
|
BLAKE2b-256 | 60bacb9bddea33432bf6f976bebf273a79277548c4c55e64328d7efeabfd1fc7 |
File details
Details for the file otdf_python-0.0.13-cp312-cp312-macosx_13_0_x86_64.whl
.
File metadata
- Download URL: otdf_python-0.0.13-cp312-cp312-macosx_13_0_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.12, macOS 13.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5cd9d6e1507a9f2407346c0d1f1e3d3580a0c9f7e1608839a7e45ea4582bb7a |
|
MD5 | 80e5440b77a0a7152ded78a295a2030d |
|
BLAKE2b-256 | 825bdd8018e46687f00af7520c9e470c7546445873a471a84ab95f972b77d89e |
File details
Details for the file otdf_python-0.0.13-cp312-cp312-macosx_13_0_arm64.whl
.
File metadata
- Download URL: otdf_python-0.0.13-cp312-cp312-macosx_13_0_arm64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.12, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 824430a7609bddd12513119c6e305e1a0216481c5f4e34f14f397d5c77fd58ca |
|
MD5 | db0dcb5d6305da586d03c5dace7dde77 |
|
BLAKE2b-256 | 2aa3669cea36cbc380a49a570ebd1dccd0a0c48d4001b014b001eb3a8bd897ed |
File details
Details for the file otdf_python-0.0.13-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: otdf_python-0.0.13-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 9.9 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50c8796242fe36d0f504432b958b4afb81ec031b009eb2b6d98190dd3e5bdd1b |
|
MD5 | 165e72bdedac4206e9c2494179aaaecd |
|
BLAKE2b-256 | 8cb938b250a1d17c8bc1e5d0be78fe6f0a4cc60a2cfb45c92f1270bcab499b92 |
File details
Details for the file otdf_python-0.0.13-cp311-cp311-macosx_13_0_x86_64.whl
.
File metadata
- Download URL: otdf_python-0.0.13-cp311-cp311-macosx_13_0_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.11, macOS 13.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 703d37442857f2393272c6b6889e45bf30832868579c4f5ef36c3bcbb42fb78b |
|
MD5 | ca0506882ef07fca914f9a95e48c1987 |
|
BLAKE2b-256 | 8e527b4ae708cdc9f6d4f1bafd2efc3641bd70070352b816798adc340d68935e |
File details
Details for the file otdf_python-0.0.13-cp311-cp311-macosx_13_0_arm64.whl
.
File metadata
- Download URL: otdf_python-0.0.13-cp311-cp311-macosx_13_0_arm64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.11, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10f863212199dd6fddb0270113c5962253364b07509a2bbec79add193f94bb8a |
|
MD5 | 2b2d12c1c4ad517bbdacab15c481b02f |
|
BLAKE2b-256 | f5d397353539200b059eafac153cfd84541becd32ec5888c74ae1c41bdd1e57f |