@@ -16,6 +16,7 @@ This Python SDK is designed to help developers easily implement Skyflow into the
1616 - [ Requirements] ( #requirements )
1717 - [ Configuration] ( #configuration )
1818 - [ Service Account Bearer Token Generation] ( #service-account-bearer-token-generation )
19+ [ Migration from v1 to v2] ( #migrate-from-v1-to-v2 )
1920 - [ Vault APIs] ( #vault-apis )
2021 - [ Insert data into the vault] ( #insert-data-into-the-vault )
2122 - [ Detokenize] ( #detokenize )
@@ -328,6 +329,250 @@ try:
328329except SkyflowError as e:
329330 print (e)
330331```
332+ ## Migrate from V1 to V2
333+
334+ Below are the steps to migrate the Python SDK from V1 to V2.
335+
336+ ### 1. Authentication Options
337+
338+ In V2, we have introduced multiple authentication options.
339+ You can now provide credentials in the following ways:
340+
341+ 1 . ** API Key (Recommended)**
342+ 2 . ** Environment Variables** (SKYFLOW_CREDENTIALS) (Recommended)
343+ 3 . ** Path to your credentials JSON file**
344+ 4 . ** Stringified JSON of your credentials**
345+ 5 . ** Bearer token**
346+
347+ These options allow you to choose the authentication method that best suits your use case.
348+
349+ #### V1 (Old):
350+ Passing the token provider function below as a parameter to the Configuration.
351+
352+ ``` python
353+ # User defined function to provide access token to the vault apis
354+ def token_provider ():
355+ global bearerToken
356+ if !(is_expired(bearerToken)):
357+ return bearerToken
358+ bearerToken, _ = generate_bearer_token(' <YOUR_CREDENTIALS_FILE_PATH>' )
359+ return bearerToken
360+ ```
361+
362+ #### V2 (New):
363+ Passing one of the following:
364+
365+ ``` python
366+ # Option 1: API Key (Recommended)
367+ credentials = {
368+ ' api_key' : ' <your_api_key>' , # API key
369+ }
370+
371+ # Option 2: Environment Variables (Recommended)
372+ # Set SKYFLOW_CREDENTIALS in your environment
373+
374+ # Option 3: Credentials File
375+ credentials = {
376+ ' path' : ' <path_to_credentials_json>' , # Path to credentials file
377+ }
378+
379+ # Option 4: Stringified JSON
380+ credentials = {
381+ ' credentials_string' : ' <your_credentials_string>' , # Credentials as string
382+ }
383+
384+ # Option 5: Bearer Token
385+ credentials = {
386+ ' token' : ' <your_bearer_token>' , # Bearer token
387+ }
388+ ```
389+
390+ ** Notes:**
391+ 1 . Use only ONE authentication method.
392+ 2 . Environment variables take precedence over programmatic configuration.
393+ 3 . API Key or Environment Variables are recommended for production use.
394+ 4 . Secure storage of credentials is essential.
395+ 5 . For overriding behavior and priority order of credentials, please refer to the README.
396+
397+ ### 2. Client Initialization
398+
399+ In V2, we have introduced a Builder design pattern for client initialization and added support for multi-vault. This allows you to configure multiple vaults during client initialization.
400+
401+ In V2, the log level is tied to each individual client instance.
402+
403+ During client initialization, you can pass the following parameters:
404+
405+ 1 . ** vault_id** and ** cluster_id** : These values are derived from the vault ID & vault URL.
406+ 2 . ** env** : Specify the environment (e.g., SANDBOX or PROD).
407+ 3 . ** credentials** : The necessary authentication credentials.
408+
409+ #### V1 (Old):
410+
411+ ``` python
412+ # Initializing a Skyflow Client instance with a SkyflowConfiguration object
413+ config = Configuration(' <YOUR_VAULT_ID>' , ' <YOUR_VAULT_URL>' , token_provider)
414+ client = Client(config)
415+ ```
416+
417+ #### V2 (New):
418+
419+ ``` python
420+ # Initializing a Skyflow Client instance
421+ client = (
422+ Skyflow.builder()
423+ .add_vault_config({
424+ ' vault_id' : ' VAULT_ID' , # Primary vault
425+ ' cluster_id' : ' CLUSTER_ID' , # ID from your vault URL e.g., https://{clusterId}.vault.skyflowapis.com
426+ ' env' : Env.PROD , # Env by default it is set to PROD
427+ ' credentials' : credentials # Individual credentials
428+ })
429+ .add_skyflow_credentials(credentials) # Skyflow credentials will be used if no individual credentials are passed
430+ .set_log_level(LogLevel.INFO ) # set log level by default it is set to ERROR
431+ .build()
432+ )
433+ ```
434+
435+ ** Key Changes:**
436+ 1 . ` vault_url ` replaced with ` clusterId ` .
437+ 2 . Added environment specification (` env ` ).
438+ 3 . Instance-specific log levels.
439+
440+ ### 3. Request & Response Structure
441+
442+ In V2, with the introduction of constructor parameters, you can now pass parameters to ` InsertRequest ` . This request need
443+ - ** table_name** : The name of the table.
444+ - ** values** : An array of objects containing the data to be inserted.
445+ The response will be of type ` InsertResponse ` class, which contains ` inserted_fields ` and errors.
446+
447+ #### V1 (Old): Request Building
448+
449+ ``` python
450+ client.insert(
451+ {
452+ " records" : [
453+ {
454+ " table" : " cards" ,
455+ " fields" : {
456+ " cardNumber" : " 41111111111" ,
457+ " cvv" : " 123" ,
458+ },
459+ }
460+ ]
461+ },
462+ InsertOptions(True ),
463+ )
464+ ```
465+
466+ #### V2 (New): Request Building
467+
468+ ``` python
469+ # Prepare Insertion Data
470+ insert_data = [
471+ {
472+ ' card_number' : ' <VALUE1>' ,
473+ ' cvv' : ' <VALUE2>' ,
474+ },
475+ ]
476+
477+ table_name = ' <SENSITIVE_DATA_TABLE>' # Replace with your actual table name
478+
479+ # Create Insert Request
480+ insert_request = InsertRequest(
481+ table_name = table_name,
482+ values = insert_data,
483+ return_tokens = True , # Optional: Get tokens for inserted data
484+ continue_on_error = True # Optional: Continue on partial errors
485+ )
486+
487+ # Perform Secure Insertion
488+ response = skyflow_client.vault(primary_vault_config.get(' vault_id' )).insert(insert_request)
489+ ```
490+
491+ #### V1 (Old): Response Structure
492+
493+ ``` json
494+ {
495+ "records" : [
496+ {
497+ "table" : " cards" ,
498+ "fields" : {
499+ "cardNumber" : " f3907186-e7e2-466f-91e5-48e12c2bcbc1" ,
500+ "cvv" : " 1989cb56-63da-4482-a2df-1f74cd0dd1a5" ,
501+ "skyflow_id" : " d863633c-8c75-44fc-b2ed-2b58162d1117"
502+ },
503+ "request_index" : 0
504+ }
505+ ]
506+ }
507+ ```
508+
509+ #### V2 (New): Response Structure
510+
511+ ``` python
512+ InsertResponse(
513+ inserted_fields = [
514+ {
515+ ' skyflow_id' : ' a8f3ed5d-55eb-4f32-bf7e-2dbf4b9d9097' ,
516+ ' card_number' : ' 5479-4229-4622-1393'
517+ }
518+ ],
519+ errors = []
520+ )
521+ ```
522+
523+ ### 4. Request Options
524+
525+ In V2, we have introduced constructor parameters, allowing you to set options as key-value pairs as parameters in request.
526+
527+ #### V1 (Old):
528+
529+ ``` python
530+ options = InsertOptions(
531+ tokens = True
532+ )
533+ ```
534+
535+ #### V2 (New):
536+
537+ ``` python
538+ insert_request = InsertRequest(
539+ table_name = table_name,
540+ values = insert_data,
541+ return_tokens = True , # Optional: Get tokens for inserted data
542+ continue_on_error = True # Optional: Continue on partial errors
543+ )
544+ ```
545+
546+ ### 5. Request Options
547+
548+ In V2, we have enriched the error details to provide better debugging capabilities.
549+ The error response now includes:
550+ - ** http_status** : The HTTP status code.
551+ - ** grpc_code** : The gRPC code associated with the error.
552+ - ** details & message** : A detailed description of the error.
553+ - ** request_id** : A unique request identifier for easier debugging.
554+
555+ #### V1 (Old) Error Structure:
556+
557+ ``` json
558+ {
559+ "code" : " <http_code>" ,
560+ "message" : " <message>"
561+ }
562+ ```
563+
564+ #### V2 (New) Error Structure:
565+
566+ ``` json
567+ {
568+ "http_status" : " <http_status>" ,
569+ "grpc_code" : " <grpc_code>" ,
570+ "http_code" : " <http_code>" ,
571+ "message" : " <message>" ,
572+ "request_id" : " <req_id>" ,
573+ "details" : [ " <details>" ]
574+ }
575+ ```
331576
332577## Vault APIs
333578
0 commit comments