Skip to main content

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)

TDF container format

TDF archives are written with the spec-mandated manifest.json zip entry (per opentdf/spec) instead of the legacy 0.manifest.json. Readers accept both names, so archives written by older versions of this SDK remain readable forever. The payload zip entry is resolved from manifest.payload.url rather than assumed. schemaVersion is unchanged (still 4.3.0); tdf_spec_version is now read at either its legacy or spec-conformant placement, but never written.

Interoperability note: archives written by this SDK can only be opened by readers that support the manifest.json entry. Older releases of otdfctl and the upstream OpenTDF SDKs only look for 0.manifest.json and cannot open them. If you exchange TDFs with those tools, make sure you are on a release that reads manifest.json.

Project Structure

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

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes
  4. Run tests: uv run pytest tests/
  5. Commit your changes: git commit -am 'feat: add feature'
  6. Push to the branch: git push origin feature-name
  7. 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.

Metadata

Release files for otdf-python 0.13.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for otdf-python 0.13.1
File Size Uploaded Provenance Actions
otdf_python-0.13.1.tar.gz 192.6 kB With provenance Details for otdf_python-0.13.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for otdf-python 0.13.1
File Interpreter ABI Platform Actions
otdf_python-0.13.1-py3-none-any.whl Python 3 none any Details for otdf_python-0.13.1-py3-none-any.whl

Total release size: 458.6 kB

Release files / otdf_python-0.13.1.tar.gz

Download URL otdf_python-0.13.1.tar.gz
Size 192.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d61d14e8c8b6ff2f9eea7fcc720ce4b3029599f784791fd4f7301a078c9e2b25
BLAKE2b-256 checksum
How to use checksums
0d61233546632c66b243042c34272c7619481feddd4763e4b9b2aafce2160846
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / otdf_python-0.13.1-py3-none-any.whl

Download URL otdf_python-0.13.1-py3-none-any.whl
Size 266.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33c40b1cb8a63bafc9fb786c02773ed52fb9ed9db52de9a1b249f2a10031c1d5
BLAKE2b-256 checksum
How to use checksums
6214c4d311ea1b2b442cffc1499858d0a8b72b0eec2aca3441c7f126820b3b1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for otdf-python 0.13.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for otdf_python-0.13.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.13.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page