Unofficial OpenTDF SDK for Python
- 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
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.
Install from PyPI:
pip install otdf-pythonfromotdf_python.sdk_builderimportSDKBuilder# Create and configure SDK using builder patternbuilder=SDKBuilder()
builder.set_platform_endpoint("https://platform.example.com")
builder.client_secret("your-client-id", "your-client-secret")
# Build the SDK instancesdk=builder.build()fromotdf_python.sdk_builderimportSDKBuilder# Create SDK with additional configuration optionsbuilder=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 HTTPSbuilder.use_insecure_plaintext_connection(True)
# Or# Skip TLS verificationbuilder.use_insecure_skip_verify(True)
# Build the SDK instancesdk=builder.build()fromioimportBytesIO# Create TDF configuration with attributesconfig=sdk.new_tdf_config(attributes=["https://example.net/attr/attr1/value/value1"])
# Encrypt data to TDF formatinput_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 filewithopen("encrypted.tdf", "wb") asf:
f.write(encrypted_data)# Read encrypted TDF filewithopen("encrypted.tdf", "rb") asf:
encrypted_data=f.read()
# Decrypt TDFtdf_reader=sdk.load_tdf(encrypted_data)
decrypted_data=tdf_reader.payload# Save decrypted datawithopen("decrypted.txt", "wb") asf:
f.write(decrypted_data)packages/otdf-python/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
- 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
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
This project is licensed under the MIT License - see the LICENSE file for details.