Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 84 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,47 +81,104 @@ pip install otdf-python
### Basic Configuration

```python
from otdf_python.config import Config
from otdf_python.sdk import SDK

# Create configuration
config = Config(
platform_endpoint="https://platform.example.com",
client_id="your-client-id",
client_secret="your-client-secret"
)
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")

# Initialize SDK
sdk = SDK(config)
# Build the SDK instance
sdk = builder.build()
```

### Advanced Configuration

```python
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

```python
# Encrypt a string
encrypted_data = sdk.encrypt_string(
data="Hello, World!",
attributes=["https://example.com/attr/classification/value/public"]
)
from io import BytesIO

# Encrypt a file
sdk.encrypt_file(
input_path="plaintext.txt",
output_path="encrypted.tdf"
)
# Create TDF configuration with attributes
config = sdk.new_tdf_config(attributes=["https://example.com/attr/classification/value/public"])

# 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

```python
# Decrypt to string
decrypted_text = sdk.decrypt_string(encrypted_data)
from otdf_python.tdf import TDFReaderConfig

# Read encrypted TDF file
with open("encrypted.tdf", "rb") as f:
encrypted_data = f.read()

# Decrypt TDF
reader_config = TDFReaderConfig()
tdf_reader = sdk.load_tdf(encrypted_data, reader_config)
decrypted_data = tdf_reader.payload

# Save decrypted data
with open("decrypted.txt", "wb") as f:
f.write(decrypted_data)

# Don't forget to close the SDK when done
sdk.close()
```

### NanoTDF Support

```python
from io import BytesIO
from otdf_python.config import NanoTDFConfig

# Decrypt a file
sdk.decrypt_file(
input_path="encrypted.tdf",
output_path="decrypted.txt"
# Create NanoTDF configuration
config = NanoTDFConfig(
attributes=["https://example.com/attr/classification/value/public"],
ecc_mode="ecdsa" # or "gmac"
)

# Encrypt to NanoTDF format
input_data = b"Hello, World!"
output_stream = BytesIO()
size = sdk.create_nano_tdf(BytesIO(input_data), output_stream, config)
encrypted_data = output_stream.getvalue()

# Decrypt NanoTDF
decrypted_stream = BytesIO()
sdk.read_nano_tdf(BytesIO(encrypted_data), decrypted_stream, config)
decrypted_data = decrypted_stream.getvalue()
```

## Project Structure
Expand Down
22 changes: 13 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "otdf-python"
version = "0.3.0a1"
version = "0.3.0a2"
description = "Unofficial OpenTDF SDK for Python"
readme = "README.md"
authors = [
Expand All @@ -18,13 +18,25 @@ dependencies = [
"grpcio-tools>=1.74.0",
"grpcio-status>=1.74.0",
"protoc-gen-openapiv2>=0.0.1",
# Local workspace dependency for proto files
"otdf-python-proto",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = [
"src/otdf_python",
]

[tool.uv.sources]
otdf-python-proto = { workspace = true }

[tool.uv.workspace]
members = [".", "otdf-python-proto"]


[dependency-groups]
dev = [
Expand Down Expand Up @@ -68,11 +80,3 @@ lint.select = [
"FURB", # refurb (FURB)
"PT018", # flake8-pytest-style (pytest style)
]

[tool.uv.workspace]
members = [
"otdf-python-proto",
]

[tool.uv.sources]
otdf-python-proto = { workspace = true }
2 changes: 1 addition & 1 deletion src/otdf_python/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


# Version - get from project metadata
__version__ = "0.3.0a1"
__version__ = "0.3.0a2"


# Set up logging
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_cli_version():
)
assert result.returncode == 0
assert "OpenTDF Python SDK" in result.stdout
assert "0.3.0a1" in result.stdout
assert "0.3.0a2" in result.stdout


def test_cli_encrypt_help():
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading