diff --git a/README.md b/README.md index e47e3eb..92100c6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index f6dc3cc..424886e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ @@ -18,6 +18,7 @@ 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", ] @@ -25,6 +26,17 @@ dependencies = [ 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 = [ @@ -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 } diff --git a/src/otdf_python/cli.py b/src/otdf_python/cli.py index ee7c6d6..a9355c4 100644 --- a/src/otdf_python/cli.py +++ b/src/otdf_python/cli.py @@ -22,7 +22,7 @@ # Version - get from project metadata -__version__ = "0.3.0a1" +__version__ = "0.3.0a2" # Set up logging diff --git a/tests/test_cli.py b/tests/test_cli.py index 13529b7..a46e296 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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(): diff --git a/uv.lock b/uv.lock index 14cb079..cbfbf2e 100644 --- a/uv.lock +++ b/uv.lock @@ -499,7 +499,7 @@ wheels = [ [[package]] name = "otdf-python" -version = "0.3.0a1" +version = "0.3.0a2" source = { editable = "." } dependencies = [ { name = "connect-python", extra = ["compiler"] }, @@ -840,11 +840,11 @@ wheels = [ [[package]] name = "types-protobuf" -version = "6.30.2.20250703" +version = "6.30.2.20250809" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/dc/54/d63ce1eee8e93c4d710bbe2c663ec68e3672cf4f2fca26eecd20981c0c5d/types_protobuf-6.30.2.20250703.tar.gz", hash = "sha256:609a974754bbb71fa178fc641f51050395e8e1849f49d0420a6281ed8d1ddf46", size = 62300, upload-time = "2025-07-03T03:14:05.74Z" } +sdist = { url = "https://files.pythonhosted.org/packages/d5/9e/8777c578b5b66f6ef99ce9dac4865b51016a52b1d681942fbf75ac35d60f/types_protobuf-6.30.2.20250809.tar.gz", hash = "sha256:b04f2998edf0d81bd8600bbd5db0b2adf547837eef6362ba364925cee21a33b4", size = 62204, upload-time = "2025-08-09T03:14:07.547Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/7e/2b/5d0377c3d6e0f49d4847ad2c40629593fee4a5c9ec56eba26a15c708fbc0/types_protobuf-6.30.2.20250703-py3-none-any.whl", hash = "sha256:fa5aff9036e9ef432d703abbdd801b436a249b6802e4df5ef74513e272434e57", size = 76489, upload-time = "2025-07-03T03:14:04.453Z" }, + { url = "https://files.pythonhosted.org/packages/2c/9a/43daca708592570539888d80d6b708dff0b1795218aaf6b13057cc2e2c18/types_protobuf-6.30.2.20250809-py3-none-any.whl", hash = "sha256:7afc2d3f569d281dd22f339179577243be60bf7d1dfb4bc13d0109859fb1f1be", size = 76389, upload-time = "2025-08-09T03:14:06.531Z" }, ] [[package]]