Unofficial OpenTDF SDK for Python
Project description
OpenTDF Python SDK
Unofficial OpenTDF SDK for Python
Features
- TDF Encryption/Decryption: Create and decrypt TDF files with policy-based access control
- Flexible Configuration: Support for various authentication methods and platform endpoints
- Comprehensive Testing: Full test suite with unit and integration tests
Legacy Version
A legacy version (0.2.x) of this project is available for users who need the previous implementation. For more information, see LEGACY_VERSION.md or visit the legacy branch on GitHub.
Installation
Install from PyPI:
pip install otdf-python
Quick Start
Basic Configuration
from otdf_python.sdk_builder import SDKBuilder
# Create and configure SDK using builder pattern
builder = SDKBuilder()
builder.set_platform_endpoint("https://platform.example.com")
builder.client_secret("your-client-id", "your-client-secret")
# Build the SDK instance
sdk = builder.build()
Advanced Configuration
from otdf_python.sdk_builder import SDKBuilder
# Create SDK with additional configuration options
builder = SDKBuilder()
builder.set_platform_endpoint("https://platform.example.com")
builder.set_issuer_endpoint("https://auth.example.com")
builder.client_secret("your-client-id", "your-client-secret")
# Examples, for local development
# Use HTTP instead of HTTPS
builder.use_insecure_plaintext_connection(True)
# Or
# Skip TLS verification
builder.use_insecure_skip_verify(True)
# Build the SDK instance
sdk = builder.build()
Encrypt Data
from io import BytesIO
# Create TDF configuration with attributes
config = sdk.new_tdf_config(attributes=["https://example.net/attr/attr1/value/value1"])
# Encrypt data to TDF format
input_data = b"Hello, World!"
output_stream = BytesIO()
manifest, size, _ = sdk.create_tdf(BytesIO(input_data), config, output_stream)
encrypted_data = output_stream.getvalue()
# Save encrypted data to file
with open("encrypted.tdf", "wb") as f:
f.write(encrypted_data)
Decrypt Data
# Read encrypted TDF file
with open("encrypted.tdf", "rb") as f:
encrypted_data = f.read()
# Decrypt TDF
tdf_reader = sdk.load_tdf(encrypted_data)
decrypted_data = tdf_reader.payload
# Save decrypted data
with open("decrypted.txt", "wb") as f:
f.write(decrypted_data)
Project Structure
src/otdf_python/
├── sdk.py # Main SDK interface
├── config.py # Configuration management
├── tdf.py # TDF format handling
├── nanotdf.py # NanoTDF format handling
├── crypto_utils.py # Cryptographic utilities
├── kas_client.py # Key Access Service client
└── ... # Additional modules
tests/
└── ... # Various tests
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Run tests:
uv run pytest tests/ - Commit your changes:
git commit -am 'feat: add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
Release Process
For maintainers and contributors working on releases:
- See RELEASES.md for comprehensive release documentation
- Feature branch alpha releases available for testing changes before merge
- Automated releases via Release Please on the main branch
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file otdf_python-0.4.3.tar.gz.
File metadata
- Download URL: otdf_python-0.4.3.tar.gz
- Upload date:
- Size: 384.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a0be90ebf94f7f3158f7e546cc69769c77172d13f858d8d2d396555396db851
|
|
| MD5 |
d676045b3fa34e59f2588f709b80b6e3
|
|
| BLAKE2b-256 |
87dd29f4d234ba2080cebfdfc125b73b70c616856738849db82e29e8b3176da3
|
Provenance
The following attestation bundles were made for otdf_python-0.4.3.tar.gz:
Publisher:
release-please.yaml on b-long/opentdf-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
otdf_python-0.4.3.tar.gz -
Subject digest:
1a0be90ebf94f7f3158f7e546cc69769c77172d13f858d8d2d396555396db851 - Sigstore transparency entry: 917070280
- Sigstore integration time:
-
Permalink:
b-long/opentdf-python-sdk@08d4a4ee44a9778444eb0c20cdd305fab4cac6cb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/b-long
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yaml@08d4a4ee44a9778444eb0c20cdd305fab4cac6cb -
Trigger Event:
push
-
Statement type:
File details
Details for the file otdf_python-0.4.3-py3-none-any.whl.
File metadata
- Download URL: otdf_python-0.4.3-py3-none-any.whl
- Upload date:
- Size: 225.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c483add7b7ffd653f5866a5c3aa48acd6d70512d3f9472592a859a202002a11
|
|
| MD5 |
dced9e39d96f9dfac3f3d17e9232b809
|
|
| BLAKE2b-256 |
2efda9fa73611c34b39e469bc9bf22b25f63e55966e7f14fc28ad5618df839fd
|
Provenance
The following attestation bundles were made for otdf_python-0.4.3-py3-none-any.whl:
Publisher:
release-please.yaml on b-long/opentdf-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
otdf_python-0.4.3-py3-none-any.whl -
Subject digest:
3c483add7b7ffd653f5866a5c3aa48acd6d70512d3f9472592a859a202002a11 - Sigstore transparency entry: 917070288
- Sigstore integration time:
-
Permalink:
b-long/opentdf-python-sdk@08d4a4ee44a9778444eb0c20cdd305fab4cac6cb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/b-long
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yaml@08d4a4ee44a9778444eb0c20cdd305fab4cac6cb -
Trigger Event:
push
-
Statement type: