From e8422825a20896ea71939ca534d8f18504771b28 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 19 Nov 2024 14:10:38 +0530 Subject: [PATCH 01/15] SK-1749: Updated samples --- .github/workflows/internal-release.yml | 2 +- .../scoped_token_generation_example.py | 5 ++- .../token_generation_with_context_example.py | 6 +-- samples/vault_api/delete_records.py | 5 +-- samples/vault_api/detokenize_records.py | 6 +-- samples/vault_api/insert_byot.py | 41 +++++++++++-------- samples/vault_api/insert_records.py | 3 +- samples/vault_api/invoke_connection.py | 14 +++++-- skyflow/generated/rest/api/tokens_api.py | 1 + skyflow/vault/data/_get_request.py | 2 +- 10 files changed, 49 insertions(+), 36 deletions(-) diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml index 629fba1..f14d216 100644 --- a/.github/workflows/internal-release.yml +++ b/.github/workflows/internal-release.yml @@ -9,7 +9,7 @@ on: - "*.yml" - "*.md" - "skyflow/utils/_version.py" - - "samples/*" + - "samples/**" branches: - release/* diff --git a/samples/service_account/scoped_token_generation_example.py b/samples/service_account/scoped_token_generation_example.py index 1b7e9ed..1f740a5 100644 --- a/samples/service_account/scoped_token_generation_example.py +++ b/samples/service_account/scoped_token_generation_example.py @@ -8,9 +8,8 @@ # Generate bearer token from credentials file path options = { - "ctx": "" + "role_ids": ["ROLE_ID1", "ROLE_ID2"] } - if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token( "", options @@ -25,3 +24,5 @@ print(bearer_token, token_type) + + diff --git a/samples/service_account/token_generation_with_context_example.py b/samples/service_account/token_generation_with_context_example.py index ea087c5..5e455a5 100644 --- a/samples/service_account/token_generation_with_context_example.py +++ b/samples/service_account/token_generation_with_context_example.py @@ -8,8 +8,9 @@ # Generate bearer token from credentials file path options = { - "role_ids": ["ROLE_ID1", "ROLE_ID2"] + "ctx": "" } + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token( "", options @@ -22,5 +23,4 @@ if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options) - print(bearer_token, token_type) - + print(bearer_token, token_type) \ No newline at end of file diff --git a/samples/vault_api/delete_records.py b/samples/vault_api/delete_records.py index 449ff91..b03122a 100644 --- a/samples/vault_api/delete_records.py +++ b/samples/vault_api/delete_records.py @@ -35,12 +35,11 @@ ] delete_request = DeleteRequest( - table='TABLE_NAME', + table='', ids = primary_delete_ids ) -# will return first Vault ID -response = client.vault().delete(delete_request) +response = client.vault('').delete(delete_request) print(response) diff --git a/samples/vault_api/detokenize_records.py b/samples/vault_api/detokenize_records.py index f20d43c..92e43fd 100644 --- a/samples/vault_api/detokenize_records.py +++ b/samples/vault_api/detokenize_records.py @@ -8,9 +8,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: skyflow_credentials_string, // credentials as string + # api_key: "API_KEY", #API_KEY + # path: "PATH", #path to credentials file + # credentials_string: skyflow_credentials_string, #credentials as string } client = ( diff --git a/samples/vault_api/insert_byot.py b/samples/vault_api/insert_byot.py index 36135d7..f0b20eb 100644 --- a/samples/vault_api/insert_byot.py +++ b/samples/vault_api/insert_byot.py @@ -1,5 +1,6 @@ from skyflow import Env from skyflow import Skyflow, LogLevel +from skyflow.error import SkyflowError from skyflow.utils.enums import TokenStrict from skyflow.vault.data import GetRequest, InsertRequest from skyflow.vault.tokens import DetokenizeRequest @@ -28,23 +29,27 @@ .build() ) -# sample data -insert_data = [ - { "card_number": 'CARD_NUMBER1', "card_cvv": 'CVV1' }, - { "card_number": 'CARD_NUMBER2', "card_cvv": 'CVV2' }, -] - -insert_request = InsertRequest( - table_name='TABLE_NAME', - values = insert_data, - continue_on_error=False, # if continue on error is set true we will return request_index for errors - token_strict=TokenStrict.ENABLE, # token strict / byot is enabled, - tokens = [ - { "card_number": 'CARD_NUMBER1', "card_cvv": 'CVV1' }, - { "card_number": 'CARD_NUMBER2', "card_cvv": 'CVV2' }, - ], -) +#Initialize Client + +try: + insert_data = [ + {"": ''}, + {"": ''} + ] + + token_data = [ + {"": ''}, + {"": ''} + ] -response = skyflow_client.vault('VAULT_ID').insert(insert_request) + insert_request = InsertRequest( + table_name='', + values=insert_data, + token_strict=TokenStrict.ENABLE, # token strict is enabled, + tokens=token_data, + ) -print(response) + response = skyflow_client.vault('VAULT_ID').insert(insert_request) + print("Response:", response) +except SkyflowError as e: + print("Error Occurred:", e) diff --git a/samples/vault_api/insert_records.py b/samples/vault_api/insert_records.py index ee89c24..da8f2a3 100644 --- a/samples/vault_api/insert_records.py +++ b/samples/vault_api/insert_records.py @@ -29,8 +29,7 @@ # sample data insert_data = [ - { "card_number": 'CARD_NUMBER1', "card_cvv": 'CVV1' }, - { "card_number": 'CARD_NUMBER2', "card_cvv": 'CVV2' }, + { "": '', "": '' }, ] insert_request = InsertRequest( diff --git a/samples/vault_api/invoke_connection.py b/samples/vault_api/invoke_connection.py index 1daca5a..84cc76d 100644 --- a/samples/vault_api/invoke_connection.py +++ b/samples/vault_api/invoke_connection.py @@ -34,19 +34,27 @@ .build() ) + body = { "KEY1": "VALUE1", "KEY2": "VALUE2" } - headers = { -'Content-Type': 'application/json' + "KEY1": "VALUE1" +} +path_params = { + "KEY1": "VALUE1" +} +query_params = { + "KEY1": "VALUE1" } invoke_connection_request = InvokeConnectionRequest( method=Method.POST, body=body, - request_headers = headers + request_headers = headers, # optional + path_params = path_params, # optional + query_params=query_params # optional ) # will return the first connection response = skyflow_client.connection().invoke(invoke_connection_request) diff --git a/skyflow/generated/rest/api/tokens_api.py b/skyflow/generated/rest/api/tokens_api.py index d6bd55e..e21e793 100644 --- a/skyflow/generated/rest/api/tokens_api.py +++ b/skyflow/generated/rest/api/tokens_api.py @@ -101,6 +101,7 @@ def record_service_detokenize( _response_types_map: Dict[str, Optional[str]] = { '200': "V1DetokenizeResponse", + '207': "V1DetokenizeResponse", '404': "object", } response_data = self.api_client.call_api( diff --git a/skyflow/vault/data/_get_request.py b/skyflow/vault/data/_get_request.py index e40f904..a6c57e9 100644 --- a/skyflow/vault/data/_get_request.py +++ b/skyflow/vault/data/_get_request.py @@ -5,7 +5,7 @@ class GetRequest: def __init__(self, table, ids = None, - redaction_type = "plain-text", + redaction_type = None, return_tokens = False, fields = None, offset = None, From 2e1272e86f5249563fb7e8a8e8db4d4ea08a5c4a Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Tue, 19 Nov 2024 15:49:17 +0530 Subject: [PATCH 02/15] SK-1749: Updated README --- README.md | 1361 ++++++++++++---------- samples/vault_api/credentials_options.py | 6 +- samples/vault_api/delete_records.py | 6 +- samples/vault_api/get_column_values.py | 7 +- samples/vault_api/get_records.py | 7 +- samples/vault_api/insert_byot.py | 9 +- samples/vault_api/insert_records.py | 9 +- samples/vault_api/invoke_connection.py | 8 +- samples/vault_api/query_records.py | 11 +- samples/vault_api/tokenize_records.py | 11 +- samples/vault_api/update_record.py | 11 +- 11 files changed, 761 insertions(+), 685 deletions(-) diff --git a/README.md b/README.md index b64a0bc..24cf7e9 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Invoking connections to call downstream third party APIs without directly handli ### Requirements -- Python 3.7.0 and above +- Python 3.8.0 and above ### Configuration @@ -57,542 +57,620 @@ The [Service Account](https://github.com/skyflowapi/skyflow-python/tree/main/sky The `generate_bearer_token(filepath)` function takes the credentials file path for token generation, alternatively, you can also send the entire credentials as string, by using `generate_bearer_token_from_creds(credentials)` -[Example using filepath](https://github.com/skyflowapi/skyflow-python/blob/main/samples/sa_token_sample.py): +[Example using filepath](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/token_generation_example.py): ```python -from skyflow.errors import SkyflowError +from skyflow.error import SkyflowError from skyflow.service_account import generate_bearer_token, is_expired # cache token for reuse -bearerToken = '' -tokenType = '' +bearer_token = '' +token_type = '' def token_provider(): - global bearerToken - global tokenType + global bearer_token + global token_type - if is_expired(bearerToken): - bearerToken, tokenType = generate_bearer_token('') - return bearerToken, tokenType + if is_expired(bearer_token): + bearer_token, token_type = generate_bearer_toke('') + return bearer_token, token_type try: - accessToken, tokenType = token_provider() - print("Access Token:", accessToken) - print("Type of token:", tokenType) + bearer_token, token_type = token_provider() + print("Access Token:", bearer_token) + print("Type of token:", token_type) except SkyflowError as e: print(e) ``` -[Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/main/samples/generate_bearer_token_from_creds_sample.py): +[Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/token_generation_example.py): ```python -from skyflow.errors import SkyflowError -from skyflow.service_account import generate_bearer_token_from_creds, is_expired +from skyflow.error import SkyflowError +from skyflow.service_account import generate_bearer_token, generate_bearer_token_from_creds, is_expired # cache token for reuse -bearerToken = '' -tokenType = '' +bearer_token = '' +token_type = '' def token_provider(): - global bearerToken - global tokenType + global bearer_token + global token_type # As an example - credentials = { - "clientID": "", - "clientName": "", - "keyID": "", - "tokenURI": '', - "privateKey": "" - } - jsonString = json.dumps(credentials) - if is_expired(bearerToken): - bearerToken, tokenType = generate_bearer_token_from_creds( - credentials=jsonString) - return bearerToken, tokenType + skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' + if is_expired(bearer_token): + bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string) + return bearer_token, token_type try: - accessToken, tokenType = token_provider() - print("Access Token:", accessToken) - print("Type of token:", tokenType) + bearer_token, token_type = token_provider() + print("Access Token:", bearer_token) + print("Type of token:", token_type) except SkyflowError as e: print(e) ``` -## Vault APIs +## Service Account Scoped Token Generation -The [Vault](https://github.com/skyflowapi/skyflow-python/tree/main/skyflow/vault) python module is used to perform operations on the vault such as inserting records, detokenizing tokens, retrieving tokens for a skyflow_id and to invoke a connection. +[Example using filepath](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/scoped_token_generation_example.py): + +```python +from skyflow.error import SkyflowError +from skyflow.service_account import generate_bearer_token, is_expired + +# cache token for reuse +bearer_token = '' +token_type = '' +options = { + "role_ids": ["ROLE_ID1", "ROLE_ID2"] +} +def token_provider(): + global bearer_token + global token_type + + if is_expired(bearer_token): + bearer_token, token_type = generate_bearer_token('', options) + return bearer_token, token_type + +try: + bearer_token, token_type = token_provider() + print("Access Token:", bearer_token) + print("Type of token:", token_type) +except SkyflowError as e: + print(e) + +``` + + +[Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/scoped_token_generation_example.py): + +```python +from skyflow.error import SkyflowError +from skyflow.service_account import generate_bearer_token, generate_bearer_token_from_creds, is_expired + +# cache token for reuse +bearer_token = '' +token_type = '' +options = { + "role_ids": ["ROLE_ID1", "ROLE_ID2"] +} +def token_provider(): + global bearer_token + global token_type + # As an example + skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' + if is_expired(bearer_token): + bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options) + return bearer_token, token_type + +try: + bearer_token, token_type = token_provider() + print("Access Token:", bearer_token) + print("Type of token:", token_type) +except SkyflowError as e: + print(e) + +``` + +## Service Account Token Generation With Context + +[Example using filepath](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/token_generation_with_context_example.py): + +```python +from skyflow.error import SkyflowError +from skyflow.service_account import generate_bearer_token, is_expired + +# cache token for reuse +bearer_token = '' +token_type = '' +options = { + "ctx": "" +} +def token_provider(): + global bearer_token + global token_type + + if is_expired(bearer_token): + bearer_token, token_type = generate_bearer_token('', options) + return bearer_token, token_type + +try: + bearer_token, token_type = token_provider() + print("Access Token:", bearer_token) + print("Type of token:", token_type) +except SkyflowError as e: + print(e) + +``` -To use this module, the skyflow client must first be initialized as follows. + +[Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/token_generation_with_context_example.py): + +```python +from skyflow.error import SkyflowError +from skyflow.service_account import generate_bearer_token, generate_bearer_token_from_creds, is_expired + +# cache token for reuse +bearer_token = '' +token_type = '' +options = { + "ctx": "" +} +def token_provider(): + global bearer_token + global token_type + # As an example + skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' + if is_expired(bearer_token): + bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options) + return bearer_token, token_type + +try: + bearer_token, token_type = token_provider() + print("Access Token:", bearer_token) + print("Type of token:", token_type) +except SkyflowError as e: + print(e) + +``` + +## Service Account Signed Token Generation + +[Example using filepath](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/signed_token_generation_example.py): ```python -from skyflow.vault import Client, Configuration +from skyflow.error import SkyflowError from skyflow.service_account import generate_bearer_token, is_expired -# cache for reuse -bearerToken = '' +# cache token for reuse +bearer_token = '' +token_type = '' +options = { + "ctx": "CONTEX_ID", + "data_tokens": ["DATA_TOKEN1", "DATA_TOKEN2"], + "time_to_live": 90 # in seconds +} +def token_provider(): + global bearer_token + global token_type + + if is_expired(bearer_token): + bearer_token, token_type = generate_bearer_token('', options) + return bearer_token, token_type + +try: + bearer_token, token_type = token_provider() + print("Access Token:", bearer_token) + print("Type of token:", token_type) +except SkyflowError as e: + print(e) + +``` + + +[Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/signed_token_generation_example.py): + +```python +from skyflow.error import SkyflowError +from skyflow.service_account import generate_bearer_token, generate_bearer_token_from_creds, is_expired -# User defined function to provide access token to the vault apis +# cache token for reuse +bearer_token = '' +token_type = '' +options = { + "ctx": "CONTEX_ID", + "data_tokens": ["DATA_TOKEN1", "DATA_TOKEN2"], + "time_to_live": 90 # in seconds +} def token_provider(): - global bearerToken - if !(is_expired(bearerToken)): - return bearerToken - bearerToken, _ = generate_bearer_token('') - return bearerToken + global bearer_token + global token_type + # As an example + skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' + if is_expired(bearer_token): + bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options) + return bearer_token, token_type + +try: + bearer_token, token_type = token_provider() + print("Access Token:", bearer_token) + print("Type of token:", token_type) +except SkyflowError as e: + print(e) + +``` + +## Vault APIs + +The vault python module is used to perform operations on the vault such as inserting records, detokenizing tokens, retrieving tokens for a skyflow_id and to invoke a connection. -#Initializing a Skyflow Client instance with a SkyflowConfiguration object -config = Configuration('', '', token_provider) -client = Client(config) +To use this module, the skyflow client must first be initialized as follows. + +```python +from skyflow import Env +from skyflow import Skyflow, LogLevel + +# To generate Bearer Token from credentials string. +skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' + +# Pass one of api_key, token, credentials_string & path as credentials +credentials = { + "token": "BEARER_TOKEN", # bearer token + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: skyflow_credentials_string, # credentials as string +} + +client = ( + Skyflow.builder() + .add_vault_config({ + "vault_id": "VAULT_ID", # primary vault + "cluster_id": "CLUSTER_ID", # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + "env": Env.PROD, # Env by default it is set to PROD + "credentials": credentials # individual credentials + }) + .add_skyflow_credentials(credentials) # skyflow credentials will be used if no individual credentials are passed + .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR + .build() +) ``` All Vault APIs must be invoked using a client instance. ### Insert data into the vault -To insert data into your vault use the `insert(records: dict, options: InsertOptions)` method. The `records` parameter is a dictionary that requires a `records` key and takes an array of records to insert into the vault. The `options` parameter takes a dictionary of optional parameters for the insertion. This includes an option to return tokenized data, upsert records and continue on error. +To insert data into your vault, use the `insert` method. The `InsertRequest` class is used to create an insert request, which contains the data to be inserted in the form of a dictionary of records. Additionally, you can provide options in the insert request, such as returning tokenized data, upserting records, and continuing on error. +Insert call schema ```python -# Optional, indicates whether you return tokens for inserted data. Defaults to 'true'. -tokens: bool -# Optional, indicates Upsert support in the vault. -upsert: [UpsertOption] -# Optional, decides whether to continue if error encountered or not -continueOnError: bool +#Initialize Client +from skyflow.vault.data import InsertRequest + +try: + insert_data = [ + {"": ''}, + {"": ''} + ] + + + insert_request = InsertRequest( + table_name='', + values=insert_data, + ) + + response = skyflow_client.vault('VAULT_ID').insert(insert_request) + print("Response:", response) +except SkyflowError as e: + print("Error Occurred:", e) ``` -Insert call schema +**Insert call [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/insert_records.py)** + ```python -from skyflow.vault import InsertOptions, UpsertOption -from skyflow.errors import SkyflowError +from skyflow.vault.data import InsertRequest -#Initialize Client try: - # Create an Upsert option. - upsertOption = UpsertOption(table="",column="") - options = InsertOptions(tokens=True, upsert=[upsertOption], continueOnError=False) + insert_data = [ + {"card_number": '4111111111111111'}, + ] - data = { - "records": [ - { - "table": "", - "fields": { - "": "" - } - } - ] - } - response = client.insert(data, options=options) + insert_request = InsertRequest( + table_name='table1', + values=insert_data, + return_tokens=True # returns tokens + ) + + response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').insert(insert_request) print("Response:", response) except SkyflowError as e: print("Error Occurred:", e) + ``` -**Insert call [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/insert_sample.py)** +Skyflow returns tokens for the record you just inserted. ```python -client.insert( - { - "records": [ +InsertResponse( + inserted_fields= + [ { - "table": "cards", - "fields": { - "cardNumber": "41111111111", - "cvv": "123", - }, + 'skyflow_id': 'a8f3ed5d-55eb-4f32-bf7e-2dbf4b9d9097', + 'card_number': '5479-4229-4622-1393' } - ] - }, - InsertOptions(True), + ], + error=[] ) ``` -Skyflow returns tokens for the record you just inserted. +**Insert call example with `continue_on_error` option** -```json -{ - "records": [ - { - "table": "cards", - "fields": { - "cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1", - "cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5", - "skyflow_id": "d863633c-8c75-44fc-b2ed-2b58162d1117" - }, - "request_index": 0 - } +```python +from skyflow.vault.data import InsertRequest + +try: + insert_data = [ + {"card_number": '4111111111111111'}, + {"card_numbe": '4111111111111111'}, # Intentional typo ] -} + + insert_request = InsertRequest( + table_name='table1', + values=insert_data, + return_tokens=True, # returns tokens + continue_on_error=True + ) + + response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').insert(insert_request) + print("Response:", response) +except SkyflowError as e: + print("Error Occurred:", e) + ``` -**Insert call [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/insert_with_continue_on_error_sample.py) with `continueOnError` option** +Sample Response ```python -client.insert( - { - "records": [ +InsertResponse( + inserted_fields= + [ { - "table": "cards", - "fields": { - "card_number": "4111111111111111", - "full_name": "john doe" - } - }, - { - "table": "pii_field", - "fields": { - "card_number": "4242424242424200" - "full_name": "jane doe" - } + 'skyflow_id': '89c125d1-3bec-4360-b701-a032dda16500', + 'request_index': 0, + 'card_number': '5479-4229-4622-1393' } + ], + error= + [ + { + 'request_index': 1, + 'error': 'Insert failed. Column card_numbe is invalid. Specify a valid column.'} ] - }, InsertOptions(tokens=True, continueOnError=True) ) + ``` -Sample Response +**Insert call example with `upsert` options** -```json -{ - "records": [ - { - "table": "cards", - "fields": { - "card_number": "f37186-e7e2-466f-91e5-48e2bcbc1", - "full_name": "1989cb56-63a-4482-adf-1f74cd1a5", - "skyflow_id": "3daf1a7f-bc7f-4fc9-8c56-a6e4e93231e6" - }, - "request_index": 0 - } - ], - "errors": [ - { - "error": { - "code": 404, - "description": "Object Name pii_field was not found for Vault - requestId : af4aad11-f276-474d-b626-c75c8b35d49e", - "request_index": 1 - } - } - ] -} +```python +from skyflow.vault.data import InsertRequest + +try: + insert_data = [ + {"name": 'sample name'}, + ] + + insert_request = InsertRequest( + table_name='table1', + values=insert_data, + return_tokens=True, # returns tokens + upsert="name" # unique column name + ) + response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').insert(insert_request) + print("Response:", response) +except SkyflowError as e: + print("Error Occurred:", e) ``` -**Insert call [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/insert_upsert_sample.py) with `upsert` options** +Skyflow returns tokens, with `upsert` support, for the record you just inserted. ```python -upsertOption = UpsertOption(table="cards",column="cardNumber") -client.insert( - { - "records": [ +InsertResponse( + inserted_fields= + [ { - "table": "cards", - "fields": { - "cardNumber": "41111111111", - "cvv": "123", - }, + 'skyflow_id': 'a8f3ed5d-55eb-4f32-bf7e-2dbf4b9d9097', + 'name': '3f27b3d7-6bf0-432a-acf9-789c0470e2da' } - ] - }, - InsertOptions(tokens=True,upsert=[upsertOption]), + ], + error=[] ) ``` -Skyflow returns tokens, with `upsert` support, for the record you just inserted. - -```json -{ - "records": [ - { - "table": "cards", - "fields": { - "cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1", - "cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5", - "skyflow_id": "60b32788-12ec-4dd7-9da5-0146c3afbe11" - }, - "request_index": 0 - } - ] -} -``` - ### Detokenize -To retrieve tokens from your vault, you can use the `Detokenize(records: dict, options: DetokenizeOptions)` method.The records parameter takes a dictionary that contains the `records` key that takes an array of records to return. The options parameter is a `DetokenizeOptions` object that provides further options, including `continueOnError` operation, for your detokenize call, as shown below: +To retrieve tokens from your vault, you can use the `detokenize` method. The `DetokenizeRequest` class requires a list of detokenization data to be provided as input. Additionally, the redaction type and continue on error are optional parameters. ```python -{ - "records":[ - { - "token": str , # Token for the record to fetch - "redaction": Skyflow.RedactionType # Optional. Redaction to apply for retrieved data. E.g. RedactionType.MASKED - } - ] -} +from skyflow.vault.tokens import DetokenizeRequest + +try: + detokenize_data = ["", "", ""] + + detokenize_request = DetokenizeRequest( + tokens=detokenize_data, + continue_on_error=False, # optional + redaction_type='plain-text' # optional + ) + + response = skyflow_client.vault('').detokenize(detokenize_request) + print("Response:", response) +except SkyflowError as e: + print("Error Occurred:", e) + ``` Notes: -- `redaction` defaults to [RedactionType.PLAIN_TEXT](#redaction-types). -- `continueOnError` in DetokenizeOptions will default to `True`. +- `redaction` defaults to `plain-text`. +- `continue_on_error` default valus is `False`. -An [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/detokenize_sample.py) of a detokenize call: +An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/detokenize_records.py) of a detokenize call: ```python +from skyflow.vault.tokens import DetokenizeRequest + try: - client.detokenize( - { - "records": [ - { - "token": "45012507-f72b-4f5c-9bf9-86b133bae719" - }, - { - "token": '1r434532-6f76-4319-bdd3-96281e051051', - "redaction": Skyflow.RedactionType.MASKED - }, - { - "token": "invalid-token" - } - ] - } + detokenize_data = ["9738-1683-0486-1480", "6184-6357-8409-6668", "4914-9088-2814-3840"] + + detokenize_request = DetokenizeRequest( + tokens=detokenize_data, + continue_on_error=False, # optional + redaction_type='plain-text' # optional ) + + response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').detokenize(detokenize_request) + print("Response:", response) except SkyflowError as e: - if e.data: - print(e.data) # see note below - else: - print(e) + print("Error Occurred:", e) + ``` Sample response: ```python -{ - "records": [ - { - "token": "131e70dc-6f76-4319-bdd3-96281e051051", - "value": "1990-01-01" - }, - { - "token": "1r434532-6f76-4319-bdd3-96281e051051", - "value": "xxxxxxer", - } - ], - "errors": [ - { - "token": "invalid-token", - "error": { - "code": 404, - "description": "Tokens not found for invalid-token" - } - } - ] -} +DetokenizeResponse( + detokenized_fields=[ + {'token': '9738-1683-0486-1480', 'value': '4111111111111115', 'type': 'STRING'}, + {'token': '6184-6357-8409-6668', 'value': '4111111111111119', 'type': 'STRING'}, + {'token': '4914-9088-2814-3840', 'value': '4111111111111118', 'type': 'STRING'} + ], + errors=[] +) ``` -An [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/detokenize_with_continue_on_error_sample.py) of a detokenize call with continueOnError: +An example of a detokenize call with continue_on_error: ```python +from skyflow.vault.tokens import DetokenizeRequest + try: - client.detokenize( - { - "records": [ - { - "token": "45012507-f72b-4f5c-9bf9-86b133bae719" - }, - { - "token": '1r434532-6f76-4319-bdd3-96281e051051', - "redaction": Skyflow.RedactionType.MASKED - } - ] - }, DetokenizeOptions(continueOnError=False) + detokenize_data = ["9738-1683-0486-1480", "6184-6357-8409-6668", "4914-9088-2814-384"] + + detokenize_request = DetokenizeRequest( + tokens=detokenize_data, + continue_on_error=True, # optional + redaction_type='plain-text' # optional ) + + response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').detokenize(detokenize_request) + print("Response:", response) except SkyflowError as e: - if e.data: - print(e.data) # see note below - else: - print(e) + print("Error Occurred:", e) + ``` Sample response: ```python -{ - "records": [ - { - "token": "131e70dc-6f76-4319-bdd3-96281e051051", - "value": "1990-01-01" - }, - { - "token": "1r434532-6f76-4319-bdd3-96281e051051", - "value": "xxxxxxer", - } - ] -} +DetokenizeResponse( + detokenized_fields=[ + { + 'token': '9738-1683-0486-1480', + 'value': '4111111111111115', + 'type': 'STRING' + }, + { + 'token': '6184-6357-8409-6668', + 'value': '4111111111111119', + 'type': 'STRING' + } + ], + errors=[ + { + 'token': '4914-9088-2814-384', + 'error': 'Token Not Found' + } + ] +) + ``` ### Get -To retrieve data using Skyflow IDs or unique column values, use the `get(records: dict,options: GetOptions)` method. The `records` parameter takes a Dictionary that contains either an array of Skyflow IDs or a unique column name and values.The second parameter options is a GetOptions object that retrieves tokens of Skyflow IDs. +To retrieve data using Skyflow IDs or unique column values, use the `get` method. The `GetRequest` class is used to create a get request, where you specify parameters such as the table name, redaction type, Skyflow IDs, column names, column values, and return tokens. If Skyflow IDs are provided, column names and column values cannot be used. Similarly, if column names or column values are provided, Skyflow IDs cannot be used. -Note: +```python +from skyflow.vault.data import GetRequest - - You can use either Skyflow IDs or `unique` values to retrieve records. You can't use both at the same time. - - GetOptions parameter applicable only for retrieving tokens using Skyflow ID. - - You can't pass GetOptions along with the redaction type. - - `tokens` defaults to false. +GetRequest( + table = '', + ids = ['SKYFLOW_ID1>', 'SKYFLOW_ID2>'], + return_tokens = True, + redaction_type='plain-text' +) -```python -{ - 'records': [ - { - 'columnName': str, # Name of the unique column. - 'columnValues': [str], # List of unique column values. - 'table': str, # Name of table holding the data. - 'redaction': Skyflow.RedactionType, # Redaction applied to retrieved data. - } - ] -} - or -{ - 'records': [ - { - 'ids': [str], # List of Skyflow IDs. - 'table': str, # Name of table holding the data. - 'redaction': Skyflow.RedactionType, # Redaction applied to retrieved data. - } - ] -} +# or +GetRequest( + table = '', + column_name="", + column_values=['COLUMN_VALUE1>', 'COLUMN_VALUE2>'], + redaction_type='plain-text' +) ``` Sample usage -The following snippet shows how to use the `get()` method. For details, see [get_sample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/get_sample.py), - -```python -from skyflow.vault import RedactionType - -skyflowIDs = ['f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9'] -record = {'ids': skyflowIDs, 'table': 'cards', 'redaction':RedactionType.PLAIN_TEXT} -recordsWithUniqueColumn = - { - 'table': 'test_table', - 'columnName': 'card_number', - 'columnValues': ['123456'], - 'redaction': RedactionType.PLAIN_TEXT - } - -invalidID = ['invalid skyflow ID'] -badRecord = {'ids': invalidID, 'table': 'cards', 'redaction': RedactionType.PLAIN_TEXT} - -records = {'records': [record, badRecord]} - -try: - client.get(records) -except SkyflowError as e: - if e.data: - print(e.data) - else: - print(e) -``` - -Sample response: +The following snippet shows how to use the `get` method. For details, see [get_column_values.py](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/get_column_values.py), ```python -{ - 'records': [ - { - 'fields': { - 'card_number': '4111111111111111', - 'cvv': '127', - 'expiry_date': '11/35', - 'fullname': 'monica', - 'skyflow_id': 'f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9' - }, - 'table': 'cards' - }, - { - 'fields': { - 'card_number': '123456', - 'cvv': '317', - 'expiry_date': '10/23', - 'fullname': 'sam', - 'skyflow_id': 'da26de53-95d5-4bdb-99db-8d8c66a35ff9' - }, - 'table': 'cards' - } - ], - 'errors': [ - { - 'error': { - 'code': '404', - 'description': 'No Records Found' - }, - 'skyflow_ids': ['invalid skyflow id'] - } - ] -} -``` +from skyflow.vault.data import GetRequest -The following snippet shows how to use the `get()` method with GetOptions. +try: + column_values = [ + '123456' + ] -```python -from skyflow.vault import GetOptions + get_request = GetRequest( + table='table1', + column_name="card_number", + column_values=column_values, + redaction_type='plain-text' + ) -{ - 'records': [ - { - 'ids': ['56513264-fc45-41fa-9cb0-d1ad3602bc49','da26de53-95d5-4bdb-99db-8d8c66a35ff9'], - 'table': 'cards', - } - ] -} - -try: - client.get(records, GetOptions(True)) + response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').get(get_request) + print("Response:", response) except SkyflowError as e: - if e.data: - print(e.data) - else: - print(e) + print("Error Occurred:", e) + ``` Sample response: ```python -{ - 'records': [ - { - 'fields': { - 'card_number': '4555-5176-5936-1930', - 'cvv': '6ad5f708-2061-453e-9491-618a1f29a688', - 'skyflow_id': '56513264-fc45-41fa-9cb0-d1ad3602bc49' - }, - 'table': 'cards' - }, - { - 'fields': { - 'card_number': '8882-7418-2776-6660', - 'cvv': '25260679-e339-4b33-a5b0-c8b08df77af7', - 'skyflow_id': 'da26de53-95d5-4bdb-99db-8d8c66a35ff9' - }, - 'table': 'cards' - } - ], - 'errors': [] -} +GetResponse( + data=[ + { + 'card_number': '123456', + 'skyflow_id': '4f7af9f9-09e0-4f47-af8e-04c9b1ee1968' + } + ], + error=[] +) + ``` -### Get By Id +### Get By Skyflow Ids -For retrieving using SkyflowID's, use the get_by_id(records: dict) method. The records parameter takes a Dictionary that contains records to be fetched as shown below: ```python -{ - "records": [ - { - "ids": [str], # List of SkyflowID's of the records to be fetched - "table": str, # name of table holding the above skyflow_id's - "redaction": Skyflow.RedactionType, # redaction to be applied to retrieved data - } - ] -} +from skyflow.vault.data import GetRequest + +GetRequest( + table = '', + ids = ['SKYFLOW_ID1>', 'SKYFLOW_ID2>'], + return_tokens = True, + redaction_type='plain-text' +) ``` #### Redaction Types @@ -603,245 +681,238 @@ There are 4 accepted values in Skyflow.RedactionTypes: - `REDACTED` - `DEFAULT` -An [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/get_by_ids_sample.py) of get_by_id call: +An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/get_records.py) of get by skyflow ids call: ```python -from skyflow.vault import RedactionType +from skyflow.vault.data import GetRequest -skyflowIDs = [ - "f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9", - "da26de53-95d5-4bdb-99db-8d8c66a35ff9" -] -record = {"ids": skyflowIDs, "table": "cards", "redaction": RedactionType.PLAIN_TEXT} +try: + get_request = GetRequest( + table='table1', + ids=["aea64577-12b1-4682-aad5-a183194c3f3d", "b385c565-86eb-4af2-b959-8376f9b0754b"], + redaction_type="plain-text" + ) -invalidID = ["invalid skyflow ID"] -badRecord = {"ids": invalidID, "table": "cards", "redaction": RedactionType.PLAIN_TEXT} + response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').get(get_request) + print("Response:", response) +except SkyflowError as e: + print("Error Occurred:", e) -records = {"records": [record, badRecord]} -try: - client.get_by_id(records) -except SkyflowError as e: - if e.data: - print(e.data) # see note below - else: - print(e) ``` Sample response: ```python -{ - "records": [ - { - "fields": { - "card_number": "4111111111111111", - "cvv": "127", - "expiry_date": "11/35", - "fullname": "myname", - "skyflow_id": "f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9" - }, - "table": "cards" - }, - { - "fields": { - "card_number": "4111111111111111", - "cvv": "317", - "expiry_date": "10/23", - "fullname": "sam", - "skyflow_id": "da26de53-95d5-4bdb-99db-8d8c66a35ff9" - }, - "table": "cards" - } - ], - "errors": [ - { - "error": { - "code": "404", - "description": "No Records Found" - }, - "skyflow_ids": ["invalid skyflow id"] - } - ] -} +GetResponse( + data=[ + { + 'card_number': '4555555555555553', + 'skyflow_id': 'aea64577-12b1-4682-aad5-a183194c3f3d' + }, + { + 'card_number': '4555555555555559', + 'skyflow_id': 'b385c565-86eb-4af2-b959-8376f9b0754b' + } + ], + error=[] +) + ``` -`Note:` While using detokenize and get_by_id methods, there is a possibility that some or all of the tokens might be invalid. In such cases, the data from response consists of both errors and detokenized records. In the SDK, this will raise a SkyflowError Exception and you can retrieve the data from this Exception object as shown above. -### Update +The following snippet shows how to use the `get()` method with return_tokens true. -To update data in your vault, use the `update(records: dict, options: UpdateOptions)` method. The `records` parameter takes a Dictionary that contains records to fetch. If `UpdateTokens` is `True`, Skyflow returns tokens for the record you just updated. If `UpdateOptions` is `False`, Skyflow returns IDs for the record you updated. +```python +from skyflow.vault.data import GetRequest + +try: + get_request = GetRequest( + table='table1', + ids=["aea64577-12b1-4682-aad5-a183194c3f3d", "b385c565-86eb-4af2-b959-8376f9b0754b"], + return_tokens=True + ) + + response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').get(get_request) + print("Response:", response) +except SkyflowError as e: + print("Error Occurred:", e) + +``` + +Sample response: ```python -# Optional, indicates whether to return all fields for updated data. Defaults to 'true'. -options: UpdateOptions +GetResponse( + data=[ + { + 'card_number': '3562-0140-8820-7499', + 'skyflow_id': 'aea64577-12b1-4682-aad5-a183194c3f3d' + }, + { + 'card_number': '3998-2139-0328-0697', + 'skyflow_id': 'b385c565-86eb-4af2-b959-8376f9b0754b' + } + ], + error=[] +) ``` +### Update + +To update data in your vault, use the `update` method. The `UpdateRequest` class is used to create an update request, where you specify parameters such as the table name, data (as a dictionary), tokens, return_tokens, and token_strict. If `return_tokens` is set to True, Skyflow returns tokens for the updated records. If `return_tokens` is set to False, Skyflow returns IDs for the updated records. + ```python -{ - 'records': [ - { - 'id': str, # Skyflow ID of the record to be updated. - 'table': str, # Name of table holding the skyflowID. - 'fields': { - str: str # Name of the column and value to update. - } - } - ] -} +from skyflow.vault.data import UpdateRequest + +try: + update_data = { + 'id': '', + '': '' + } + + update_request = UpdateRequest( + table='TABLE_NAME', + data=update_data + ) + + response = skyflow_client.vault('VAULT_ID').update(update_request) + print("Response:", response) +except SkyflowError as e: + print("Error Occurred:", e) ``` Sample usage -The following snippet shows how to use the `update()` method. For details, see [update_sample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/update_sample.py), +The following snippet shows how to use the `update()` method. For details, see [update_record.py](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/update_record.py), ```python -records = { - 'records': [ - { - 'id': '56513264-fc45-41fa-9cb0-d1ad3602bc49', - 'table': 'cards', - 'fields': { - 'card_number': '45678910234' - } - } - ] - } +from skyflow.vault.data import UpdateRequest + try: - client.update(records, UpdateOptions(True)) + update_data = { + 'id': '3b80c76a-c0d7-4c02-be00-b4128cb0f315', + 'card_number': '4111111111117777' + } + + update_request = UpdateRequest( + table='table1', + data=update_data + ) + + response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').update(update_request) + print("Response:", response) except SkyflowError as e: - if e.data: - print(e.data) - else: - print(e) + print("Error Occurred:", e) ``` Sample response -`UpdateOptions` set to `True` +`return_tokens` set to `True` ```python -{ - 'records':[ - { - 'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49', - 'fields':{ - 'card_number':'0051-6502-5704-9879' - } - } - ], - 'errors':[] -} -``` - -`UpdateOptions` set to `False` +UpdateResponse( + updated_field={ + 'skyflow_id': '3b80c76a-c0d7-4c02-be00-b4128cb0f315', + 'card_number': '4131-1751-0217-8491' + }, + error=[] +) -```python -{ - 'records':[ - { - 'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49' - } - ], - 'errors':[] -} ``` -Sample Error +`return_tokens` set to `False` ```python -{ - 'records':[ - { - 'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49' - } - ], - 'errors':[ - { - 'error':{ - 'code':404, - 'description':'Token for skyflowID doesn"t exist in vault - Request ID: a8def196-9569-9cb7-9974-f899f9e4bd0a' - } - } - ] -} +UpdateResponse( + updated_field={'skyflow_id': '3b80c76a-c0d7-4c02-be00-b4128cb0f315'}, + error=[] +) + ``` ### Delete -For deleting using SkyflowID's, use the delete(records: dict) method. The records parameter takes a Dictionary that contains records to be deleted as shown below: +To delete records using Skyflow IDs, use the `delete` method. The `DeleteRequest` class accepts a list of Skyflow IDs that you want to delete, as shown below: ```python -{ - "records": [ - { - "id": str, # SkyflowID of the records to be deleted - "table": str, # name of table holding the above skyflow_id - }, - { - "id": str, # SkyflowID of the records to be deleted - "table": str, # name of table holding the above skyflow_id - } - ] -} +from skyflow.vault.data import DeleteRequest + +primary_delete_ids = [ + 'SKYFLOW_ID1', + 'SKYFLOW_ID2', + 'SKYFLOW_ID3', +] + +delete_request = DeleteRequest( + table='', + ids = primary_delete_ids +) ``` -An [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/delete_sample.py) of delete call: +An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/delete_records.py) of delete call: ```python +from skyflow.vault.data import DeleteRequest -skyflowID = "b3d52e6d-1d6c-4750-ba28-aa30d04dbf01" -record = {"id": skyflowID, "table": "cards"} - -invalidID = "invalid skyflow ID" -badRecord = {"id": invalidID, "table": "cards"} +try: + delete_ids = [ + "77e093f8-3ace-4295-8683-bb6745d6178e", + "bf5989cc-79e8-4b2f-ad71-cb20b0a76091" + ] -records = {"records": [record, badRecord]} + delete_request = DeleteRequest( + table='table1', + ids=delete_ids + ) -try: - client.delete(records) + response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').delete(delete_request) + print("Response:", response) except SkyflowError as e: - if e.data: - print(e.data) # see note below - else: - print(e) + print("Error Occurred:", e) + ``` Sample response: ```python -{ - "records":[ - { - "skyflow_id":"b3d52e6d-1d6c-4750-ba28-aa30d04dbf01", - "deleted":true - } - ], - "errors":[ - { - "id":"invalid skyflow ID", - "error":{ - "code":404, - "description":"No Records Found - request id: 239d462c-aa13-9f9d-a349-165b3dd11217" - } - } - ] -} +DeleteResponse( + deleted_ids=[ + "77e093f8-3ace-4295-8683-bb6745d6178e", + "bf5989cc-79e8-4b2f-ad71-cb20b0a76091" + ], + error=[] +) + ``` ### Invoke Connection -Using Skyflow Connection, end-user applications can integrate checkout/card issuance flow with their apps/systems. To invoke connection, use the invoke_connection(config: Skyflow.ConnectionConfig) method of the Skyflow client. +Using Skyflow Connection, end-user applications can integrate checkout/card issuance flow with their apps/systems. To invoke connection, use the `invoke` method of the Skyflow client. ```python -config = ConnectionConfig( - connectionURL: str, # connection url received when creating a skyflow connection integration - methodName: Skyflow.RequestMethod, - pathParams: dict, # optional - queryParams: dict, # optional - requestHeader: dict, # optional - requestBody: dict, # optional +from skyflow.vault.connection import InvokeConnectionRequest + +body = { + "KEY1": "VALUE1", + "KEY2": "VALUE2" +} +headers = { + "KEY1": "VALUE1" +} +path_params = { + "KEY1": "VALUE1" +} +query_params = { + "KEY1": "VALUE1" +} + +invoke_connection_request = InvokeConnectionRequest( + method=Method.POST, + body=body, + request_headers = headers, # optional + path_params = path_params, # optional + query_params=query_params # optional ) -client.invokeConnection(config) ``` `methodName` supports the following methods: @@ -852,71 +923,80 @@ client.invokeConnection(config) - PATCH - DELETE -**pathParams, queryParams, requestHeader, requestBody** are the JSON objects represented as dictionaries that will be sent through the connection integration url. +**path_params, query_params, request_header, request_body** are the JSON objects represented as dictionaries that will be sent through the connection integration url. -An [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/invoke_connection_sample.py) of invoke_connection: +An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/invoke_connection.py) of invoke_connection: ```python -from skyflow.vault import ConnectionConfig, Configuration, RequestMethod +from skyflow import Skyflow +from skyflow import LogLevel +from skyflow.utils.enums import Method +from skyflow.vault.connection import InvokeConnectionRequest -bearerToken = '' -def token_provider(): - global bearerToken - if !(is_expired(bearerToken)): - return bearerToken - bearerToken, _ = generate_bearer_token('') - return bearerToken +credentials = { + "path": '/home/saib/skyflow/skyflow-python/credentials.json', +} -try: - config = Configuration('', '', token_provider) - connectionConfig = ConnectionConfig('', RequestMethod.POST, - requestHeader={ - 'Content-Type': 'application/json', - 'Authorization': '' - }, - requestBody= # For third party integration - { - "expirationDate": { - "mm": "12", - "yy": "22" - } +client = ( + Skyflow.builder() + .add_connection_config({ + "connection_id": "ef34fc6b0b914ad59a1754c06f10b24c", + "connection_url": "https://sb.area51.gateway.skyflowapis.dev/v1/gateway/inboundRoutes/ef34fc6b0b914ad59a1754c06f10b24c/test", + "credentials": credentials + }) + .set_log_level(LogLevel.OFF) + .build() +) + +invoke_connection_request = InvokeConnectionRequest( + method=Method.POST, + body={ + "card_number": "4337-1696-5866-0865", + "ssn": "524-41-4248" }, - pathParams={'cardID': ''}) # param as in the example - client = Client(config) + request_headers = { + 'Content-Type': 'application/json' + } +) + +response = client.connection('ef34fc6b0b914ad59a1754c06f10b24c').invoke(invoke_connection_request) + +print(response) - response = client.invoke_connection(connectionConfig) - print('Response:', response) -except SkyflowError as e: - print('Error Occurred:', e) ``` Sample response: ```python -{ - "receivedTimestamp": "2021-11-05 13:43:12.534", - "processingTimeinMs": 12, - "resource": { - "cvv2": "558" +ConnectionResponse( + { + 'card_number': '4337-1696-5866-0865', + 'ssn': '524-41-4248', + 'request_id': '84796a11-0b7d-4cb0-a348-cf9fefb5886f,84796a11-0b7d-4cb0-a348-cf9fefb5886f' } -} +) + ``` ### Query -To retrieve data with SQL queries, use the `query(queryInput, options)` method. `queryInput` is an object that takes the `query` parameter as follows: +To retrieve data with SQL queries, use the `query` method. `QueryRequest` is class that takes the `query` parameter as follows: ```python -{ - query: str # SQL query statement -} +from skyflow.vault.data import QueryRequest + +query_request = QueryRequest( + query= "" +) ``` See [Query your data](https://docs.skyflow.com/query-data/) and [Execute Query](https://docs.skyflow.com/record/#QueryService_ExecuteQuery) for guidelines and restrictions on supported SQL statements, operators, and keywords. -An [example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/query_sample.py) of Query call: +An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/query_records.py) of Query call: ```python +from skyflow.vault.data import QueryRequest + queryInput = { query: "SELECT * FROM cards WHERE skyflow_id='3ea3861-x107-40w8-la98-106sp08ea83f'" } @@ -933,37 +1013,48 @@ except SkyflowError as e: Sample Response ```python -{ - "records": [ - { - "fields": { - "card_number": "XXXXXXXXXXXX1111", - "card_pin": "*REDACTED*", - "cvv": "", - "expiration_date": "*REDACTED*", - "expiration_month": "*REDACTED*", - "expiration_year": "*REDACTED*", - "name": "a***te", - "skyflow_id": "3ea3861-x107-40w8-la98-106sp08ea83f", - "ssn": "XXX-XX-6789", - "zip_code": None - }, - "tokens": None - } - ] -} +QueryResponse( + fields=[ + { + "fields": { + "card_number": "XXXXXXXXXXXX1111", + "card_pin": "*REDACTED*", + "cvv": "", + "expiration_date": "*REDACTED*", + "expiration_month": "*REDACTED*", + "expiration_year": "*REDACTED*", + "name": "a***te", + "skyflow_id": "3ea3861-x107-40w8-la98-106sp08ea83f", + "ssn": "XXX-XX-6789", + "zip_code": None + }, + } + ], + error=[] +) ``` ## Logging -The skyflow python SDK provides useful logging using python's inbuilt `logging` library. By default the logging level of the SDK is set to `LogLevel.ERROR`. This can be changed by using `set_log_level(logLevel)` as shown below: +The skyflow python SDK provides useful logging using python's inbuilt `logging` library. By default the logging level of the SDK is set to `LogLevel.ERROR`. This can be changed by using `set_log_level(log_level)` as shown below: ```python -import logging -from skyflow import set_log_level, LogLevel - -logging.basicConfig() # You can set the basic config here -set_log_level(LogLevel.INFO) # sets the skyflow SDK log level to INFO +from skyflow import Skyflow +from skyflow import LogLevel +from skyflow import Env + +client = ( + Skyflow.builder() + .add_vault_config({ + "vault_id": "VAULT_ID", # primary vault + "cluster_id": "CLUSTER_ID", # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + "env": Env.PROD, # Env by default it is set to PROD + "credentials": credentials # individual credentials + }) + .add_skyflow_credentials(credentials) # skyflow credentials will be used if no individual credentials are passed + .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR + .build() +) ``` Current the following 5 log levels are supported: diff --git a/samples/vault_api/credentials_options.py b/samples/vault_api/credentials_options.py index 06108b8..9250571 100644 --- a/samples/vault_api/credentials_options.py +++ b/samples/vault_api/credentials_options.py @@ -6,9 +6,9 @@ credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: "CREDENTIAL_STRING", // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: "CREDENTIAL_STRING", # credentials as string } skyflow_client = ( diff --git a/samples/vault_api/delete_records.py b/samples/vault_api/delete_records.py index b03122a..a82969a 100644 --- a/samples/vault_api/delete_records.py +++ b/samples/vault_api/delete_records.py @@ -10,9 +10,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: "CREDENTIAL_STRING", // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: "CREDENTIAL_STRING", # credentials as string } client = ( diff --git a/samples/vault_api/get_column_values.py b/samples/vault_api/get_column_values.py index 2b0577a..1316f58 100644 --- a/samples/vault_api/get_column_values.py +++ b/samples/vault_api/get_column_values.py @@ -1,7 +1,6 @@ from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.data import GetRequest -from skyflow.vault.tokens import DetokenizeRequest # To generate Bearer Token from credentials string. skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' @@ -9,9 +8,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: skyflow_credentials_string, // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: skyflow_credentials_string, # credentials as string } client = ( diff --git a/samples/vault_api/get_records.py b/samples/vault_api/get_records.py index 0429a7f..b697a23 100644 --- a/samples/vault_api/get_records.py +++ b/samples/vault_api/get_records.py @@ -1,7 +1,6 @@ from skyflow import Env from skyflow import Skyflow, LogLevel from skyflow.vault.data import GetRequest -from skyflow.vault.tokens import DetokenizeRequest # To generate Bearer Token from credentials string. skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' @@ -9,9 +8,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: skyflow_credentials_string, // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: skyflow_credentials_string, # credentials as string } client = ( diff --git a/samples/vault_api/insert_byot.py b/samples/vault_api/insert_byot.py index f0b20eb..abded0e 100644 --- a/samples/vault_api/insert_byot.py +++ b/samples/vault_api/insert_byot.py @@ -2,8 +2,7 @@ from skyflow import Skyflow, LogLevel from skyflow.error import SkyflowError from skyflow.utils.enums import TokenStrict -from skyflow.vault.data import GetRequest, InsertRequest -from skyflow.vault.tokens import DetokenizeRequest +from skyflow.vault.data import InsertRequest # To generate Bearer Token from credentials string. skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' @@ -11,9 +10,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: skyflow_credentials_string, // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: skyflow_credentials_string, # credentials as string } skyflow_client = ( diff --git a/samples/vault_api/insert_records.py b/samples/vault_api/insert_records.py index da8f2a3..a01e39f 100644 --- a/samples/vault_api/insert_records.py +++ b/samples/vault_api/insert_records.py @@ -1,7 +1,6 @@ from skyflow import Env from skyflow import Skyflow, LogLevel -from skyflow.vault.data import GetRequest, InsertRequest -from skyflow.vault.tokens import DetokenizeRequest +from skyflow.vault.data import InsertRequest # To generate Bearer Token from credentials string. skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' @@ -9,9 +8,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: skyflow_credentials_string, // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: skyflow_credentials_string, # credentials as string } skyflow_client = ( diff --git a/samples/vault_api/invoke_connection.py b/samples/vault_api/invoke_connection.py index 84cc76d..51eeded 100644 --- a/samples/vault_api/invoke_connection.py +++ b/samples/vault_api/invoke_connection.py @@ -2,8 +2,6 @@ from skyflow import Skyflow, LogLevel from skyflow.utils.enums import Method from skyflow.vault.connection import InvokeConnectionRequest -from skyflow.vault.data import GetRequest, InsertRequest -from skyflow.vault.tokens import DetokenizeRequest # To generate Bearer Token from credentials string. skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' @@ -11,9 +9,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: skyflow_credentials_string, // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: skyflow_credentials_string, # credentials as string } skyflow_client = ( diff --git a/samples/vault_api/query_records.py b/samples/vault_api/query_records.py index f1449ef..3def104 100644 --- a/samples/vault_api/query_records.py +++ b/samples/vault_api/query_records.py @@ -1,9 +1,6 @@ from skyflow import Env from skyflow import Skyflow, LogLevel -from skyflow.utils.enums import Method -from skyflow.vault.connection import InvokeConnectionRequest -from skyflow.vault.data import GetRequest, InsertRequest, QueryRequest -from skyflow.vault.tokens import DetokenizeRequest +from skyflow.vault.data import QueryRequest # To generate Bearer Token from credentials string. skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' @@ -11,9 +8,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: skyflow_credentials_string, // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: skyflow_credentials_string, # credentials as string } skyflow_client = ( diff --git a/samples/vault_api/tokenize_records.py b/samples/vault_api/tokenize_records.py index 6628716..00582cf 100644 --- a/samples/vault_api/tokenize_records.py +++ b/samples/vault_api/tokenize_records.py @@ -1,9 +1,6 @@ from skyflow import Env from skyflow import Skyflow, LogLevel -from skyflow.utils.enums import Method -from skyflow.vault.connection import InvokeConnectionRequest -from skyflow.vault.data import GetRequest, InsertRequest, QueryRequest -from skyflow.vault.tokens import DetokenizeRequest, TokenizeRequest +from skyflow.vault.tokens import TokenizeRequest # To generate Bearer Token from credentials string. skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' @@ -11,9 +8,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: skyflow_credentials_string, // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: skyflow_credentials_string, # credentials as string } skyflow_client = ( diff --git a/samples/vault_api/update_record.py b/samples/vault_api/update_record.py index 2179abf..59563ed 100644 --- a/samples/vault_api/update_record.py +++ b/samples/vault_api/update_record.py @@ -1,9 +1,6 @@ from skyflow import Env from skyflow import Skyflow, LogLevel -from skyflow.utils.enums import Method -from skyflow.vault.connection import InvokeConnectionRequest -from skyflow.vault.data import GetRequest, InsertRequest, QueryRequest, UpdateRequest -from skyflow.vault.tokens import DetokenizeRequest, TokenizeRequest +from skyflow.vault.data import UpdateRequest # To generate Bearer Token from credentials string. skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' @@ -11,9 +8,9 @@ # please pass one of api_key, token, credentials_string & path as credentials credentials = { "token": "BEARER_TOKEN", # bearer token - # api_key: "API_KEY", //API_KEY - # path: "PATH", //path to credentials file - # credentials_string: skyflow_credentials_string, // credentials as string + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: skyflow_credentials_string, # credentials as string } skyflow_client = ( From bc01ad77980dbe9b0bcd64a88301067a81ee8945 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 20 Nov 2024 14:36:30 +0530 Subject: [PATCH 03/15] SK-1749: Fix linting --- .github/workflows/internal-release.yml | 1 + setup.py | 2 +- skyflow/utils/_version.py | 2 +- skyflow/vault/data/_get_request.py | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml index f14d216..d4ca8ae 100644 --- a/.github/workflows/internal-release.yml +++ b/.github/workflows/internal-release.yml @@ -20,4 +20,5 @@ jobs: ref: ${{ github.ref_name }} is-internal: true secrets: inherit + diff --git a/setup.py b/setup.py index 7f0e9e1..46ae383 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ if sys.version_info < (3, 7): raise RuntimeError("skyflow requires Python 3.7+") -current_version = '1.15.1' +current_version = '1.15.1.dev0+ddb228b' setup( name='skyflow', diff --git a/skyflow/utils/_version.py b/skyflow/utils/_version.py index 551e675..9b42e1f 100644 --- a/skyflow/utils/_version.py +++ b/skyflow/utils/_version.py @@ -1 +1 @@ -SDK_VERSION = "v2" \ No newline at end of file +SDK_VERSION = '1.15.1.dev0+ddb228b' \ No newline at end of file diff --git a/skyflow/vault/data/_get_request.py b/skyflow/vault/data/_get_request.py index a6c57e9..16bb79a 100644 --- a/skyflow/vault/data/_get_request.py +++ b/skyflow/vault/data/_get_request.py @@ -23,3 +23,4 @@ def __init__(self, self.download_url = download_url self.column_name = column_name self.column_values = column_values + From 59e98bea22dcef21346e95706cd42c6301101072 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 20 Nov 2024 14:37:25 +0530 Subject: [PATCH 04/15] SK-1749: Fix linting --- .github/workflows/internal-release.yml | 2 -- skyflow/vault/data/_get_request.py | 1 - 2 files changed, 3 deletions(-) diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml index d4ca8ae..9987a49 100644 --- a/.github/workflows/internal-release.yml +++ b/.github/workflows/internal-release.yml @@ -20,5 +20,3 @@ jobs: ref: ${{ github.ref_name }} is-internal: true secrets: inherit - - diff --git a/skyflow/vault/data/_get_request.py b/skyflow/vault/data/_get_request.py index 16bb79a..a6c57e9 100644 --- a/skyflow/vault/data/_get_request.py +++ b/skyflow/vault/data/_get_request.py @@ -23,4 +23,3 @@ def __init__(self, self.download_url = download_url self.column_name = column_name self.column_values = column_values - From f426bfc0e8a35a4ec76637f2bc4aead5e3ae678f Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 20 Nov 2024 14:38:02 +0530 Subject: [PATCH 05/15] SK-1749: Fix linting --- .github/workflows/internal-release.yml | 2 +- skyflow/vault/data/_get_request.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml index 9987a49..1ce9ce9 100644 --- a/.github/workflows/internal-release.yml +++ b/.github/workflows/internal-release.yml @@ -19,4 +19,4 @@ jobs: with: ref: ${{ github.ref_name }} is-internal: true - secrets: inherit + secrets: inherit \ No newline at end of file diff --git a/skyflow/vault/data/_get_request.py b/skyflow/vault/data/_get_request.py index a6c57e9..f7238de 100644 --- a/skyflow/vault/data/_get_request.py +++ b/skyflow/vault/data/_get_request.py @@ -22,4 +22,4 @@ def __init__(self, self.limit = limit self.download_url = download_url self.column_name = column_name - self.column_values = column_values + self.column_values = column_values \ No newline at end of file From cae05783c59af5d98e03f5bb073aa66dff37afe8 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 20 Nov 2024 14:41:44 +0530 Subject: [PATCH 06/15] SK-1749: Fix linting --- .github/workflows/internal-release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml index 1ce9ce9..d4ad940 100644 --- a/.github/workflows/internal-release.yml +++ b/.github/workflows/internal-release.yml @@ -19,4 +19,5 @@ jobs: with: ref: ${{ github.ref_name }} is-internal: true - secrets: inherit \ No newline at end of file + secrets: inherit + \ No newline at end of file From 190bf2c77403ec6bd77681f1f920628ec78c8009 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 20 Nov 2024 17:04:18 +0530 Subject: [PATCH 07/15] SK-1749: Updated README --- README.md | 311 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 210 insertions(+), 101 deletions(-) diff --git a/README.md b/README.md index 24cf7e9..2080f5c 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,8 @@ def token_provider(): try: bearer_token, token_type = token_provider() - print("Access Token:", bearer_token) - print("Type of token:", token_type) + print('Access Token:', bearer_token) + print('Type of token:', token_type) except SkyflowError as e: print(e) @@ -97,15 +97,23 @@ def token_provider(): global bearer_token global token_type # As an example - skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' + skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', + } + credentials_string = json.dumps(skyflow_credentials) + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string) return bearer_token, token_type try: bearer_token, token_type = token_provider() - print("Access Token:", bearer_token) - print("Type of token:", token_type) + print('Access Token:', bearer_token) + print('Type of token:', token_type) except SkyflowError as e: print(e) @@ -123,7 +131,7 @@ from skyflow.service_account import generate_bearer_token, is_expired bearer_token = '' token_type = '' options = { - "role_ids": ["ROLE_ID1", "ROLE_ID2"] + 'role_ids': ['ROLE_ID1', 'ROLE_ID2'] } def token_provider(): global bearer_token @@ -135,8 +143,8 @@ def token_provider(): try: bearer_token, token_type = token_provider() - print("Access Token:", bearer_token) - print("Type of token:", token_type) + print('Access Token:', bearer_token) + print('Type of token:', token_type) except SkyflowError as e: print(e) @@ -153,21 +161,29 @@ from skyflow.service_account import generate_bearer_token, generate_bearer_token bearer_token = '' token_type = '' options = { - "role_ids": ["ROLE_ID1", "ROLE_ID2"] + 'role_ids': ['ROLE_ID1', 'ROLE_ID2'] } def token_provider(): global bearer_token global token_type # As an example - skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' + skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', + } + credentials_string = json.dumps(skyflow_credentials) + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options) return bearer_token, token_type try: bearer_token, token_type = token_provider() - print("Access Token:", bearer_token) - print("Type of token:", token_type) + print('Access Token:', bearer_token) + print('Type of token:', token_type) except SkyflowError as e: print(e) @@ -185,7 +201,7 @@ from skyflow.service_account import generate_bearer_token, is_expired bearer_token = '' token_type = '' options = { - "ctx": "" + 'ctx': "" } def token_provider(): global bearer_token @@ -197,8 +213,8 @@ def token_provider(): try: bearer_token, token_type = token_provider() - print("Access Token:", bearer_token) - print("Type of token:", token_type) + print('Access Token:', bearer_token) + print('Type of token:', token_type) except SkyflowError as e: print(e) @@ -215,21 +231,29 @@ from skyflow.service_account import generate_bearer_token, generate_bearer_token bearer_token = '' token_type = '' options = { - "ctx": "" + 'ctx': '' } def token_provider(): global bearer_token global token_type # As an example - skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' + skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', + } + credentials_string = json.dumps(skyflow_credentials) + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options) return bearer_token, token_type try: bearer_token, token_type = token_provider() - print("Access Token:", bearer_token) - print("Type of token:", token_type) + print('Access Token:', bearer_token) + print('Type of token:', token_type) except SkyflowError as e: print(e) @@ -247,9 +271,9 @@ from skyflow.service_account import generate_bearer_token, is_expired bearer_token = '' token_type = '' options = { - "ctx": "CONTEX_ID", - "data_tokens": ["DATA_TOKEN1", "DATA_TOKEN2"], - "time_to_live": 90 # in seconds + 'ctx': 'CONTEX_ID', + 'data_tokens': ['DATA_TOKEN1', 'DATA_TOKEN2'], + 'time_to_live': 90 # in seconds } def token_provider(): global bearer_token @@ -261,8 +285,8 @@ def token_provider(): try: bearer_token, token_type = token_provider() - print("Access Token:", bearer_token) - print("Type of token:", token_type) + print('Access Token:', bearer_token) + print('Type of token:', token_type) except SkyflowError as e: print(e) @@ -279,26 +303,33 @@ from skyflow.service_account import generate_bearer_token, generate_bearer_token bearer_token = '' token_type = '' options = { - "ctx": "CONTEX_ID", - "data_tokens": ["DATA_TOKEN1", "DATA_TOKEN2"], - "time_to_live": 90 # in seconds + 'ctx': 'CONTEX_ID', + 'data_tokens': ['DATA_TOKEN1', 'DATA_TOKEN2'], + 'time_to_live': 90 # in seconds } def token_provider(): global bearer_token global token_type # As an example - skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' + skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', + } + credentials_string = json.dumps(skyflow_credentials) + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options) return bearer_token, token_type try: bearer_token, token_type = token_provider() - print("Access Token:", bearer_token) - print("Type of token:", token_type) + print('Access Token:', bearer_token) + print('Type of token:', token_type) except SkyflowError as e: print(e) - ``` ## Vault APIs @@ -312,45 +343,56 @@ from skyflow import Env from skyflow import Skyflow, LogLevel # To generate Bearer Token from credentials string. -skyflow_credentials_string = '{"clientID":"","clientName":"","tokenURI":"","keyID":"","privateKey":""}' +skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', + } +credentials_string = json.dumps(skyflow_credentials) # Pass one of api_key, token, credentials_string & path as credentials credentials = { - "token": "BEARER_TOKEN", # bearer token + 'token': 'BEARER_TOKEN', # bearer token # api_key: "API_KEY", # API_KEY # path: "PATH", # path to credentials file - # credentials_string: skyflow_credentials_string, # credentials as string + # credentials_string: credentials_string, # credentials as string } client = ( Skyflow.builder() .add_vault_config({ - "vault_id": "VAULT_ID", # primary vault - "cluster_id": "CLUSTER_ID", # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - "env": Env.PROD, # Env by default it is set to PROD - "credentials": credentials # individual credentials + 'vault_id': 'VAULT_ID', # primary vault + 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + 'env': Env.PROD, # Env by default it is set to PROD + 'credentials': credentials # individual credentials }) .add_skyflow_credentials(credentials) # skyflow credentials will be used if no individual credentials are passed .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR .build() ) ``` +Notes: +- If both Skyflow common credentials and individual credentials at the configuration level are provided, the individual credentials at the configuration level will take priority. + All Vault APIs must be invoked using a client instance. ### Insert data into the vault -To insert data into your vault, use the `insert` method. The `InsertRequest` class is used to create an insert request, which contains the data to be inserted in the form of a dictionary of records. Additionally, you can provide options in the insert request, such as returning tokenized data, upserting records, and continuing on error. +To insert data into your vault, use the `insert` method. The `InsertRequest` class is used to create an insert request, which contains the values to be inserted in the form of a dictionary of records. Additionally, you can provide options in the insert request, such as returning tokenized data, upserting records, and continuing on error. Insert call schema ```python #Initialize Client +from skyflow.error import SkyflowError from skyflow.vault.data import InsertRequest try: insert_data = [ - {"": ''}, - {"": ''} + {'': ''}, + {'': ''} ] @@ -360,19 +402,20 @@ try: ) response = skyflow_client.vault('VAULT_ID').insert(insert_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` **Insert call [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/insert_records.py)** ```python +from skyflow.error import SkyflowError from skyflow.vault.data import InsertRequest try: insert_data = [ - {"card_number": '4111111111111111'}, + {'card_number': '4111111111111111'}, ] insert_request = InsertRequest( @@ -396,7 +439,7 @@ InsertResponse( [ { 'skyflow_id': 'a8f3ed5d-55eb-4f32-bf7e-2dbf4b9d9097', - 'card_number': '5479-4229-4622-1393' + 'card_number': '5479-4229-4622-1393' } ], error=[] @@ -406,12 +449,13 @@ InsertResponse( **Insert call example with `continue_on_error` option** ```python +from skyflow.error import SkyflowError from skyflow.vault.data import InsertRequest try: insert_data = [ - {"card_number": '4111111111111111'}, - {"card_numbe": '4111111111111111'}, # Intentional typo + {'card_number': '4111111111111111'}, + {'card_numbe': '4111111111111111'}, # Intentional typo card_numbe ] insert_request = InsertRequest( @@ -422,9 +466,9 @@ try: ) response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').insert(insert_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` @@ -453,6 +497,7 @@ InsertResponse( **Insert call example with `upsert` options** ```python +from skyflow.error import SkyflowError from skyflow.vault.data import InsertRequest try: @@ -468,9 +513,9 @@ try: ) response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').insert(insert_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` Skyflow returns tokens, with `upsert` support, for the record you just inserted. @@ -493,10 +538,11 @@ InsertResponse( To retrieve tokens from your vault, you can use the `detokenize` method. The `DetokenizeRequest` class requires a list of detokenization data to be provided as input. Additionally, the redaction type and continue on error are optional parameters. ```python +from skyflow.error import SkyflowError from skyflow.vault.tokens import DetokenizeRequest try: - detokenize_data = ["", "", ""] + detokenize_data = ['', '', ''] detokenize_request = DetokenizeRequest( tokens=detokenize_data, @@ -505,9 +551,9 @@ try: ) response = skyflow_client.vault('').detokenize(detokenize_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` Notes: @@ -517,10 +563,11 @@ Notes: An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/detokenize_records.py) of a detokenize call: ```python +from skyflow.error import SkyflowError from skyflow.vault.tokens import DetokenizeRequest try: - detokenize_data = ["9738-1683-0486-1480", "6184-6357-8409-6668", "4914-9088-2814-3840"] + detokenize_data = ['9738-1683-0486-1480', '6184-6357-8409-6668', '4914-9088-2814-3840'] detokenize_request = DetokenizeRequest( tokens=detokenize_data, @@ -529,9 +576,9 @@ try: ) response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').detokenize(detokenize_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` @@ -551,10 +598,11 @@ DetokenizeResponse( An example of a detokenize call with continue_on_error: ```python +from skyflow.error import SkyflowError from skyflow.vault.tokens import DetokenizeRequest try: - detokenize_data = ["9738-1683-0486-1480", "6184-6357-8409-6668", "4914-9088-2814-384"] + detokenize_data = ['9738-1683-0486-1480', '6184-6357-8409-6668', '4914-9088-2814-384'] detokenize_request = DetokenizeRequest( tokens=detokenize_data, @@ -563,9 +611,9 @@ try: ) response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').detokenize(detokenize_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` @@ -595,11 +643,62 @@ DetokenizeResponse( ``` +### Tokenize + +To tokenize data, use the `tokenize` method. The `TokenizeRequest` class is utilized to create a tokenize request. In this request, you specify the `tokenize_parameters` parameter, which is a list of dictionaries. Each dictionary contains two keys: `value` and `column_group`. + +```python +from skyflow.vault.tokens import TokenizeRequest + +tokenize_request = TokenizeRequest( + tokenize_parameters=[{ + 'value': '', + 'column_group': '' + }] +) +``` + +Sample usage + +An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/tokenize_records.py) of a tokenize call: + +```python +from skyflow.error import SkyflowError +from skyflow.vault.tokens import TokenizeRequest + +try: + tokenize_request = TokenizeRequest( + tokenize_parameters=[{ + "value": '4111111111111111', + "column_group": "card_number_cg" + }] + ) + + response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').tokenize(tokenize_request) + print(response) +except SyntaxError as e: + print('Error Occurred: ', e) +``` + +Sample response: + +```python +TokenizeResponse( + tokenized_fields=[ + { + 'token': '5479-4229-4622-1393' + } + ] +) + +``` + ### Get To retrieve data using Skyflow IDs or unique column values, use the `get` method. The `GetRequest` class is used to create a get request, where you specify parameters such as the table name, redaction type, Skyflow IDs, column names, column values, and return tokens. If Skyflow IDs are provided, column names and column values cannot be used. Similarly, if column names or column values are provided, Skyflow IDs cannot be used. ```python +from skyflow.error import SkyflowError from skyflow.vault.data import GetRequest GetRequest( @@ -613,16 +712,19 @@ GetRequest( GetRequest( table = '', - column_name="", + column_name='', column_values=['COLUMN_VALUE1>', 'COLUMN_VALUE2>'], redaction_type='plain-text' ) ``` Sample usage -The following snippet shows how to use the `get` method. For details, see [get_column_values.py](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/get_column_values.py), +### Get By Column Name and Column Values + +The following snippet shows how to use the `get` method using column names and column values. For details, see [get_column_values.py](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/get_column_values.py), ```python +from skyflow.error import SkyflowError from skyflow.vault.data import GetRequest try: @@ -632,15 +734,15 @@ try: get_request = GetRequest( table='table1', - column_name="card_number", + column_name="card_number", # It must be configured as unique in the schema. column_values=column_values, redaction_type='plain-text' ) response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').get(get_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` @@ -661,8 +763,8 @@ GetResponse( ### Get By Skyflow Ids - ```python +from skyflow.error import SkyflowError from skyflow.vault.data import GetRequest GetRequest( @@ -684,21 +786,20 @@ There are 4 accepted values in Skyflow.RedactionTypes: An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/get_records.py) of get by skyflow ids call: ```python +from skyflow.error import SkyflowError from skyflow.vault.data import GetRequest try: get_request = GetRequest( table='table1', - ids=["aea64577-12b1-4682-aad5-a183194c3f3d", "b385c565-86eb-4af2-b959-8376f9b0754b"], + ids=['aea64577-12b1-4682-aad5-a183194c3f3d', 'b385c565-86eb-4af2-b959-8376f9b0754b'], redaction_type="plain-text" ) response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').get(get_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) - - + print('Error Occurred:', e) ``` Sample response: @@ -724,19 +825,20 @@ GetResponse( The following snippet shows how to use the `get()` method with return_tokens true. ```python +from skyflow.error import SkyflowError from skyflow.vault.data import GetRequest try: get_request = GetRequest( table='table1', - ids=["aea64577-12b1-4682-aad5-a183194c3f3d", "b385c565-86eb-4af2-b959-8376f9b0754b"], + ids=['aea64577-12b1-4682-aad5-a183194c3f3d', 'b385c565-86eb-4af2-b959-8376f9b0754b'], return_tokens=True ) response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').get(get_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` @@ -763,6 +865,7 @@ GetResponse( To update data in your vault, use the `update` method. The `UpdateRequest` class is used to create an update request, where you specify parameters such as the table name, data (as a dictionary), tokens, return_tokens, and token_strict. If `return_tokens` is set to True, Skyflow returns tokens for the updated records. If `return_tokens` is set to False, Skyflow returns IDs for the updated records. ```python +from skyflow.error import SkyflowError from skyflow.vault.data import UpdateRequest try: @@ -777,15 +880,16 @@ try: ) response = skyflow_client.vault('VAULT_ID').update(update_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` Sample usage The following snippet shows how to use the `update()` method. For details, see [update_record.py](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/update_record.py), ```python +from skyflow.error import SkyflowError from skyflow.vault.data import UpdateRequest try: @@ -800,9 +904,9 @@ try: ) response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').update(update_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` Sample response @@ -835,6 +939,7 @@ UpdateResponse( To delete records using Skyflow IDs, use the `delete` method. The `DeleteRequest` class accepts a list of Skyflow IDs that you want to delete, as shown below: ```python +from skyflow.error import SkyflowError from skyflow.vault.data import DeleteRequest primary_delete_ids = [ @@ -852,12 +957,13 @@ delete_request = DeleteRequest( An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/delete_records.py) of delete call: ```python +from skyflow.error import SkyflowError from skyflow.vault.data import DeleteRequest try: delete_ids = [ - "77e093f8-3ace-4295-8683-bb6745d6178e", - "bf5989cc-79e8-4b2f-ad71-cb20b0a76091" + '77e093f8-3ace-4295-8683-bb6745d6178e', + 'bf5989cc-79e8-4b2f-ad71-cb20b0a76091' ] delete_request = DeleteRequest( @@ -866,9 +972,9 @@ try: ) response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').delete(delete_request) - print("Response:", response) + print('Response:', response) except SkyflowError as e: - print("Error Occurred:", e) + print('Error Occurred:', e) ``` @@ -877,8 +983,8 @@ Sample response: ```python DeleteResponse( deleted_ids=[ - "77e093f8-3ace-4295-8683-bb6745d6178e", - "bf5989cc-79e8-4b2f-ad71-cb20b0a76091" + '77e093f8-3ace-4295-8683-bb6745d6178e', + 'bf5989cc-79e8-4b2f-ad71-cb20b0a76091' ], error=[] ) @@ -890,20 +996,21 @@ DeleteResponse( Using Skyflow Connection, end-user applications can integrate checkout/card issuance flow with their apps/systems. To invoke connection, use the `invoke` method of the Skyflow client. ```python +from skyflow.error import SkyflowError from skyflow.vault.connection import InvokeConnectionRequest body = { - "KEY1": "VALUE1", - "KEY2": "VALUE2" + 'KEY1': 'VALUE1', + 'KEY2': 'VALUE2' } headers = { - "KEY1": "VALUE1" + 'KEY1': 'VALUE1' } path_params = { - "KEY1": "VALUE1" + 'KEY1': 'VALUE1' } query_params = { - "KEY1": "VALUE1" + 'KEY1': 'VALUE1' } invoke_connection_request = InvokeConnectionRequest( @@ -931,18 +1038,19 @@ An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/sa from skyflow import Skyflow from skyflow import LogLevel from skyflow.utils.enums import Method +from skyflow.error import SkyflowError from skyflow.vault.connection import InvokeConnectionRequest credentials = { - "path": '/home/saib/skyflow/skyflow-python/credentials.json', + 'path': '/path/to/credentials.json', } client = ( Skyflow.builder() .add_connection_config({ - "connection_id": "ef34fc6b0b914ad59a1754c06f10b24c", - "connection_url": "https://sb.area51.gateway.skyflowapis.dev/v1/gateway/inboundRoutes/ef34fc6b0b914ad59a1754c06f10b24c/test", - "credentials": credentials + 'connection_id': '', + 'connection_url': '', + 'credentials': credentials }) .set_log_level(LogLevel.OFF) .build() @@ -951,15 +1059,15 @@ client = ( invoke_connection_request = InvokeConnectionRequest( method=Method.POST, body={ - "card_number": "4337-1696-5866-0865", - "ssn": "524-41-4248" + 'card_number': '4337-1696-5866-0865', + 'ssn': '524-41-4248' }, request_headers = { 'Content-Type': 'application/json' } ) -response = client.connection('ef34fc6b0b914ad59a1754c06f10b24c').invoke(invoke_connection_request) +response = client.connection('').invoke(invoke_connection_request) print(response) @@ -986,7 +1094,7 @@ To retrieve data with SQL queries, use the `query` method. `QueryRequest` is cla from skyflow.vault.data import QueryRequest query_request = QueryRequest( - query= "" + query= '' ) ``` @@ -995,6 +1103,7 @@ See [Query your data](https://docs.skyflow.com/query-data/) and [Execute Query]( An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/query_records.py) of Query call: ```python +from skyflow.error import SkyflowError from skyflow.vault.data import QueryRequest queryInput = { @@ -1046,10 +1155,10 @@ from skyflow import Env client = ( Skyflow.builder() .add_vault_config({ - "vault_id": "VAULT_ID", # primary vault - "cluster_id": "CLUSTER_ID", # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com - "env": Env.PROD, # Env by default it is set to PROD - "credentials": credentials # individual credentials + 'vault_id': 'VAULT_ID', # primary vault + 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com + 'env': Env.PROD, # Env by default it is set to PROD + 'credentials': "" # individual credentials }) .add_skyflow_credentials(credentials) # skyflow credentials will be used if no individual credentials are passed .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR From 820337919775b67d5d46e9f1c265347be6fd20bc Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 20 Nov 2024 18:48:05 +0530 Subject: [PATCH 08/15] SK-1749: Added placeholder for vault id --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2080f5c..c712d16 100644 --- a/README.md +++ b/README.md @@ -424,7 +424,7 @@ try: return_tokens=True # returns tokens ) - response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').insert(insert_request) + response = client.vault('').insert(insert_request) print("Response:", response) except SkyflowError as e: print("Error Occurred:", e) @@ -465,7 +465,7 @@ try: continue_on_error=True ) - response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').insert(insert_request) + response = client.vault('').insert(insert_request) print('Response:', response) except SkyflowError as e: print('Error Occurred:', e) @@ -512,7 +512,7 @@ try: upsert="name" # unique column name ) - response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').insert(insert_request) + response = client.vault('').insert(insert_request) print('Response:', response) except SkyflowError as e: print('Error Occurred:', e) @@ -575,7 +575,7 @@ try: redaction_type='plain-text' # optional ) - response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').detokenize(detokenize_request) + response = skyflow_client.vault('').detokenize(detokenize_request) print('Response:', response) except SkyflowError as e: print('Error Occurred:', e) @@ -610,7 +610,7 @@ try: redaction_type='plain-text' # optional ) - response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').detokenize(detokenize_request) + response = skyflow_client.vault('').detokenize(detokenize_request) print('Response:', response) except SkyflowError as e: print('Error Occurred:', e) @@ -674,7 +674,7 @@ try: }] ) - response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').tokenize(tokenize_request) + response = client.vault('').tokenize(tokenize_request) print(response) except SyntaxError as e: print('Error Occurred: ', e) @@ -739,7 +739,7 @@ try: redaction_type='plain-text' ) - response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').get(get_request) + response = skyflow_client.vault('').get(get_request) print('Response:', response) except SkyflowError as e: print('Error Occurred:', e) @@ -796,7 +796,7 @@ try: redaction_type="plain-text" ) - response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').get(get_request) + response = client.vault('').get(get_request) print('Response:', response) except SkyflowError as e: print('Error Occurred:', e) @@ -835,7 +835,7 @@ try: return_tokens=True ) - response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').get(get_request) + response = client.vault('').get(get_request) print('Response:', response) except SkyflowError as e: print('Error Occurred:', e) @@ -903,7 +903,7 @@ try: data=update_data ) - response = skyflow_client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').update(update_request) + response = skyflow_client.vault('').update(update_request) print('Response:', response) except SkyflowError as e: print('Error Occurred:', e) @@ -971,7 +971,7 @@ try: ids=delete_ids ) - response = client.vault('d3dd9bbb7abc4c779b72f32cb7ee5d14').delete(delete_request) + response = client.vault('').delete(delete_request) print('Response:', response) except SkyflowError as e: print('Error Occurred:', e) @@ -1106,12 +1106,12 @@ An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/sa from skyflow.error import SkyflowError from skyflow.vault.data import QueryRequest -queryInput = { - query: "SELECT * FROM cards WHERE skyflow_id='3ea3861-x107-40w8-la98-106sp08ea83f'" -} +query_request = QueryRequest( + query= "SELECT * FROM cards WHERE skyflow_id='3ea3861-x107-40w8-la98-106sp08ea83f'" +) try: - client.query(queryInput) + skyflow_client.vault('').query(query_request) except SkyflowError as e: if e.data: print(e.data) From 83792c54cb9c4f0ef3ec9b2fe7d44968fd5c872c Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 20 Nov 2024 20:54:14 +0530 Subject: [PATCH 09/15] SK-1749: Updated readme file --- README.md | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c712d16..71a916a 100644 --- a/README.md +++ b/README.md @@ -442,7 +442,7 @@ InsertResponse( 'card_number': '5479-4229-4622-1393' } ], - error=[] + errors=[] ) ``` @@ -484,11 +484,12 @@ InsertResponse( 'card_number': '5479-4229-4622-1393' } ], - error= + errors= [ { 'request_index': 1, - 'error': 'Insert failed. Column card_numbe is invalid. Specify a valid column.'} + 'error': 'Insert failed. Column card_numbe is invalid. Specify a valid column.' + } ] ) @@ -529,7 +530,7 @@ InsertResponse( 'name': '3f27b3d7-6bf0-432a-acf9-789c0470e2da' } ], - error=[] + errors=[] ) ``` @@ -539,6 +540,7 @@ To retrieve tokens from your vault, you can use the `detokenize` method. The `De ```python from skyflow.error import SkyflowError +from skyflow.utils.enums import RedactionType from skyflow.vault.tokens import DetokenizeRequest try: @@ -547,7 +549,7 @@ try: detokenize_request = DetokenizeRequest( tokens=detokenize_data, continue_on_error=False, # optional - redaction_type='plain-text' # optional + redaction_type=RedactionType.PLAIN_TEXT # optional ) response = skyflow_client.vault('').detokenize(detokenize_request) @@ -557,13 +559,14 @@ except SkyflowError as e: ``` Notes: -- `redaction` defaults to `plain-text`. +- `redaction_type` defaults to `RedactionType.PLAIN_TEXT`. - `continue_on_error` default valus is `False`. An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/detokenize_records.py) of a detokenize call: ```python from skyflow.error import SkyflowError +from skyflow.utils.enums import RedactionType from skyflow.vault.tokens import DetokenizeRequest try: @@ -572,7 +575,7 @@ try: detokenize_request = DetokenizeRequest( tokens=detokenize_data, continue_on_error=False, # optional - redaction_type='plain-text' # optional + redaction_type=RedactionType.PLAIN_TEXT # optional ) response = skyflow_client.vault('').detokenize(detokenize_request) @@ -599,6 +602,7 @@ An example of a detokenize call with continue_on_error: ```python from skyflow.error import SkyflowError +from skyflow.utils.enums import RedactionType from skyflow.vault.tokens import DetokenizeRequest try: @@ -607,7 +611,7 @@ try: detokenize_request = DetokenizeRequest( tokens=detokenize_data, continue_on_error=True, # optional - redaction_type='plain-text' # optional + redaction_type=RedactionType.PLAIN_TEXT # optional ) response = skyflow_client.vault('').detokenize(detokenize_request) @@ -699,13 +703,14 @@ To retrieve data using Skyflow IDs or unique column values, use the `get` method ```python from skyflow.error import SkyflowError +from skyflow.utils.enums import RedactionType from skyflow.vault.data import GetRequest GetRequest( table = '', ids = ['SKYFLOW_ID1>', 'SKYFLOW_ID2>'], return_tokens = True, - redaction_type='plain-text' + redaction_type=RedactionType.PLAIN_TEXT ) # or @@ -714,7 +719,7 @@ GetRequest( table = '', column_name='', column_values=['COLUMN_VALUE1>', 'COLUMN_VALUE2>'], - redaction_type='plain-text' + redaction_type=RedactionType.PLAIN_TEXT ) ``` Sample usage @@ -725,6 +730,7 @@ The following snippet shows how to use the `get` method using column names and c ```python from skyflow.error import SkyflowError +from skyflow.utils.enums import RedactionType from skyflow.vault.data import GetRequest try: @@ -736,7 +742,7 @@ try: table='table1', column_name="card_number", # It must be configured as unique in the schema. column_values=column_values, - redaction_type='plain-text' + redaction_type=RedactionType.PLAIN_TEXT ) response = skyflow_client.vault('').get(get_request) @@ -756,7 +762,7 @@ GetResponse( 'skyflow_id': '4f7af9f9-09e0-4f47-af8e-04c9b1ee1968' } ], - error=[] + errors=[] ) ``` @@ -765,13 +771,14 @@ GetResponse( ```python from skyflow.error import SkyflowError +from skyflow.utils.enums import RedactionType from skyflow.vault.data import GetRequest GetRequest( table = '', ids = ['SKYFLOW_ID1>', 'SKYFLOW_ID2>'], return_tokens = True, - redaction_type='plain-text' + redaction_type=RedactionType.PLAIN_TEXT ) ``` @@ -787,13 +794,14 @@ An [example](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/sa ```python from skyflow.error import SkyflowError +from skyflow.utils.enums import RedactionType from skyflow.vault.data import GetRequest try: get_request = GetRequest( table='table1', ids=['aea64577-12b1-4682-aad5-a183194c3f3d', 'b385c565-86eb-4af2-b959-8376f9b0754b'], - redaction_type="plain-text" + redaction_type=RedactionType.PLAIN_TEXT ) response = client.vault('').get(get_request) @@ -816,7 +824,7 @@ GetResponse( 'skyflow_id': 'b385c565-86eb-4af2-b959-8376f9b0754b' } ], - error=[] + errors=[] ) ``` @@ -856,7 +864,7 @@ GetResponse( 'skyflow_id': 'b385c565-86eb-4af2-b959-8376f9b0754b' } ], - error=[] + errors=[] ) ``` @@ -919,7 +927,7 @@ UpdateResponse( 'skyflow_id': '3b80c76a-c0d7-4c02-be00-b4128cb0f315', 'card_number': '4131-1751-0217-8491' }, - error=[] + errors=[] ) ``` @@ -929,7 +937,7 @@ UpdateResponse( ```python UpdateResponse( updated_field={'skyflow_id': '3b80c76a-c0d7-4c02-be00-b4128cb0f315'}, - error=[] + errors=[] ) ``` @@ -986,7 +994,7 @@ DeleteResponse( '77e093f8-3ace-4295-8683-bb6745d6178e', 'bf5989cc-79e8-4b2f-ad71-cb20b0a76091' ], - error=[] + errors=[] ) ``` @@ -1139,7 +1147,7 @@ QueryResponse( }, } ], - error=[] + errors=[] ) ``` @@ -1192,4 +1200,4 @@ Current the following 5 log levels are supported: ## Reporting a Vulnerability -If you discover a potential security issue in this project, please reach out to us at security@skyflow.com. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them. +If you discover a potential security issue in this project, please reach out to us at security@skyflow.com. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them. \ No newline at end of file From 3b4d0498ebbf70377dc4dcc9cb12f41a65dddd04 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 20 Nov 2024 23:15:16 +0530 Subject: [PATCH 10/15] SK-1749: Updated tokenize and invoke connection readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71a916a..50f39de 100644 --- a/README.md +++ b/README.md @@ -655,7 +655,7 @@ To tokenize data, use the `tokenize` method. The `TokenizeRequest` class is util from skyflow.vault.tokens import TokenizeRequest tokenize_request = TokenizeRequest( - tokenize_parameters=[{ + values=[{ 'value': '', 'column_group': '' }] @@ -1024,7 +1024,7 @@ query_params = { invoke_connection_request = InvokeConnectionRequest( method=Method.POST, body=body, - request_headers = headers, # optional + headers = headers, # optional path_params = path_params, # optional query_params=query_params # optional ) From 91e087f9c40873152b149c33db71da189db73d81 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Thu, 21 Nov 2024 00:35:28 +0530 Subject: [PATCH 11/15] SK-1749: Updated update interface --- README.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 50f39de..199473e 100644 --- a/README.md +++ b/README.md @@ -878,7 +878,7 @@ from skyflow.vault.data import UpdateRequest try: update_data = { - 'id': '', + 'skyflow_id': '', '': '' } @@ -902,7 +902,7 @@ from skyflow.vault.data import UpdateRequest try: update_data = { - 'id': '3b80c76a-c0d7-4c02-be00-b4128cb0f315', + 'skyflow_id': '3b80c76a-c0d7-4c02-be00-b4128cb0f315', 'card_number': '4111111111117777' } @@ -1133,18 +1133,10 @@ Sample Response QueryResponse( fields=[ { - "fields": { - "card_number": "XXXXXXXXXXXX1111", - "card_pin": "*REDACTED*", - "cvv": "", - "expiration_date": "*REDACTED*", - "expiration_month": "*REDACTED*", - "expiration_year": "*REDACTED*", - "name": "a***te", - "skyflow_id": "3ea3861-x107-40w8-la98-106sp08ea83f", - "ssn": "XXX-XX-6789", - "zip_code": None - }, + 'card_number': 'XXXXXXXXXXXX1112', + 'name': 'S***ar', + 'skyflow_id': '4f7af9f9-09e0-4f47-af8e-04c9b1ee1968', + 'tokenized_data': {} } ], errors=[] From 2002b8eab8628b5701aab0b36a4ea849442508b6 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Thu, 21 Nov 2024 01:07:39 +0530 Subject: [PATCH 12/15] SK-1749: Added link for tokenize --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 199473e..a9f4d7c 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ This Python SDK is designed to help developers easily implement Skyflow into the - [Vault APIs](#vault-apis) - [Insert data into the vault](#insert-data-into-the-vault) - [Detokenize](#detokenize) + - [Tokenize](#tokenize) - [Get](#get) - [Get By Id](#get-by-id) - [Redaction Types](#redaction-types) From f8f8f8d85530959d9fe2d67fa1c4dfaa3852d84d Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Thu, 21 Nov 2024 10:37:58 +0530 Subject: [PATCH 13/15] SK-1749: Fixed linting --- README.md | 132 +++++++++++++++++++++++++++--------------------------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index a9f4d7c..5345ea8 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ # Skyflow-python --- -## Description -This Python SDK is designed to help developers easily implement Skyflow into their python backend. +## Description +This Python SDK is designed to help developers easily implement Skyflow into their python backend. ## Table of Contents + - [Skyflow-python](#skyflow-python) - [Description](#description) - [Table of Contents](#table-of-contents) @@ -29,7 +30,6 @@ This Python SDK is designed to help developers easily implement Skyflow into the - [Logging](#logging) - [Reporting a Vulnerability](#reporting-a-vulnerability) - ## Features Authentication with a Skyflow Service Account and generation of a bearer token @@ -70,7 +70,7 @@ token_type = '' def token_provider(): global bearer_token global token_type - + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_toke('') return bearer_token, token_type @@ -84,7 +84,6 @@ except SkyflowError as e: ``` - [Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/token_generation_example.py): ```python @@ -137,7 +136,7 @@ options = { def token_provider(): global bearer_token global token_type - + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token('', options) return bearer_token, token_type @@ -151,7 +150,6 @@ except SkyflowError as e: ``` - [Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/scoped_token_generation_example.py): ```python @@ -207,7 +205,7 @@ options = { def token_provider(): global bearer_token global token_type - + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token('', options) return bearer_token, token_type @@ -221,7 +219,6 @@ except SkyflowError as e: ``` - [Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/token_generation_with_context_example.py): ```python @@ -279,7 +276,7 @@ options = { def token_provider(): global bearer_token global token_type - + if is_expired(bearer_token): bearer_token, token_type = generate_bearer_token('', options) return bearer_token, token_type @@ -293,7 +290,6 @@ except SkyflowError as e: ``` - [Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/service_account/signed_token_generation_example.py): ```python @@ -374,9 +370,10 @@ client = ( .build() ) ``` + Notes: -- If both Skyflow common credentials and individual credentials at the configuration level are provided, the individual credentials at the configuration level will take priority. +- If both Skyflow common credentials and individual credentials at the configuration level are provided, the individual credentials at the configuration level will take priority. All Vault APIs must be invoked using a client instance. @@ -385,6 +382,7 @@ All Vault APIs must be invoked using a client instance. To insert data into your vault, use the `insert` method. The `InsertRequest` class is used to create an insert request, which contains the values to be inserted in the form of a dictionary of records. Additionally, you can provide options in the insert request, such as returning tokenized data, upserting records, and continuing on error. Insert call schema + ```python #Initialize Client from skyflow.error import SkyflowError @@ -398,8 +396,8 @@ try: insert_request = InsertRequest( - table_name='', - values=insert_data, + table_name = '', + values = insert_data, ) response = skyflow_client.vault('VAULT_ID').insert(insert_request) @@ -420,9 +418,9 @@ try: ] insert_request = InsertRequest( - table_name='table1', - values=insert_data, - return_tokens=True # returns tokens + table_name = 'table1', + values = insert_data, + return_tokens = True # returns tokens ) response = client.vault('').insert(insert_request) @@ -460,10 +458,10 @@ try: ] insert_request = InsertRequest( - table_name='table1', - values=insert_data, - return_tokens=True, # returns tokens - continue_on_error=True + table_name = 'table1', + values = insert_data, + return_tokens = True, # returns tokens + continue_on_error = True ) response = client.vault('').insert(insert_request) @@ -508,10 +506,10 @@ try: ] insert_request = InsertRequest( - table_name='table1', - values=insert_data, - return_tokens=True, # returns tokens - upsert="name" # unique column name + table_name = 'table1', + values = insert_data, + return_tokens = True, # returns tokens + upsert = "name" # unique column name ) response = client.vault('').insert(insert_request) @@ -548,9 +546,9 @@ try: detokenize_data = ['', '', ''] detokenize_request = DetokenizeRequest( - tokens=detokenize_data, - continue_on_error=False, # optional - redaction_type=RedactionType.PLAIN_TEXT # optional + tokens =d etokenize_data, + continue_on_error = False, # optional + redaction_type = RedactionType.PLAIN_TEXT # optional ) response = skyflow_client.vault('').detokenize(detokenize_request) @@ -559,7 +557,9 @@ except SkyflowError as e: print('Error Occurred:', e) ``` + Notes: + - `redaction_type` defaults to `RedactionType.PLAIN_TEXT`. - `continue_on_error` default valus is `False`. @@ -574,9 +574,9 @@ try: detokenize_data = ['9738-1683-0486-1480', '6184-6357-8409-6668', '4914-9088-2814-3840'] detokenize_request = DetokenizeRequest( - tokens=detokenize_data, - continue_on_error=False, # optional - redaction_type=RedactionType.PLAIN_TEXT # optional + tokens = detokenize_data, + continue_on_error = False, # optional + redaction_type = RedactionType.PLAIN_TEXT # optional ) response = skyflow_client.vault('').detokenize(detokenize_request) @@ -591,10 +591,10 @@ Sample response: ```python DetokenizeResponse( detokenized_fields=[ - {'token': '9738-1683-0486-1480', 'value': '4111111111111115', 'type': 'STRING'}, - {'token': '6184-6357-8409-6668', 'value': '4111111111111119', 'type': 'STRING'}, + {'token': '9738-1683-0486-1480', 'value': '4111111111111115', 'type': 'STRING'}, + {'token': '6184-6357-8409-6668', 'value': '4111111111111119', 'type': 'STRING'}, {'token': '4914-9088-2814-3840', 'value': '4111111111111118', 'type': 'STRING'} - ], + ], errors=[] ) ``` @@ -610,9 +610,9 @@ try: detokenize_data = ['9738-1683-0486-1480', '6184-6357-8409-6668', '4914-9088-2814-384'] detokenize_request = DetokenizeRequest( - tokens=detokenize_data, - continue_on_error=True, # optional - redaction_type=RedactionType.PLAIN_TEXT # optional + tokens = detokenize_data, + continue_on_error = True, # optional + redaction_type = RedactionType.PLAIN_TEXT # optional ) response = skyflow_client.vault('').detokenize(detokenize_request) @@ -656,7 +656,7 @@ To tokenize data, use the `tokenize` method. The `TokenizeRequest` class is util from skyflow.vault.tokens import TokenizeRequest tokenize_request = TokenizeRequest( - values=[{ + values = [{ 'value': '', 'column_group': '' }] @@ -673,7 +673,7 @@ from skyflow.vault.tokens import TokenizeRequest try: tokenize_request = TokenizeRequest( - tokenize_parameters=[{ + values = [{ "value": '4111111111111111', "column_group": "card_number_cg" }] @@ -711,18 +711,19 @@ GetRequest( table = '', ids = ['SKYFLOW_ID1>', 'SKYFLOW_ID2>'], return_tokens = True, - redaction_type=RedactionType.PLAIN_TEXT + redaction_type = RedactionType.PLAIN_TEXT ) # or GetRequest( table = '', - column_name='', - column_values=['COLUMN_VALUE1>', 'COLUMN_VALUE2>'], - redaction_type=RedactionType.PLAIN_TEXT + column_name ='', + column_values = ['COLUMN_VALUE1>', 'COLUMN_VALUE2>'], + redaction_type = RedactionType.PLAIN_TEXT ) ``` + Sample usage ### Get By Column Name and Column Values @@ -740,10 +741,10 @@ try: ] get_request = GetRequest( - table='table1', - column_name="card_number", # It must be configured as unique in the schema. - column_values=column_values, - redaction_type=RedactionType.PLAIN_TEXT + table = 'table1', + column_name = 'card_number', # It must be configured as unique in the schema. + column_values = column_values, + redaction_type = RedactionType.PLAIN_TEXT ) response = skyflow_client.vault('').get(get_request) @@ -779,11 +780,12 @@ GetRequest( table = '', ids = ['SKYFLOW_ID1>', 'SKYFLOW_ID2>'], return_tokens = True, - redaction_type=RedactionType.PLAIN_TEXT + redaction_type = RedactionType.PLAIN_TEXT ) ``` #### Redaction Types + There are 4 accepted values in Skyflow.RedactionTypes: - `PLAIN_TEXT` @@ -800,9 +802,9 @@ from skyflow.vault.data import GetRequest try: get_request = GetRequest( - table='table1', - ids=['aea64577-12b1-4682-aad5-a183194c3f3d', 'b385c565-86eb-4af2-b959-8376f9b0754b'], - redaction_type=RedactionType.PLAIN_TEXT + table = 'table1', + ids = ['aea64577-12b1-4682-aad5-a183194c3f3d', 'b385c565-86eb-4af2-b959-8376f9b0754b'], + redaction_type = RedactionType.PLAIN_TEXT ) response = client.vault('').get(get_request) @@ -830,7 +832,6 @@ GetResponse( ``` - The following snippet shows how to use the `get()` method with return_tokens true. ```python @@ -839,11 +840,11 @@ from skyflow.vault.data import GetRequest try: get_request = GetRequest( - table='table1', - ids=['aea64577-12b1-4682-aad5-a183194c3f3d', 'b385c565-86eb-4af2-b959-8376f9b0754b'], - return_tokens=True + table = 'table1', + ids = ['aea64577-12b1-4682-aad5-a183194c3f3d', 'b385c565-86eb-4af2-b959-8376f9b0754b'], + return_tokens = True ) - + response = client.vault('').get(get_request) print('Response:', response) except SkyflowError as e: @@ -893,6 +894,7 @@ try: except SkyflowError as e: print('Error Occurred:', e) ``` + Sample usage The following snippet shows how to use the `update()` method. For details, see [update_record.py](https://github.com/skyflowapi/skyflow-python/blob/SK-1749-readme/samples/vault_api/update_record.py), @@ -908,8 +910,8 @@ try: } update_request = UpdateRequest( - table='table1', - data=update_data + table = 'table1', + data = update_data ) response = skyflow_client.vault('').update(update_request) @@ -958,7 +960,7 @@ primary_delete_ids = [ ] delete_request = DeleteRequest( - table='', + table = '', ids = primary_delete_ids ) ``` @@ -1023,11 +1025,11 @@ query_params = { } invoke_connection_request = InvokeConnectionRequest( - method=Method.POST, - body=body, + method = Method.POST, + body = body, headers = headers, # optional path_params = path_params, # optional - query_params=query_params # optional + query_params = query_params # optional ) ``` @@ -1071,7 +1073,7 @@ invoke_connection_request = InvokeConnectionRequest( 'card_number': '4337-1696-5866-0865', 'ssn': '524-41-4248' }, - request_headers = { + headers = { 'Content-Type': 'application/json' } ) @@ -1116,7 +1118,7 @@ from skyflow.error import SkyflowError from skyflow.vault.data import QueryRequest query_request = QueryRequest( - query= "SELECT * FROM cards WHERE skyflow_id='3ea3861-x107-40w8-la98-106sp08ea83f'" + query = "SELECT * FROM cards WHERE skyflow_id='3ea3861-x107-40w8-la98-106sp08ea83f'" ) try: @@ -1193,4 +1195,4 @@ Current the following 5 log levels are supported: ## Reporting a Vulnerability -If you discover a potential security issue in this project, please reach out to us at security@skyflow.com. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them. \ No newline at end of file +If you discover a potential security issue in this project, please reach out to us at security@skyflow.com. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them. From c75d429064d485221df179d3618b701abce1880f Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Thu, 21 Nov 2024 10:41:18 +0530 Subject: [PATCH 14/15] SK-1749: Fixed tokenize parameters --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5345ea8..cb05a36 100644 --- a/README.md +++ b/README.md @@ -650,7 +650,7 @@ DetokenizeResponse( ### Tokenize -To tokenize data, use the `tokenize` method. The `TokenizeRequest` class is utilized to create a tokenize request. In this request, you specify the `tokenize_parameters` parameter, which is a list of dictionaries. Each dictionary contains two keys: `value` and `column_group`. +To tokenize data, use the `tokenize` method. The `TokenizeRequest` class is utilized to create a tokenize request. In this request, you specify the `values` parameter, which is a list of dictionaries. Each dictionary contains two keys: `value` and `column_group`. ```python from skyflow.vault.tokens import TokenizeRequest From c5933806060ac70cd97c13354b8b25dc9b105409 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Thu, 21 Nov 2024 10:48:52 +0530 Subject: [PATCH 15/15] SK-1749: Added creds for logging --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cb05a36..bfdab7a 100644 --- a/README.md +++ b/README.md @@ -1155,13 +1155,31 @@ from skyflow import Skyflow from skyflow import LogLevel from skyflow import Env +# To generate Bearer Token from credentials string. +skyflow_credentials = { + 'clientID': '', + 'clientName': '', + 'tokenURI': '', + 'keyID': '', + 'privateKey': '', + } +credentials_string = json.dumps(skyflow_credentials) + +# Pass one of api_key, token, credentials_string & path as credentials +credentials = { + 'token': 'BEARER_TOKEN', # bearer token + # api_key: "API_KEY", # API_KEY + # path: "PATH", # path to credentials file + # credentials_string: credentials_string, # credentials as string +} + client = ( Skyflow.builder() .add_vault_config({ 'vault_id': 'VAULT_ID', # primary vault 'cluster_id': 'CLUSTER_ID', # ID from your vault URL Eg https://{clusterId}.vault.skyflowapis.com 'env': Env.PROD, # Env by default it is set to PROD - 'credentials': "" # individual credentials + 'credentials': credentials # individual credentials }) .add_skyflow_credentials(credentials) # skyflow credentials will be used if no individual credentials are passed .set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR