From 685a9d3d719e59c6c0ed52e915035b2cb52d1192 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Fri, 15 May 2026 00:30:06 +0530 Subject: [PATCH 1/2] SK-2817: cleanup samples --- samples/detect_api/deidentify_file.py | 124 +++++++++--------- samples/detect_api/deidentify_file_async.py | 62 ++++----- .../signed_token_generation_example.py | 38 +++--- .../token_generation_example.py | 7 +- samples/vault_api/credentials_options.py | 28 ++-- samples/vault_api/get_records.py | 15 +-- 6 files changed, 136 insertions(+), 138 deletions(-) diff --git a/samples/detect_api/deidentify_file.py b/samples/detect_api/deidentify_file.py index 99b4b26e..88f012c9 100644 --- a/samples/detect_api/deidentify_file.py +++ b/samples/detect_api/deidentify_file.py @@ -1,7 +1,14 @@ from skyflow.error import SkyflowError from skyflow import Env, Skyflow, LogLevel from skyflow.utils.enums import DetectEntities, MaskingMethod, DetectOutputTranscriptions -from skyflow.vault.detect import DeidentifyFileRequest, TokenFormat, Transformations, DateTransformation, Bleep, FileInput +from skyflow.vault.detect import ( + DeidentifyFileRequest, + TokenFormat, + Transformations, + DateTransformation, + Bleep, + FileInput, +) """ * Skyflow Deidentify File Example @@ -11,6 +18,7 @@ * spreadsheets, presentations, structured text. """ + def perform_file_deidentification(): try: # Step 1: Configure Credentials @@ -23,7 +31,7 @@ def perform_file_deidentification(): 'vault_id': '', # Replace with your vault ID 'cluster_id': '', # Replace with your cluster ID 'env': Env.PROD, # Deployment environment - 'credentials': credentials + 'credentials': credentials, } # Step 3: Configure & Initialize Skyflow Client @@ -36,70 +44,66 @@ def perform_file_deidentification(): # Step 4: Create File Object file_path = '' # Replace with your file path - file = open(file_path, 'rb') - # Step 5: Configure Deidentify File Request with all options - deidentify_request = DeidentifyFileRequest( - file=FileInput(file), # File to de-identify (can also provide a file path) - entities=[DetectEntities.SSN, DetectEntities.CREDIT_CARD], # Entities to detect - allow_regex_list=[''], # Optional: Patterns to allow - restrict_regex_list=[''], # Optional: Patterns to restrict - - # Token format configuration - token_format=TokenFormat( - vault_token=[DetectEntities.SSN], # Use vault tokens for these entities - ), - - # Optional: Custom transformations - # transformations=Transformations( - # shift_dates=DateTransformation( - # max_days=30, - # min_days=10, - # entities=[DetectEntities.DOB] - # ) - # ), - - # Output configuration - output_directory='', # Where to save processed file - wait_time=15, # Max wait time in seconds (max 64) - - # Image-specific options - output_processed_image=True, # Include processed image in output - output_ocr_text=True, # Include OCR text in response - masking_method=MaskingMethod.BLACKBOX, # Masking method for images - - # PDF-specific options - pixel_density=15, # Pixel density for PDF processing - max_resolution=2000, # Max resolution for PDF - # Audio-specific options - output_processed_audio=True, # Include processed audio - output_transcription=DetectOutputTranscriptions.PLAINTEXT_TRANSCRIPTION, # Transcription type - - # Audio bleep configuration - - # bleep=Bleep( - # gain=5, # Loudness in dB - # frequency=1000, # Pitch in Hz - # start_padding=0.1, # Padding at start (seconds) - # stop_padding=0.2 # Padding at end (seconds) - # ) - ) - - # Step 6: Call deidentifyFile API - response = skyflow_client.detect().deidentify_file(deidentify_request) + # Step 5: Configure Deidentify File Request and call API + with open(file_path, 'rb') as file: + deidentify_request = DeidentifyFileRequest( + file=FileInput(file), # File to de-identify (can also provide a file path) + entities=[DetectEntities.SSN, DetectEntities.CREDIT_CARD], # Entities to detect + allow_regex_list=[''], # Optional: Patterns to allow + restrict_regex_list=[''], # Optional: Patterns to restrict + # Token format configuration + token_format=TokenFormat( + vault_token=[DetectEntities.SSN], # Use vault tokens for these entities + ), + # Optional: Custom transformations + # transformations=Transformations( + # shift_dates=DateTransformation( + # max_days=30, + # min_days=10, + # entities=[DetectEntities.DOB] + # ) + # ), + # Output configuration + output_directory='', # Where to save processed file + wait_time=15, # Max wait time in seconds (max 64) + # Image-specific options + output_processed_image=True, # Include processed image in output + output_ocr_text=True, # Include OCR text in response + masking_method=MaskingMethod.BLACKBOX, # Masking method for images + # PDF-specific options + pixel_density=15, # Pixel density for PDF processing + max_resolution=2000, # Max resolution for PDF + # Audio-specific options + output_processed_audio=True, # Include processed audio + output_transcription=DetectOutputTranscriptions.PLAINTEXT_TRANSCRIPTION, # Transcription type + # Audio bleep configuration + # bleep=Bleep( + # gain=5, # Loudness in dB + # frequency=1000, # Pitch in Hz + # start_padding=0.1, # Padding at start (seconds) + # stop_padding=0.2 # Padding at end (seconds) + # ) + ) + + # Step 6: Call deidentifyFile API + response = skyflow_client.detect().deidentify_file(deidentify_request) # Handle Successful Response - print("\nDeidentify File Response:", response) + print('\nDeidentify File Response:', response) except SkyflowError as error: # Handle Skyflow-specific errors - print('\nSkyflow Error:', { - 'http_code': error.http_code, - 'grpc_code': error.grpc_code, - 'http_status': error.http_status, - 'message': error.message, - 'details': error.details - }) + print( + '\nSkyflow Error:', + { + 'http_code': error.http_code, + 'grpc_code': error.grpc_code, + 'http_status': error.http_status, + 'message': error.message, + 'details': error.details, + }, + ) except Exception as error: # Handle unexpected errors print('Unexpected Error:', error) diff --git a/samples/detect_api/deidentify_file_async.py b/samples/detect_api/deidentify_file_async.py index 579dab2e..7ff2ac13 100644 --- a/samples/detect_api/deidentify_file_async.py +++ b/samples/detect_api/deidentify_file_async.py @@ -1,7 +1,14 @@ from skyflow.error import SkyflowError from skyflow import Env, Skyflow, LogLevel from skyflow.utils.enums import DetectEntities, MaskingMethod, DetectOutputTranscriptions -from skyflow.vault.detect import DeidentifyFileRequest, TokenFormat, Transformations, DateTransformation, Bleep, FileInput +from skyflow.vault.detect import ( + DeidentifyFileRequest, + TokenFormat, + Transformations, + DateTransformation, + Bleep, + FileInput, +) from concurrent.futures import ThreadPoolExecutor """ @@ -13,6 +20,7 @@ * spreadsheets, presentations, structured text. """ + def perform_file_deidentification_async(): try: # Step 1: Configure Credentials @@ -25,7 +33,7 @@ def perform_file_deidentification_async(): 'vault_id': '', # Replace with your vault ID 'cluster_id': '', # Replace with your cluster ID 'env': Env.PROD, # Deployment environment - 'credentials': credentials + 'credentials': credentials, } # Step 3: Configure & Initialize Skyflow Client @@ -38,18 +46,16 @@ def perform_file_deidentification_async(): # Step 4: Create File Object file_path = '' # Replace with your file path - + deidentify_request = DeidentifyFileRequest( file=FileInput(file_path=file_path), # File to de-identify # entities=[DetectEntities.SSN, DetectEntities.CREDIT_CARD], # Entities to detect allow_regex_list=[''], # Optional: Patterns to allow restrict_regex_list=[''], # Optional: Patterns to restrict - # Token format configuration token_format=TokenFormat( vault_token=[DetectEntities.SSN], # Use vault tokens for these entities ), - # Optional: Custom transformations # transformations=Transformations( # shift_dates=DateTransformation( @@ -58,26 +64,20 @@ def perform_file_deidentification_async(): # entities=[DetectEntities.DOB] # ) # ), - - # Output configuration - output_directory='', # Where to save processed file - wait_time=15, # Max wait time in seconds (max 64) - + # Output configuration + output_directory='', # Where to save processed file + wait_time=15, # Max wait time in seconds (max 64) # Image-specific options output_processed_image=True, # Include processed image in output output_ocr_text=True, # Include OCR text in response masking_method=MaskingMethod.BLACKBOX, # Masking method for images - # PDF-specific options pixel_density=15, # Pixel density for PDF processing max_resolution=2000, # Max resolution for PDF - # Audio-specific options output_processed_audio=True, # Include processed audio output_transcription=DetectOutputTranscriptions.PLAINTEXT_TRANSCRIPTION, # Transcription type - # Audio bleep configuration - # bleep=Bleep( # gain=5, # Loudness in dB # frequency=1000, # Pitch in Hz @@ -85,35 +85,36 @@ def perform_file_deidentification_async(): # stop_padding=0.2 # Padding at end (seconds) # ) ) - + # Create a thread pool executor executor = ThreadPoolExecutor(max_workers=1) - - future = executor.submit( - lambda: skyflow_client.detect().deidentify_file(deidentify_request) - ) - + + future = executor.submit(lambda: skyflow_client.detect().deidentify_file(deidentify_request)) + def handle_response(future): exception = future.exception() if exception is not None: if isinstance(exception, SkyflowError): # Handle Skyflow-specific errors - print('\nSkyflow Error:', { - 'http_code': exception.http_code, - 'grpc_code': exception.grpc_code, - 'http_status': exception.http_status, - 'message': exception.message, - 'details': exception.details - }) + print( + '\nSkyflow Error:', + { + 'http_code': exception.http_code, + 'grpc_code': exception.grpc_code, + 'http_status': exception.http_status, + 'message': exception.message, + 'details': exception.details, + }, + ) else: # Handle unexpected errors print('Unexpected Error:', exception) return - + # Handle Successful Response result = future.result() - print("\nDeidentify File Response:", result) - + print('\nDeidentify File Response:', result) + future.add_done_callback(handle_response) executor.shutdown(wait=True) @@ -121,4 +122,3 @@ def handle_response(future): except Exception as error: # Handle unexpected errors print('Unexpected Error:', error) - diff --git a/samples/service_account/signed_token_generation_example.py b/samples/service_account/signed_token_generation_example.py index 6ede1746..7ae175cd 100644 --- a/samples/service_account/signed_token_generation_example.py +++ b/samples/service_account/signed_token_generation_example.py @@ -1,12 +1,10 @@ import json from skyflow.service_account import ( - is_expired, generate_signed_data_tokens, generate_signed_data_tokens_from_creds, ) -file_path = 'CREDENTIALS_FILE_PATH' -bearer_token = '' +file_path = '' skyflow_credentials = { 'clientID': '', @@ -19,15 +17,18 @@ # Approach 1: Signed data tokens with string context +# Returns: [('', ''), ...] def get_signed_tokens_with_string_context(): options = { 'ctx': 'user_12345', - 'data_tokens': ['DATA_TOKEN1', 'DATA_TOKEN2'], + 'data_tokens': ['', ''], 'time_to_live': 90, # in seconds } try: - data_token, signed_data_token = generate_signed_data_tokens(file_path, options) - return data_token, signed_data_token + results = generate_signed_data_tokens(file_path, options) + for data_token, signed_data_token in results: + print(f' Token: {data_token}, Signed Token: {signed_data_token}') + return results except Exception as e: print(f'Error: {str(e)}') @@ -42,12 +43,14 @@ def get_signed_tokens_with_object_context(): 'department': 'research', 'user_id': 'user_67890', }, - 'data_tokens': ['DATA_TOKEN1', 'DATA_TOKEN2'], + 'data_tokens': ['', ''], 'time_to_live': 90, } try: - data_token, signed_data_token = generate_signed_data_tokens(file_path, options) - return data_token, signed_data_token + results = generate_signed_data_tokens(file_path, options) + for data_token, signed_data_token in results: + print(f' Token: {data_token}, Signed Token: {signed_data_token}') + return results except Exception as e: print(f'Error: {str(e)}') @@ -56,16 +59,21 @@ def get_signed_tokens_with_object_context(): def get_signed_tokens_from_credentials_string(): options = { 'ctx': 'user_12345', - 'data_tokens': ['DATA_TOKEN1', 'DATA_TOKEN2'], + 'data_tokens': ['', ''], 'time_to_live': 90, } try: - data_token, signed_data_token = generate_signed_data_tokens_from_creds(credentials_string, options) - return data_token, signed_data_token + results = generate_signed_data_tokens_from_creds(credentials_string, options) + for data_token, signed_data_token in results: + print(f' Token: {data_token}, Signed Token: {signed_data_token}') + return results except Exception as e: print(f'Error: {str(e)}') -print("String context:", get_signed_tokens_with_string_context()) -print("Object context:", get_signed_tokens_with_object_context()) -print("Creds string:", get_signed_tokens_from_credentials_string()) +print('String context:') +get_signed_tokens_with_string_context() +print('Object context:') +get_signed_tokens_with_object_context() +print('Creds string:') +get_signed_tokens_from_credentials_string() diff --git a/samples/service_account/token_generation_example.py b/samples/service_account/token_generation_example.py index 34db4c37..32fa022b 100644 --- a/samples/service_account/token_generation_example.py +++ b/samples/service_account/token_generation_example.py @@ -5,7 +5,7 @@ is_expired, ) -file_path = 'CREDENTIALS_FILE_PATH' +file_path = '' bearer_token = '' # To generate Bearer Token from credentials string. @@ -46,10 +46,9 @@ def get_bearer_token_from_credentials_string(): bearer_token = token return bearer_token except Exception as e: - print(f"Error generating token from credentials string: {str(e)}") - + print(f'Error generating token from credentials string: {str(e)}') print(get_bearer_token_from_file_path()) -print(get_bearer_token_from_credentials_string()) \ No newline at end of file +print(get_bearer_token_from_credentials_string()) diff --git a/samples/vault_api/credentials_options.py b/samples/vault_api/credentials_options.py index db792042..2155f99d 100644 --- a/samples/vault_api/credentials_options.py +++ b/samples/vault_api/credentials_options.py @@ -13,6 +13,7 @@ 4. Handle response and errors """ + def perform_secure_data_deletion(): try: # Step 1: Configure Bearer Token Credentials @@ -31,10 +32,10 @@ def perform_secure_data_deletion(): } secondary_vault_config = { - 'vault_id': 'YOUR_SECONDARY_VAULT_ID', # Secondary vault - 'cluster_id': 'YOUR_SECONDARY_CLUSTER_ID', # Cluster ID from your vault URL + 'vault_id': '', # Secondary vault + 'cluster_id': '', # Cluster ID from your vault URL 'env': Env.PROD, # Deployment environment - 'credentials': credentials + 'credentials': credentials, } # Step 3: Configure & Initialize Skyflow Client @@ -51,13 +52,10 @@ def perform_secure_data_deletion(): primary_table_name = '' # Replace with actual table name - primary_delete_request = DeleteRequest( - table=primary_table_name, - ids=primary_delete_ids - ) + primary_delete_request = DeleteRequest(table=primary_table_name, ids=primary_delete_ids) # Perform Delete Operation for Primary Vault - primary_delete_response = skyflow_client.vault('').delete(primary_delete_request) + primary_delete_response = skyflow_client.vault('').delete(primary_delete_request) # Handle Successful Response print('Primary Vault Deletion Successful:', primary_delete_response) @@ -67,10 +65,7 @@ def perform_secure_data_deletion(): secondary_table_name = '' # Replace with actual table name - secondary_delete_request = DeleteRequest( - table=secondary_table_name, - ids=secondary_delete_ids - ) + secondary_delete_request = DeleteRequest(table=secondary_table_name, ids=secondary_delete_ids) # Perform Delete Operation for Secondary Vault secondary_delete_response = skyflow_client.vault('').delete(secondary_delete_request) @@ -78,17 +73,12 @@ def perform_secure_data_deletion(): # Handle Successful Response print('Secondary Vault Deletion Successful:', secondary_delete_response) - except SkyflowError as error: # Comprehensive Error Handling - print('Skyflow Specific Error: ', { - 'code': error.http_code, - 'message': error.message, - 'details': error.details - }) + print('Skyflow Specific Error: ', {'code': error.http_code, 'message': error.message, 'details': error.details}) except Exception as error: print('Unexpected Error:', error) # Invoke the secure data deletion function -perform_secure_data_deletion() \ No newline at end of file +perform_secure_data_deletion() diff --git a/samples/vault_api/get_records.py b/samples/vault_api/get_records.py index b2fd445f..9e4d031a 100644 --- a/samples/vault_api/get_records.py +++ b/samples/vault_api/get_records.py @@ -4,6 +4,7 @@ from skyflow import Skyflow, LogLevel from skyflow.vault.data import GetRequest + def perform_secure_data_retrieval(): try: # Step 1: Configure Credentials @@ -28,7 +29,7 @@ def perform_secure_data_retrieval(): 'vault_id': '', # primary vault 'cluster_id': '', # Cluster ID from your vault URL 'env': Env.PROD, # Deployment environment (PROD by default) - 'credentials': credentials # Authentication method + 'credentials': credentials, # Authentication method } # Step 3: Configure & Initialize Skyflow Client @@ -42,10 +43,10 @@ def perform_secure_data_retrieval(): # Step 4: Prepare Retrieval Data - get_ids = ['', 'SKYFLOW_ID2'] + get_ids = ['', ''] get_request = GetRequest( - table='', # Replace with your actual table name + table='', # Replace with your actual table name ids=get_ids, ) @@ -57,15 +58,11 @@ def perform_secure_data_retrieval(): except SkyflowError as error: # Comprehensive Error Handling - print('Skyflow Specific Error: ', { - 'code': error.http_code, - 'message': error.message, - 'details': error.details - }) + print('Skyflow Specific Error: ', {'code': error.http_code, 'message': error.message, 'details': error.details}) except Exception as error: print('Unexpected Error:', error) # Invoke the secure data retrieval function -perform_secure_data_retrieval() \ No newline at end of file +perform_secure_data_retrieval() From 0c9c50a815565a924c87c442ef997e6a3576fae0 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 19 May 2026 12:34:29 +0530 Subject: [PATCH 2/2] SK-2838: add v2 banner in readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 6a980d3f..23326cca 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # Skyflow Python SDK +> **This is the current, recommended version of the Skyflow SDK.** V2.1.0 brings flexible auth, multi-vault support, native data types, and rich error diagnostics. +> +> Migrating from v1? See the **[Migration Guide](https://github.com/skyflowapi/skyflow-python/blob/main/docs/migrate_to_v2.md)** for step-by-step instructions. V1 is in maintenance mode and will reach End of Life on October 31, 2026. + The Skyflow Python SDK is designed to help with integrating Skyflow into a Python backend. ## Table of Contents